Jump to content

User:DannyS712 test/watch demo.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<nowiki>
$(function (){
var scriptUrl = mw.config.get( 'wgScriptPath' ) + '/api.php';

mw.loader.using( 'mediawiki.util', function () {
    $(document).ready( function () { 
    	var page = mw.config.get('wgPageName');
    	console.log( page );
    	if ( page && page === 'Special:BlankPage/Global'){
    		GlobalWatch();
    	}
    } );
} );
async function GlobalWatch(){
	var watched = await getWatch();
	var serial = new XMLSerializer();
	var watchedString = serial.serializeToString( watched );
	console.log( watchedString );
	
	var content = $('#mw-content-text')[0];
	content.innerHTML = ''; // blanked
	content.innerText = watchedString;
}
function getWatch () {
	return new Promise((resolve) => {
		var getter = {
	        action: 'feedwatchlist',
	        format: 'json'
		};
		$.get( mw.config.get( 'wgScriptPath' ) + '/api.php', getter, function( response ) {
			console.log(response);
			//location.reload();
			resolve(response);
		} );
	} );
}
});
//</nowiki>