Version 1.0.2
Теперь по нажатии иконки расширения будет появляться меню. В нем добавил возможность выключения расширения
This commit is contained in:
parent
17e0faabc7
commit
e6195eb458
@ -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"});
|
||||
});
|
14
inject.js
14
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' показывает ответы
|
||||
|
@ -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"
|
||||
]
|
||||
}
|
60
popup.html
Normal file
60
popup.html
Normal 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
37
popup.js
Normal 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"});
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user