diff --git a/js/auto_mode.js b/js/auto_mode.js new file mode 100644 index 0000000..4c1c278 --- /dev/null +++ b/js/auto_mode.js @@ -0,0 +1,47 @@ +//По окончании загрузки документа вызывается функция +$(document).ready(function() { + var path = window.location.pathname; + var page = path.split("/").pop(); + if(page === 'index.html') { + //При получении команды 'auto_mode' заполняет ответы + chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { + if(request.command==="auto_mode") { + auto_mode(); + } + }); + //Если выбрана функция автоматического показа ответов запускается функция заполнения ответов + chrome.storage.sync.get(['auto_mode'], function(items) { + var choise=items['auto_mode']; + if(choise == undefined) choise = true; + if(choise){ + var timerId = setInterval(auto_mode, 2000); + setTimeout(function() { + clearInterval(timerId); + }, 7000); + } + }); + } +}) +//Заполнить ответы +function auto_mode() { + var test,answers; + + test = document.getElementsByClassName('selectBox'); + answers = document.getElementsByTagName('b'); + if(test&&answers) fill_selectbox(test,answers); +} +//Заполнить задания, где есть selectBox +function fill_selectbox(test,answers) { + var test_arr = Array.prototype.slice.call(test); + var answers_arr = Array.prototype.slice.call(answers); + if(answers_arr)answers_arr.forEach(function(item, i) { + var a = item.innerHTML; + Array.prototype.slice.call(test_arr[i].options).forEach(function(item) { + // alert(item.value); + if(item.value.includes(a)) { + var b = item.value.replace(a, ''); + if( b.search(/[a-zA-Z]/) === -1 ) test_arr[i].value = item.value; + } + }); + }); +} \ No newline at end of file diff --git a/js/background.js b/js/background.js index 4183c14..49bc8f6 100644 --- a/js/background.js +++ b/js/background.js @@ -1,5 +1,5 @@ -chrome.storage.sync.get(['show_answers','simple_mode','true_answers'], function(items) { - var choise=items['show_answers']; +chrome.storage.sync.get(['show_mode','simple_mode','true_mode'], function(items) { + var choise=items['show_mode']; if(choise == undefined) choise = true; if(choise) chrome.browserAction.setBadgeText({text: "on"}); else chrome.browserAction.setBadgeText({text: "off"}); @@ -8,7 +8,7 @@ chrome.storage.sync.get(['show_answers','simple_mode','true_answers'], function( if(choise == undefined) choise = false; if(choise) chrome.browserAction.setBadgeText({text: "on"}); - choise=items['true_answers']; + choise=items['true_mode']; if(choise == undefined) choise = false; if(choise) chrome.browserAction.setBadgeText({text: "on"}); }); diff --git a/js/show_answers.js b/js/show_mode.js similarity index 92% rename from js/show_answers.js rename to js/show_mode.js index b6787d1..2004a84 100644 --- a/js/show_answers.js +++ b/js/show_mode.js @@ -10,8 +10,8 @@ $(document).ready(function() { } }); //Если выбрана функция автоматического показа ответов заппускается функция показа ответов - chrome.storage.sync.get(['show_answers'], function(items) { - var choise=items['show_answers']; + chrome.storage.sync.get(['show_mode'], function(items) { + var choise=items['show_mode']; if(choise == undefined) choise = true; if(choise){ var timerId = setInterval(show, 2000); diff --git a/js/true_answers.js b/js/true_mode.js similarity index 99% rename from js/true_answers.js rename to js/true_mode.js index 585920c..f79880a 100644 --- a/js/true_answers.js +++ b/js/true_mode.js @@ -1,5 +1,5 @@ -chrome.storage.sync.get(['true_answers'], function(items) { - var choise=items['true_answers']; +chrome.storage.sync.get(['true_mode'], function(items) { + var choise=items['true_mode']; if(choise == undefined) choise = false; if(choise) on(); }); diff --git a/manifest.json b/manifest.json index 5505e43..30695ef 100644 --- a/manifest.json +++ b/manifest.json @@ -14,7 +14,7 @@ "default_popup": "popup/popup.html" }, "background": { - "scripts": ["js/background.js", "js/true_answers.js" ] + "scripts": ["js/background.js", "js/true_mode.js" ] }, "content_scripts": [ { @@ -23,7 +23,7 @@ "run_at": "document_end" },{ "matches": [ "*://www.cambridgelms.org/*" ], - "js": [ "js/jquery.js", "js/show_answers.js" ], + "js": [ "js/jquery.js", "js/show_mode.js", "js/auto_mode.js" ], "run_at": "document_idle", "all_frames": true } diff --git a/popup/popup.html b/popup/popup.html index e867d4b..2bea787 100644 --- a/popup/popup.html +++ b/popup/popup.html @@ -10,24 +10,29 @@