Exe*_*ute 7 google-chrome-extension
你能再帮我解决这个问题吗?Uncaught Error: Extension context invalidated.
我在 chrome://extensions 中遇到错误。
我正在尝试制作一个计时器,每当您空闲时,假设 5 秒就会触发警报,您需要移动鼠标来停止警报,并且我需要将其与其他打开的选项卡同步,这就是我使用的chrome.storage.onChanged.addListener
原因谢谢wOxxOm的推荐。它工作得很好,但我收到了这个错误。
*manifest.json*
{
"manifest_version": 2,
"name": "Toool",
"description": "Description ....",
"version": "1.0.0",
"icons": { "128": "icon_128.png" },
"permissions": ["activeTab", "storage"],
"content_scripts": [
{
"matches": [
"*://*.google.com/*"
],
"css":[
"bootstrap/css/bootstrap-iso.css",
"css/animate.min.css",
"css/all.css",
"css/style.css"
],
"js": [
"js/jquery.min.js",
"js/contentscript.js"
]
}
],
"web_accessible_resources": [
"index.html",
"audio/*",
"webfonts/*"
]
}
Run Code Online (Sandbox Code Playgroud)
*contentscript.js*
// So here is what I've been working so far..
//Instead of popup, I am using this to inject html directly to the DOM.
$('body').prepend('<div class="idletimer-element bootstrap" style="display: block"></div>');
$.get(chrome.extension.getURL('index.html'), function(data) {
$(data).appendTo('.idletimer-element');
});
var audio_url = chrome.runtime.getURL('audio/bells.mp3');
var audio = new Audio(audio_url);
var timerStartIn = 6;
var timer = -1;
var idle = null;
var timeOut = null;
var MouseMoved = 0;
//Initialize the mouse storage value
chrome.storage.local.set({"mouseStorage": MouseMoved}, function() {
console.log('Mouse Moved: ' + MouseMoved);
});
$(document).on('mousemove', function(){
// I used validation here to just execute it when necessary but the problem didn't fix it at all :(
clearTimeout(timeOut);
if(MouseMoved == 0){
MouseMoved = 1;
chrome.storage.local.set({"mouseStorage": MouseMoved}, function() {
console.log('Mouse Moved: ' + MouseMoved);
});
}
timeOut = setTimeout(function(){
MouseMoved = 0;
chrome.storage.local.set({"mouseStorage": MouseMoved}, function() {
console.log('Mouse Moved: ' + MouseMoved);
});
}, 1000);
});
chrome.storage.onChanged.addListener(function(changes, namespace) {
if(changes['mouseStorage']){
IT();
}
});
function IT(){
clearInterval(idle);
timer = -1;
audio.pause(); // Stop playing
audio.currentTime = 0; // Reset time
timerStartIn = 6;
$('.timer').html('User is active');
$('.timer-content i').removeClass('animated shake infinite');
$('.it-status').html('<span> <strong>Reviewer Status: </strong> <span class="active m-r-10">Active</span></span>');
idle = setInterval(function(){
timer++;
//console.log(timer);
timerStartIn--;
$('.timer').html('User is active. <br> Idle starts in ' + timerStartIn + ' second/s');
if(timer >= 5){
//Idle
//console.log('Idle');
$('.timer').html('You are idle for about <br> ' + secondsToHms(timer - 5) +'.');
//console.log(timer);
audio.play();
$('.timer-content i').addClass('animated shake infinite');
$('.it-status').html('<span> <strong>Reviewer Status: </strong> <span class="idle m-r-10">Idle</span></span>');
}
}, 1000);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4526 次 |
最近记录: |