diff --git a/background.js b/background.js index 95aed10..dcf07ac 100644 --- a/background.js +++ b/background.js @@ -1,7 +1,6 @@ -chrome.browserAction.setBadgeText({text: "on"}); -//При нажатии иконки расширения вызывается данная функция -chrome.browserAction.onClicked.addListener(function() { - chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { - chrome.tabs.sendMessage(tabs[0].id, {command: "show"}); - }); -}); +chrome.storage.sync.get(['choise'], 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 diff --git a/inject.js b/inject.js index be77c60..e059b3f 100644 --- a/inject.js +++ b/inject.js @@ -1,9 +1,15 @@ //По окончании загрузки документа вызывается функция $(document).ready(function() { - var timerId = setInterval(show, 2000); - setTimeout(function() { - clearInterval(timerId); - }, 7000); + 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' показывает ответы diff --git a/manifest.json b/manifest.json index 3223216..53c87ad 100644 --- a/manifest.json +++ b/manifest.json @@ -10,7 +10,8 @@ "version": "1.4.8.8", "manifest_version": 2, "browser_action": { - "default_icon": "icon.png" + "default_icon": "icon.png", + "default_popup": "popup.html" }, "background": { "scripts": ["background.js"] @@ -24,6 +25,7 @@ } ], "permissions": [ - "tabs" + "tabs", + "storage" ] } \ No newline at end of file diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..c92766d --- /dev/null +++ b/popup.html @@ -0,0 +1,60 @@ + + + + + LMS Answers + + + + +
+

LMS Answers

+
+
+

Автоматический режим

+
+
+ +
+ + \ No newline at end of file diff --git a/popup.js b/popup.js new file mode 100644 index 0000000..85baea8 --- /dev/null +++ b/popup.js @@ -0,0 +1,37 @@ +document.addEventListener('DOMContentLoaded', function() { + loadOptions(); + var showButton = document.getElementById('showBtn'); + showButton.addEventListener('click', function() { + show(); + }, false); + var showChecker = document.getElementById('choiser'); + showChecker.addEventListener('change', function() { + saveOptions(); + show(); + }, false); +}, false); + +function loadOptions() { + chrome.storage.sync.get(['choise'], function(items) { + var choise=items['choise']; + if(choise == undefined) choise = true; + var select = document.getElementById("choiser"); + select.checked = choise; + if(select.checked) chrome.browserAction.setBadgeText({text: "on"}); + else chrome.browserAction.setBadgeText({text: "off"}); + }); +} + +function saveOptions() { + var select = document.getElementById("choiser"); + chrome.storage.sync.set({'choise': select.checked}); + if(select.checked) chrome.browserAction.setBadgeText({text: "on"}); + else chrome.browserAction.setBadgeText({text: "off"}); +} + +function show() { + 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