Created
October 5, 2017 01:49
-
-
Save Colouratura/1366ebc68b982fa5899c0c8958a75827 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var CheckAdoptions = function () { | |
this._adoptions = []; | |
this._concerns = []; | |
return this; | |
}; | |
CheckAdoptions.prototype.__fetchAdoptionsList = function () { | |
if (this._adoptions.length > 0) { | |
this._adoptions = []; | |
this._concerns = []; | |
} | |
return new Promise(function (resolve, reject) { | |
var _payload = { | |
action: 'query', | |
list: 'recentchanges', | |
rcprop: 'title|sizes', | |
rcnamespace: '118', | |
format: 'json' | |
}; | |
$.ajax({ | |
url: mw.util.wikiScript('api'), | |
type: 'POST', | |
dataType: 'JSON', | |
data: _payload | |
}) | |
.success(function(data) { | |
resolve(data.query.recentchanges); | |
}) | |
.error(function(err, status) { | |
reject(err, status); | |
}); | |
}); | |
}; | |
CheckAdoptions.prototype.__markConcerns = function () { | |
if (this._concerns.length === 0) return; | |
var __changeLinks = document.querySelectorAll('.mw-conntent a'); | |
for (var i = 0; i < __changeLinks.length; i++) { | |
if (this._concerns.includes(__changeLinks[i].title)) | |
__changeLinks[i].parentNode.parentNode.style.backgroundColor = '#FF0000'; | |
} | |
this._adoptions = []; | |
this._concerns = []; | |
}; | |
CheckAdoptions.prototype.init = function () { | |
if (mw.config.get('wgCanonicalSpecialPageName') !== 'Recentchanges') | |
return; | |
this.__fetchAdoptionsList() | |
.then( | |
function (data) { | |
for (var i = 0; i < data.length; i++) { | |
if (data[i].oldlen > data[i].newlen) | |
this._concerns.push(data[i].title); | |
} | |
this.__markConcerns(); | |
}.bind(this), | |
function (error, status) { | |
console.error('Error: [' + status + '] ' + error); | |
} | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment