javascript - How to stop execution for function with Userscript -


the website want write userscript has that:

p.stream = p.class.extend({          .          .          . _processresponse: function(data) {     if (!data.items || !data.items.length) {         return null;     }     this.reached.start = data.atstart || this.reached.start;     this.reached.end = data.atend || this.reached.end;     var oldestid, newestid;     if (this.options.promoted) {         data.items.sort(p.stream.sortbypromoted);         oldestid = data.items[data.items.length - 1].promoted;         newestid = data.items[0].promoted;     } else {         data.items.sort(p.stream.sortbyid);         oldestid = data.items[data.items.length - 1].id;         newestid = data.items[0].id;     }     var position = (oldestid < this._oldestid) ? p.stream.position.append : p.stream.position.prepend;     this._oldestid = math.min(this._oldestid, oldestid);     this._newestid = math.max(this._newestid, newestid);     var prev = null;     var itemvotes = p.user.votecache.votes.items;     (var = 0; < data.items.length; i++) {         var item = data.items[i];         item.thumb = config.path.thumbs + item.thumb;         item.image = config.path.images + item.id;          item.fullsize = item.fullsize ? config.path.fullsize + item.fullsize : null;         item.vote = itemvotes[item.id] || 0;         this.items[item.id] = item;     }     return position; } }); 

i want manipulate _processresponse such item.image points source. possible userscripts? tried overriding function stated on websites not work expected. want override function, nothing other that.

as far can see, easiest , flexible way wrap _processresponse in function further operates on data after original function called:

var oldfunc = p.stream.prototype._processresponse; p.stream.prototype._processresponse = function(data) {     var ret = oldfunc.apply(this, arguments);     if(data.items && data.items.length)     {         for(var = 0, len = data.items.length; < len; ++i)         {             data.items[i].image = 'https://example.com/a.png'; // or whatever         }     }     return ret; } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -