【发布时间】:2014-08-20 01:14:20
【问题描述】:
我经常使用的页面有一个有点无用的超时功能,这样一小时后它会自动将用户注销。我正在尝试为 chrome 编写一个扩展,将这个超时时间延长到十小时,但是因为我在遇到问题之前从未编写过扩展。我知道内容脚本不能直接影响页面变量,但是我一直在尝试使用 Method 2 on this page,但我无法开始工作。
网站中的超时代码是基本的:
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_scripts 调用contentscript.js 的扩展编写了一个基本清单文件,这与Method 2 example. 中给出的几乎相同
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);
我目前的愿望是有一个扩展程序,可以自动将 x 的值重置为 36000 秒,即页面刷新后 10 小时。
【问题讨论】:
-
查看@SeanDowney 在stackoverflow.com/questions/3847121/… 中的回答。解决方案是清除所有超时,因为您没有处理页面超时并且更改
x可能不起作用,因为一旦您的脚本运行,超时很可能已经开始
标签: javascript google-chrome variables google-chrome-extension content-script