修改作为网页一部分下载的javascript
Modify javascript that was downloaded as part of a web page
我想修改作为网页一部分下载的Javascript。
我有这个页面:https://discussions.apple.com/thread/7629335
我想修改函数jspaginate.init。我已经说到这里了:
console.log(window.jspaginate)
Object { data: Object, loading: false, init: jspaginate.init(), update: jspaginate.update(), pushState: jspaginate.pushState(), loadingSequence: jspaginate.loadingSequence(), removeLoading: jspaginate.removeLoading(), updateUI: jspaginate.updateUI(), getData: jspaginate.getData() }
undefined
console.log(window.jspaginate["init"])
function jspaginate.init()
console.log(window.jspaginate["init"].toString())
function (action, last){
var view = this,
target, current;
... clipped ...
背景:这个页面包含了大量的javascript。jspaginate函数是从站点服务器下载的。然而,我需要更改函数jspaginate。我无法访问服务器。我想换一份jspaginate。我知道我需要在每次下载时更改功能。
我使用GreaseMonkey插入一些javascript。
用它的新定义重写init函数,如下所示:
window.jspaginate.init = function() {
console.log('there you go');
}
下面是我使用的代码。自从我皈依了西班牙语。init初始化为字符串并修改字符串,我必须将字符串转换为函数。我通过eval函数进行了转换。
var debug = 1;
/* Get the string of the function to change */
var stringed = jspaginate["init"].toString();
if ( debug ) console.log ("--> cloneGotoChange: 'n" + stringed);
/* Place the added code as the last statement in the function jspaginate["init"]
Find the function closing } */
position = stringed.lastIndexOf("}");
/* Change the downloaded javascript */
var newCode = stringed.substr(0, position)
+ " console.log ('"--> before '" ); cloneGotoUpate(); console.log ('"--> after '" ); "
+ stringed.substr(position);
/* Inject the changed code
need to use the eval function to make a function assignment instead of a string assignment */
eval( 'jspaginate["init"] =' + newCode);
if ( debug ) console.log (console.log(window.jspaginate["init"].toString()));
相关文章:
- 如何使用javascript或html下载PDF格式的填写表单
- Javascript运行php文件,然后下载文件
- 通过javascript下载文件时设置文件名
- 在同一选项卡中启动下载,而无需在Javascript中打开新选项卡或窗口
- 如何用javascript下载画布图像(base64)
- 下载HTML5/Javascript MOBILE应用程序中的PDF文件
- 多个mp3下载链接到一个zip文件,用于下载javascript或jquery
- 多个下载链接到一个zip文件,然后再下载javascript
- 下载javascript文件,但不要立即对其进行评估
- 如何从网站下载 Javascript 数组
- 下载javascript时的图像名称
- 作为非管理员用户,可以请求下载javascript文件
- 我如何禁用下载javascript与Loadrunner Web(点击和脚本)
- 下载javascript文本文件
- 在浏览器中下载Javascript文档.Web API
- 在不下载Javascript中的整个文件的情况下,检查远程JSON是否比本地JSON更新
- 使用Python从网站下载Javascript文件
- 如何下载javascript图片库
- 用户不应该既不能下载javascript代码/文件也不能下载css文件
- 使用file_get_content下载javascript输出