diff --git a/background.js b/background.js index dcf07ac..f6d76d4 100644 --- a/background.js +++ b/background.js @@ -1,6 +1,20 @@ -chrome.storage.sync.get(['choise'], function(items) { +chrome.storage.sync.get(['choise','simple'], function(items) { var choise=items['choise']; if(choise == undefined) choise = true; if(choise) chrome.browserAction.setBadgeText({text: "on"}); else chrome.browserAction.setBadgeText({text: "off"}); -}); \ No newline at end of file +}); + +chrome.contextMenus.create({"title": "Показать ответы","onclick" : show}); + +function show(info) { + var url = info.pageUrl; + var url_ = "www.cambridgelms.org"; + if(JSON.stringify(url).includes(url_)) + { + var query = { active: true, currentWindow: true }; + chrome.tabs.query(query, function(tabs) { + chrome.tabs.sendMessage(tabs[0].id, {command: "show"}); + }); + } +} \ No newline at end of file diff --git a/inject.js b/inject.js index e059b3f..8d76a3c 100644 --- a/inject.js +++ b/inject.js @@ -1,22 +1,28 @@ //По окончании загрузки документа вызывается функция $(document).ready(function() { - chrome.storage.sync.get(['choise'], function(items) { - var choise=items['choise']; - if(choise == undefined) choise = true; - if(choise){ - var timerId = setInterval(show, 2000); - setTimeout(function() { - clearInterval(timerId); - }, 7000); - } - }); + var path = window.location.pathname; + var page = path.split("/").pop(); + if(page === 'index.html') { + //При получении команды 'show' показывает ответы + chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { + if(request.command==="show") { + show(); + } + }); + //Если выбрана функция автоматического показа ответов заппускается функция показа ответов + chrome.storage.sync.get(['choise'], function(items) { + var choise=items['choise']; + if(choise == undefined) choise = true; + if(choise){ + var timerId = setInterval(show, 2000); + setTimeout(function() { + clearInterval(timerId); + }, 7000); + } + }); + } }) -//При получении команды 'show' показывает ответы -chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { - if(request.command==="show") show(); -}); - //Показать ответы function show() { $('*[class^="correct"]').show().removeClass("ng-hide").parent().show().removeClass("ng-hide"); diff --git a/manifest.json b/manifest.json index 53c87ad..68fb405 100644 --- a/manifest.json +++ b/manifest.json @@ -20,12 +20,13 @@ { "matches": [ "*://www.cambridgelms.org/*" ], "js": [ "jquery.js", "inject.js" ], - "run_at": "document_end", + "run_at": "document_idle", "all_frames": true } ], "permissions": [ "tabs", + "contextMenus", "storage" ] } \ No newline at end of file diff --git a/popup.html b/popup.html index c92766d..6c84b9f 100644 --- a/popup.html +++ b/popup.html @@ -3,57 +3,19 @@