Version 1.0.2

Теперь по нажатии иконки расширения будет появляться меню. В нем добавил возможность выключения расширения
This commit is contained in:
FutureX 2018-04-12 23:57:35 +03:00
parent 17e0faabc7
commit e6195eb458
5 changed files with 117 additions and 13 deletions

View File

@ -1,7 +1,6 @@
chrome.browserAction.setBadgeText({text: "on"}); chrome.storage.sync.get(['choise'], function(items) {
//При нажатии иконки расширения вызывается данная функция var choise=items['choise'];
chrome.browserAction.onClicked.addListener(function() { if(choise == undefined) choise = true;
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { if(choise) chrome.browserAction.setBadgeText({text: "on"});
chrome.tabs.sendMessage(tabs[0].id, {command: "show"}); else chrome.browserAction.setBadgeText({text: "off"});
}); });
});

View File

@ -1,9 +1,15 @@
//По окончании загрузки документа вызывается функция //По окончании загрузки документа вызывается функция
$(document).ready(function() { $(document).ready(function() {
var timerId = setInterval(show, 2000); chrome.storage.sync.get(['choise'], function(items) {
setTimeout(function() { var choise=items['choise'];
clearInterval(timerId); if(choise == undefined) choise = true;
}, 7000); if(choise){
var timerId = setInterval(show, 2000);
setTimeout(function() {
clearInterval(timerId);
}, 7000);
}
});
}) })
//При получении команды 'show' показывает ответы //При получении команды 'show' показывает ответы

View File

@ -10,7 +10,8 @@
"version": "1.4.8.8", "version": "1.4.8.8",
"manifest_version": 2, "manifest_version": 2,
"browser_action": { "browser_action": {
"default_icon": "icon.png" "default_icon": "icon.png",
"default_popup": "popup.html"
}, },
"background": { "background": {
"scripts": ["background.js"] "scripts": ["background.js"]
@ -24,6 +25,7 @@
} }
], ],
"permissions": [ "permissions": [
"tabs" "tabs",
"storage"
] ]
} }

60
popup.html Normal file
View File

@ -0,0 +1,60 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<html>
<head>
<title>LMS Answers</title>
<style>
body {
font-family: sans-serif;
background: #f5f5f5;
color: #666E79;
width: 250px;
}
div.form {
background: white;
border: solid 1px #e8e8e8;
border-radius: 10px;
line-height: 15px;
}
h1 {
margin:0;
padding: 0;
font-size: 20px;
text-align: center;
line-height: 40px;
}
h2 {
margin: 10px;
padding: 0;
font-size: 14px;
text-align: center;
line-height: 15px;
}
button {
border:solid 1px #5E697C;
color: red;
font-size: 13px;
line-height: 22px;
margin: 10px auto 15px;
display: block;
border-radius: 4px;
cursor: pointer;
font-weight: bolder;
text-shadow: rgba(0,0,0,0.2) -1px -1px 0px;
padding: 1 10px;
}
</style>
<script type="text/javascript" src="popup.js"> </script>
</head>
<body>
<div class="form">
<h1>LMS Answers</h1>
</div>
<div class="checker">
<h2><input type="checkbox" id="choiser" checked>Автоматический режим</h2>
</div>
<div class="newbutton">
<button id="showBtn">Показать ответы</button>
</div>
</body>
</html>

37
popup.js Normal file
View File

@ -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"});
});
}