Version 1.0.1

Добавил функцию работы расширения по нажатии иконки расширения. Сделано для того случая, когда ответы сами не показались
This commit is contained in:
FutureX 2018-04-12 23:53:19 +03:00
parent 6b432a54a5
commit 17e0faabc7
4 changed files with 32 additions and 23 deletions

View File

@ -1,9 +1,7 @@
$.get(chrome.extension.getURL('/injected.js'),
function(data) {
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
script.innerHTML = data;
document.getElementsByTagName("head")[0].appendChild(script);
document.getElementsByTagName("body")[0].setAttribute("onLoad", "injected_main();");
}
);
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"});
});
});

19
inject.js Normal file
View File

@ -0,0 +1,19 @@
//По окончании загрузки документа вызывается функция
$(document).ready(function() {
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");
$("table.ng-hide").removeClass("ng-hide");
$("section").css("user-select","initial");
}

View File

@ -1,11 +0,0 @@
function injected_main() {
var timerId = setInterval(show, 2000);
setTimeout(function() {
clearInterval(timerId);
}, 7000);
}
function show() {
$('*[class^="correct"]').show().removeClass("ng-hide").parent().show().removeClass("ng-hide");
$("table.ng-hide").removeClass("ng-hide");
$("section").css("user-select","initial");
}

View File

@ -12,15 +12,18 @@
"browser_action": {
"default_icon": "icon.png"
},
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": [ "*://www.cambridgelms.org/*" ],
"js": [ "jquery.js", "background.js" ],
"js": [ "jquery.js", "inject.js" ],
"run_at": "document_end",
"all_frames": true
}
],
"web_accessible_resources": [
"/injected.js"
"permissions": [
"tabs"
]
}