使用 Inspect Element 在 FireFox 中更改 javascript 代码
Change javascript code in FireFox using Inspect Element
这是 javascript 代码:
<script type="text/javascript">
var javascript_countdown = function ()
{
var time_left = 10; //number of seconds for countdown
var keep_counting = 1;
var no_time_left_message = 'Please Activate Javascript.';
function countdown()
{
if(time_left < 2)
{
keep_counting = 0;
}
time_left = time_left - 1;
}
function add_leading_zero( n )
{
if(n.toString().length < 2)
{
return '0' + n;
}
else
{
return n;
}
}
function format_output()
{
var hours, minutes, seconds;
seconds = time_left % 60;
minutes = Math.floor(time_left / 60) % 60;
hours = Math.floor(time_left / 3600);
seconds = add_leading_zero( seconds );
minutes = add_leading_zero( minutes );
hours = add_leading_zero( hours );
return minutes + ':' + seconds;
}
function show_time_left()
{
document.getElementById('javascript_countdown_time').innerHTML = format_output();//time_left;
document.getElementById('javascript_countdown_time_bottom').innerHTML = format_output();//time_left;
}
function no_time_left()
{
//document.getElementById('javascript_countdown_time').innerHTML = no_time_left_message;
//alert("");
document.FormAzmoon.submit();
}
return {
count: function () {
countdown();
show_time_left();
},
timer: function () {
javascript_countdown.count();
if(keep_counting) {
setTimeout("javascript_countdown.timer();", 1000);
} else {
no_time_left();
}
},
init: function (n) {
time_left = n;
javascript_countdown.timer();
}
};
}();
javascript_countdown.init(601);// Time Recorder Secends
</script>
这段javascrip代码是一个页面中的反向计时器(10分钟)。
当计时器 = 0 时,它会自动提交页面。
我想操纵它来增加时间。
我认为增加时间的最佳方法是这一行:
setTimeout("javascript_countdown.timer();", 1000);
更改为:
setTimeout("javascript_countdown.timer();", 100000);
当我在 Firefox 的 Inspect Element
的 Inspector
上更改此值时,没有任何反应。
那么解决方案是什么?
如果有firefox以外的方法请教教我!
还教我如何通过控制台重写和操作函数内的变量!
JS 将在 DOM 中 运行 被解析。在 JS 有 运行 之后更改页面标记不会更改 JS 的 运行ning。您需要以其他方式更改它。
一种选择是用您自己的函数覆盖 .timer
函数。在页面脚本有 运行 之后,打开您的控制台并 运行:
// save a reference to the original function if you need to
const origTimer = javascript_countdown.timer;
javascript_countdown.timer = () => null;
这将阻止页面对 .timer
的调用执行任何操作。然后,一旦您想提交表单,只需手动调用 document.FormAzmoon.submit();
。
Also teach me how can i rewrite and manipulate a variable inside a function via console!
如果您真的不得不采用这种方法,那几乎是不可能的,请参阅 this question 了解详细信息。简而言之,您需要使用用户脚本(或在页面加载开始时 运行s 的其他内容),使用 MutationObserver 来拦截 <script>
标记的添加,以及 fiddle 及其 textContent
一旦您检测到脚本的添加。
您确定您正确使用了 setTimeout 吗?
尝试在 Inspect 中将 setTimeout 更改为此:
setTimeout(javascript_countdown.timer, 100000);
如果这不起作用,请尝试不同的浏览器。也许 Firefox 不允许您在 Inspect
中创建计时器
这是 javascript 代码:
<script type="text/javascript">
var javascript_countdown = function ()
{
var time_left = 10; //number of seconds for countdown
var keep_counting = 1;
var no_time_left_message = 'Please Activate Javascript.';
function countdown()
{
if(time_left < 2)
{
keep_counting = 0;
}
time_left = time_left - 1;
}
function add_leading_zero( n )
{
if(n.toString().length < 2)
{
return '0' + n;
}
else
{
return n;
}
}
function format_output()
{
var hours, minutes, seconds;
seconds = time_left % 60;
minutes = Math.floor(time_left / 60) % 60;
hours = Math.floor(time_left / 3600);
seconds = add_leading_zero( seconds );
minutes = add_leading_zero( minutes );
hours = add_leading_zero( hours );
return minutes + ':' + seconds;
}
function show_time_left()
{
document.getElementById('javascript_countdown_time').innerHTML = format_output();//time_left;
document.getElementById('javascript_countdown_time_bottom').innerHTML = format_output();//time_left;
}
function no_time_left()
{
//document.getElementById('javascript_countdown_time').innerHTML = no_time_left_message;
//alert("");
document.FormAzmoon.submit();
}
return {
count: function () {
countdown();
show_time_left();
},
timer: function () {
javascript_countdown.count();
if(keep_counting) {
setTimeout("javascript_countdown.timer();", 1000);
} else {
no_time_left();
}
},
init: function (n) {
time_left = n;
javascript_countdown.timer();
}
};
}();
javascript_countdown.init(601);// Time Recorder Secends
</script>
这段javascrip代码是一个页面中的反向计时器(10分钟)。
当计时器 = 0 时,它会自动提交页面。
我想操纵它来增加时间。
我认为增加时间的最佳方法是这一行:
setTimeout("javascript_countdown.timer();", 1000);
更改为:
setTimeout("javascript_countdown.timer();", 100000);
当我在 Firefox 的 Inspect Element
的 Inspector
上更改此值时,没有任何反应。
那么解决方案是什么?
如果有firefox以外的方法请教教我!
还教我如何通过控制台重写和操作函数内的变量!
JS 将在 DOM 中 运行 被解析。在 JS 有 运行 之后更改页面标记不会更改 JS 的 运行ning。您需要以其他方式更改它。
一种选择是用您自己的函数覆盖 .timer
函数。在页面脚本有 运行 之后,打开您的控制台并 运行:
// save a reference to the original function if you need to
const origTimer = javascript_countdown.timer;
javascript_countdown.timer = () => null;
这将阻止页面对 .timer
的调用执行任何操作。然后,一旦您想提交表单,只需手动调用 document.FormAzmoon.submit();
。
Also teach me how can i rewrite and manipulate a variable inside a function via console!
如果您真的不得不采用这种方法,那几乎是不可能的,请参阅 this question 了解详细信息。简而言之,您需要使用用户脚本(或在页面加载开始时 运行s 的其他内容),使用 MutationObserver 来拦截 <script>
标记的添加,以及 fiddle 及其 textContent
一旦您检测到脚本的添加。
您确定您正确使用了 setTimeout 吗? 尝试在 Inspect 中将 setTimeout 更改为此:
setTimeout(javascript_countdown.timer, 100000);
如果这不起作用,请尝试不同的浏览器。也许 Firefox 不允许您在 Inspect
中创建计时器