Javascript 使用chrome扩展名更改变量

Javascript 使用chrome扩展名更改变量,javascript,google-chrome,variables,google-chrome-extension,content-script,Javascript,Google Chrome,Variables,Google Chrome Extension,Content Script,我经常使用的一个页面有一个稍微无用的超时功能,一小时后它会自动注销用户。我正试图为chrome编写一个扩展,将超时时间延长到十个小时,然而,在遇到问题之前,我从未编写过扩展。我知道内容脚本不能直接影响页面变量,但我一直在尝试使用它,但我一直无法使用它 网站中超时的代码是基本的: var x = 3600 var y = 1; var z = 300 x = x-y setTimeout("startClock()", 1000) function startClock(){

我经常使用的一个页面有一个稍微无用的超时功能,一小时后它会自动注销用户。我正试图为chrome编写一个扩展,将超时时间延长到十个小时,然而,在遇到问题之前,我从未编写过扩展。我知道内容脚本不能直接影响页面变量,但我一直在尝试使用它,但我一直无法使用它

网站中超时的代码是基本的:

var x = 3600
var y = 1;
var z = 300
    x = x-y
    setTimeout("startClock()", 1000)
function startClock(){
    x = x-y
    setTimeout("startClock()", 1000)
if(x==z){
alert("Your Session is about to expire. After a period of inactivity (60 minutes), all current session information is removed and you will be required to log in again.");
} else if (x==0) {
document.location.href = "content?module=home&page=homepg&logoutFinal=1";
}
我为扩展编写了一个基本清单文件,它使用
content\u scripts
调用
contentscript.js
,这与


我目前的愿望是拥有一个扩展,可以在页面刷新后自动将x的值重置为36000秒,或10小时。

经过一段时间的故障排除,我发现整个问题是
manifest.json
中的一个问题,特别是匹配部分。上面给出的代码有效,我链接到的文档中给出的方法也有效

感谢devnull69的快速响应,我尝试了这种方法,在解决了
manifest.json
中的问题后,它完全消除了超时。

请参阅中的@SeanDowney的答案。解决方案是清除所有超时,因为您没有页面超时的句柄,并且更改
x
可能不起作用,因为脚本运行后很可能已经开始超时
var actualCode = ['var x = 36000'].join('\n');

var script = document.createElement('script');
script.textContent = actualCode;
(document.head||document.documentElement).appendChild(script);
script.parentNode.removeChild(script);