我的朋友有一个在线网页,它有内联脚本标记,还有一个JavaScript函数:
(#1):
var domain = window.location.protocol + "//" + window.location.host + '/';
$(document).ready(function() {
var count = 5;
countdown = setInterval(function() {
if (count == 0) {
$('#countdow').hide();
$('#link-news').show()
} else {
$('#countdow').text(count);
count--
}
}, 1700);
$('#link-news').click(function() {
var urls = $('input[name=linknexttop]').val();
if (urls == 1) {
$('input[name=linknexttop]').val(2);
$.ajax({
type: "GET",
url: domain + "click.html",
data: "code=Sh9QA&token=0982ff3066a3c60dbd3ecf9bcafc801b",
contentType: "application/json; charset=utf-8",
success: function(html) {
//alert(html);
window.location = html;
}
})
}
})
});
他给出了一个难题:“我可以在不修改原始代码的情况下运行以下代码吗?”。
(#2):
$('input[name=linknexttop]').val(2);
$.ajax({
type: "GET",
url: domain + "click.html",
data: "code=Sh9QA&token=0982ff3066a3c60dbd3ecf9bcafc801b",
contentType: "application/json; charset=utf-8",
success: function(html) {
//alert(html);
window.location = html;
}
播放规则:“我只允许在原始代码下插入我的代码;因此,我不允许在代码中更改任何内容。而且,最重要的是,code=Sh9QA&token=0982ff3066a3c60dbd3ecf9bcafc801b
是随机的。”
为节省等待时间,我使用此extension来阻止countdown();
的工作;并将此代码添加到其中:
(#3):
$('#countdow').hide();
$('#link-news').show();
接下来,我试图通过urls = $('input[name=linknexttop]').val();
。我试过urls == 1;
;但是,我失败了。
我的问题是:“有没有办法通过urls = $('input[name=linknexttop]').val();
,这个游戏的所有规则都被接受了?”如果有可能,请告诉我。
答案 0 :(得分:1)
如果相关脚本位于内联script
标记中,您可以通过循环遍历脚本然后从中提取代码来找到它,并在插入的代码中使用它。
这些行中的某些内容,您将其作为script
元素插入:
(function() {
var code;
$("script").each(function() {
var match = /data=: "code=([^"]+)"/.exec($(this).text());
if (match) {
code = match[1];
return false;
}
});
$('#link-news').off("click");
$('#link-news').click(function() {
if (code) {
$('input[name=linknexttop]').val(2);
$.ajax({
type: "GET",
url: domain + "click.html",
data: "code=" + code,
contentType: "application/json; charset=utf-8",
success: function(html) {
//alert(html);
window.location = html;
}
});
}
});
})();
在上文中,我假设您应该从前一个事件处理程序接管,而不是添加它。这就是.off("click")
的作用。