diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index ca1b506..3afa2c0 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -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 permission since activeTab permission diff --git a/background/jigsaw_bg_common_functions.js b/background/jigsaw_bg_common_functions.js index 74dd2c9..d92eb1c 100644 --- a/background/jigsaw_bg_common_functions.js +++ b/background/jigsaw_bg_common_functions.js @@ -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); + }); }); }); } diff --git a/content_scripts/jigsaw.js b/content_scripts/jigsaw.js index 1fcdded..a35fd7a 100644 --- a/content_scripts/jigsaw.js +++ b/content_scripts/jigsaw.js @@ -42,6 +42,7 @@ var JigSaw = { maxZIndex: 100, numBlink: 8, loading: false, + timer: null, base_div: null, init: function() { @@ -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 == "") { @@ -312,6 +321,10 @@ var JigSaw = { jigsaw_preview_image.style.visibility = 'hidden'; } } + }, + + pause_resume_timer: function() { + JigSaw.timer.pause_resume(); } }; @@ -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."); } } @@ -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(); diff --git a/css/jigsaw.css b/css/jigsaw.css index 4dec9a7..e47e85d 100644 --- a/css/jigsaw.css +++ b/css/jigsaw.css @@ -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; } diff --git a/manifest.json b/manifest.json index 6c47fec..492bec7 100644 --- a/manifest.json +++ b/manifest.json @@ -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/",