所以我正在制作一个Chrome扩展程序,每分钟重新加载一个特定的标签,以检查页面是否有不同之处,并在这种情况下通知我。一切都按我想要的方式工作,只有当它在background.Ms上的chrome.alarm在periodInMinutes上的值为0.1(或接近这个数字)时才有效,我需要它能够在1.0工作但是当我设置时它在这个时候开始在我的所有标签上制作任何想法的奇怪的东西?
的manifest.json
{
"manifest_version": 2,
"name": "Ultra Reloader",
"description": "This extension allows you to work better",
"version": "1.0",
"icons": { "128": "icon.png" },
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"background": {
"scripts":["background.js"],
"persistent": false
},
"content_scripts" : [
{
"matches": ["http://*/*", "https://*/*"],
"js" : ["contentscript.js"]
}
],
"permissions": [
"activeTab",
"tabs",
"notifications",
"https://www.raterhub.com/*"
]
}
popup.html
<!doctype html>
<html>
<head>
<title>Ultra Reloader</title>
<script src="popup.js"></script>
</head>
<body bgcolor="#ff6600">
<h1>REBECCA!!</h1>
<button id="startEverything">Start!</button>
<button id="stopEverything">Stop!</button>
</body>
</html>
contentscript.js
var regex = /No tasks are currently available/;
if (!(regex.test(document.body.innerText))){
chrome.runtime.sendMessage({id: "check", alertWork: true});
}
popup.js
document.addEventListener('DOMContentLoaded', function() {
var startEverything = document.getElementById('startEverything');
var stopEverything = document.getElementById('stopEverything');
stopEverything.addEventListener('click', function() {
chrome.tabs.query({active: true, currentWindow: true}, function (arrayOfTabs) {
activeTabId = arrayOfTabs[0].id;
chrome.runtime.sendMessage({currTab: activeTabId, id: "button", startEverything: false});
});
});
startEverything.addEventListener('click', function() {
chrome.tabs.query({active: true, currentWindow: true}, function (arrayOfTabs) {
activeTabId = arrayOfTabs[0].id;
chrome.runtime.sendMessage({currTab: activeTabId, id: "button", startEverything: true});
});
});
}, false);
background.js
var band = false;
var alertaMGS = new Audio();
alertaMGS.src = "Codec.mp3";
var mirr;
chrome.runtime.onMessage.addListener(function(message){
if((message.startEverything) && (message.id === "button")) {
chrome.browserAction.setBadgeBackgroundColor({tabId: message.currTab, color: [30, 144, 255, 200] });
chrome.browserAction.setBadgeText({tabId: message.currTab, text: 'An'});
mirr=message.currTab;
chrome.alarms.create('recarga',{periodInMinutes: 0.1});
band=true;
}
else if((!message.startEverything) && (message.id === "button")) {
chrome.browserAction.setBadgeText({tabId: message.currTab, text: ''});
chrome.alarms.clear('recarga');
band=false;
}
});
chrome.alarms.onAlarm.addListener(function (){
chrome.browserAction.setBadgeBackgroundColor({tabId: mirr, color: [30, 144, 255, 200] });
chrome.browserAction.setBadgeText({tabId: mirr, text: 'An'});
chrome.tabs.reload(mirr);
band=true;
});
chrome.runtime.onMessage.addListener(function(message){
if((message.alertWork) && (message.id === "check")&&(band)){
chrome.browserAction.setBadgeBackgroundColor({tabId: mirr, color: [30, 144, 255, 200] });
chrome.browserAction.setBadgeText({tabId: mirr, text: 'An'});
alertaMGS.play();
alert('It changed!');
}
});