根据this answer和this one 我相信我可以更改脚本src中的代码,我是对的吗?
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<link type="text/css" rel="stylesheet" href="//fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic&subset=latin,latin-ext">
<script type="text/javascript" async="" src="http://www.google-analytics.com/ga.js">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
<script src="/common/script/matomy/ads/basic.js" type="text/javascript">
<script src="/common/script/matomy/ads/offer_page.js" type="text/javascript">
<script src="/common/script/matomy/util/script2.js" type="text/javascript">
<link type="text/css" rel="stylesheet" href="/common/css/landing/style18.css">
<script src="/common/script/matomy/offer_status/script.js" type="text/javascript">
</head>
<script src="/common/script/matomy/offer_status/script.js" type="text/javascript">
if (json == "0") {
setTimeout('OfferStatusChecker.checkOfferCompletion()', 30 * 1000);
return;
}
// @include http://stats.matomy.com/click/?id=*
// @require https://gist.github.com/raw/2620135/checkForBadJavascripts.js
// @run-at document-start
// @grant unsafeWindow
// ==/UserScript==
function replaceSrcScript (scriptNode) {
//var scriptSrc = scriptNode.textContent;
//var scriptSrc = scriptNode.setAttribute("src", theCode() );
/*
scriptSrc = scriptSrc.replace (
/if\s\(json\s==\s"0"\)\s+{\s+setTimeout\('OfferStatusChecker\.checkOfferCompletion\(\)',\s30\s\*\s1000\);\s+return;\s+}/,
""
);*/
//addJS_Node (null, null, scriptSrc);
//addJS_Node (scriptSrc);
}
/*
checkForBadJavascripts ( [
[ true, /script\.js/, replaceSrcScript ]
] );
*/
checkForBadJavascripts ( [
[ true,
/script\.js/,
function () {
addJS_Node (theCode.toString() );
}
]
] );
function theCode() {
//inside here the script.js code modified, without the lines I want remove
}
<script>
$(document).ready(function(){
$(window).resize(function() {
var theFrame = $("#offer");
var topHeight = $(".offer_info").height();
var newHeight = $(document.body).height() - topHeight;
theFrame.height(newHeight);
});
OfferStatusChecker.checkOfferStatusURL = 'http://stats.matomy.com/offerstatus/?id=30a54408-64fb-42d7-9279-70afb747e364';
OfferStatusChecker.onOfferCompleted = onOfferCompleted;
OfferStatusChecker.start();
setTimeout('initUI()', 1 * 1000);
});
function initUI() {
$(".inst_bar").slideDown('slow');
}
function onOfferCompleted() {
$(".inst_bar").slideUp();
$('.top_bar').slideUp('slow', function() {
$(".status").html('Offer completed!');
$(".right_side").css("background-image", "url('/common/css/landing/images/completed.gif')");
$(".med_side").hide();
$(".left_side").hide();
$('.top_bar').slideDown();
});
}
</script>
没有将src路径更改为file://...script.js,我读了一次,使用不安全,解决了它。
因为,checkForBadJavascripts属于布洛克亚当斯,我希望他能看看这个问题。
我设法替换了src,用于内联脚本,它删除了ReferenceErrors并读取了代码。但这是正确的方法吗?我的意思是,它是否适用于任何其他情况我有一个src脚本,而不仅仅是这个目标页面?
function replaceSrcScript () {
var removeFunction = theCode.toString();
removeFunction = removeFunction.replace(/\s?function\stheCode\(\)\s?\{\s+/ , "");
removeFunction = removeFunction.slice( 0 , removeFunction.lastIndexOf("}") - 1 );
addJS_Node (removeFunction);
}
checkForBadJavascripts ( [
[ true, /script\.js/, replaceSrcScript ]
] );
function theCode() {
//inside here the script.js code modified, without the lines I want remove
}
我的问题的目标是了解修改src脚本的正确解决方案,而不仅仅是让它在目标页面上运行。