Skip to content

Commit

Permalink
Commits for Version 1.4
Browse files Browse the repository at this point in the history
* Added timer to measure time taken to solve the puzzle

* Timer can be paused/resumed
  • Loading branch information
ushnisha committed Apr 21, 2020
1 parent 65a046b commit 0f235c9
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
8 changes: 8 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Version 1.4

* Added timer to measure time taken to solve the puzzle

* Timer can be paused/resumed

------------------------------

## Version 1.3

* Removed <all_urls> permission since activeTab permission
Expand Down
26 changes: 14 additions & 12 deletions background/jigsaw_bg_common_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,22 @@ function loadJigSaw(tabId, thisURL) {
let success = true;

browser.tabs.insertCSS(tabId, { matchAboutBlank: false, file: "/css/jigsaw.css", runAt: "document_end"}, function() {
browser.tabs.executeScript(tabId, { matchAboutBlank: false, file: "/content_scripts/jigsaw.js", runAt: "document_end"}, function() {
let onSendMessage = function(response) {
if (browser.runtime.lastError) {
console.log(browser.runtime.lastError);
}
else {
console.log("Response From Content Script: " + response.response);
browser.tabs.executeScript(tabId, { matchAboutBlank: false, file: "/js-utils/timer/Timer.js", runAt: "document_end"}, function() {
browser.tabs.executeScript(tabId, { matchAboutBlank: false, file: "/content_scripts/jigsaw.js", runAt: "document_end"}, function() {
let onSendMessage = function(response) {
if (browser.runtime.lastError) {
console.log(browser.runtime.lastError);
}
else {
console.log("Response From Content Script: " + response.response);
}
}
}

let sendMessage = browser.tabs.sendMessage(tabId,
{ jigsaw_action: "loadJigSaw",
jigsaw_url: thisURL },
onSendMessage);
let sendMessage = browser.tabs.sendMessage(tabId,
{ jigsaw_action: "loadJigSaw",
jigsaw_url: thisURL },
onSendMessage);
});
});
});
}
Expand Down
23 changes: 23 additions & 0 deletions content_scripts/jigsaw.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var JigSaw = {
maxZIndex: 100,
numBlink: 8,
loading: false,
timer: null,
base_div: null,

init: function() {
Expand Down Expand Up @@ -86,6 +87,14 @@ var JigSaw = {
JigSaw.calculateNeighbors();
JigSaw.loading = false;
message.parentNode.removeChild(message);
JigSaw.timer = new Timer();
JigSaw.timer.begin();
setInterval(function() {
let timer = document.getElementById('timer');
if (timer != null) {
timer.textContent = JigSaw.timer.getString();
}
}, 1000);
}, false);

if (img_url.value == "") {
Expand Down Expand Up @@ -312,6 +321,10 @@ var JigSaw = {
jigsaw_preview_image.style.visibility = 'hidden';
}
}
},

pause_resume_timer: function() {
JigSaw.timer.pause_resume();
}

};
Expand Down Expand Up @@ -651,6 +664,7 @@ function onMouseUp(e) {
JigSaw.updateConnections(piece, xpos, ypos);
let solved = JigSaw.checkSolved();
if (solved) {
JigSaw.timer.stop();
alert("Congratulations! You have solved the puzzle.");
}
}
Expand Down Expand Up @@ -777,6 +791,15 @@ function loadJigSaw(jigsaw_default_size) {
jigsaw_toggle_preview.addEventListener('click', JigSaw.toggle_preview_image);
jigsaw_controls.appendChild(jigsaw_toggle_preview);

// Create button to show timer
let jigsaw_timer = document.createElement('div');
jigsaw_timer.setAttribute('id', 'timer');
jigsaw_timer.setAttribute('class', 'jigsaw_control_item');
jigsaw_timer.setAttribute('title', 'Click to pause/resume solve timer');
jigsaw_timer.textContent = '00:00:00';
jigsaw_timer.addEventListener('click', JigSaw.pause_resume_timer);
jigsaw_controls.appendChild(jigsaw_timer);

console.log("Created basic elements. Now initializing the JigSaw puzzle");
}
JigSaw.init();
Expand Down
9 changes: 9 additions & 0 deletions css/jigsaw.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ div.jigsaw_controls
padding: 5px 5px 5px 5px;
}

div.jigsaw_control_item
{
border: 2px solid black;
border-radius: 5px;
color:black;
backgroundi-color:#dfdfdf;
text-align:center;
}

input[type="text"] {
font-size: 1em;
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"manifest_version": 2,
"name": "__MSG_extensionName__",
"version": "1.3",
"version": "1.4",

"description": "__MSG_extensionDescription__",
"homepage_url": "https://www.github.com/ushnisha/jigsaw/",
Expand Down

0 comments on commit 0f235c9

Please sign in to comment.