Jump to content

User:DannyS712 test/Global watchlist doc.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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>
/* jshint maxerr: 999 */
/* globals GlobalWatchlist */
$(function (){
var GlobalWatchlistDoc = {};
window.GlobalWatchlistDoc = GlobalWatchlistDoc;
var GlobalWatchlist = window.GlobalWatchlist;

GlobalWatchlistDoc.config = {
	docVersion: '1.1',
	scriptVersion: '6.6.3'
};
GlobalWatchlistDoc.run = function () {
	var api = new mw.ForeignApi(`//meta.wikimedia.org/w/api.php`),
		map = {},
		qqq = GlobalWatchlist.i18n.qqq,
		units = GlobalWatchlist.i18n.units,
		keys = Object.keys( units );
	console.log( api, qqq, units );
	keys.forEach( (k) => {
		map[ `Translations:User:DannyS712/Global watchlist/Translate/${units[k]}/qqq` ] = qqq[ k ];
	});
	console.log( map );
	var pages = Object.keys( map );
	pages.forEach( (p) => {
		console.log( p, map[p] );
		api.postWithEditToken( {
			action: 'edit',
			title: p,
			text: map[p],
			summary: `Automatically update documentation (v. ${GlobalWatchlistDoc.config.docVersion}`,
			assert: 'user',
		} ).always( function ( response ) {
			console.log( response );
		});
	});
};
} );
mw.loader.using( 'mediawiki.ForeignApi', function () {
	$(document).ready( function () {
		if ( mw.config.get('wgNamespaceNumber') === -1 ){
			var page = mw.config.get('wgCanonicalSpecialPageName');
			if ( page === 'Blankpage'){
				var page2 = mw.config.get( 'wgTitle' ).split('/');
				if ( page2[1] ) {
					if ( page2[1] === 'GlobalWatchlistDoc' ) {
						mw.loader.getScript( '/w/index.php?title=User:DannyS712 test/watch.js&action=raw&ctype=text/javascript' ).then( function () {
							GlobalWatchlist.init( 5 );
							console.log( 'Ready to run' );
						} );
					}
				}
			}
		}
	} );
} );