historystamp historystamp - 3 months ago 32
Javascript Question

Modify javascript that was downloaded as part of a web page

I would like to modify the Javascript that is downloaded as part of a web page.

I have this page:
https://discussions.apple.com/thread/7629335

I would like to modify the function jspaginate.init. I've gotten this far:

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 ...


background:
This page includes lots of javascript. The function jspaginate is download from the site server. Nevertheless, I need to change the function jspaginate. I do not have access to the server. I want to change my copy of jspaginate. I know that I need to change the function every time it is downloaded.

I'm using GreaseMonkey to insert some javascript.

Answer

Just override the init function with its new definition, like below:

window.jspaginate.init = function() { 
   console.log('there you go');
}