User:Gryllida/js/TagSpam.js

From Wikinews, the free news source you can write!
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins

//<nowiki>
// Adds new "tag spam" link, 
// near "What links here" and "Related changes". 
// In the timeless skin this is conveniently located 
// in the right sidebar. If you are using another 
// skin and the location of the buttons is not 
// convenient to you, please let me know. 
//
// You clicking the link immediately inserts
// "{{speedy|spam}} to the top of the current page,
// and removes the "tag spam" link from the sidebar.

var tagspam = {
	tag: function () {
		var api = new mw.Api();
		api.postWithToken("edit", {
				action: 'edit',
				title: mw.config.get ('wgPageName'),
				prependtext: '{{speedy|spam}}',
				summary: 'added status tag: {{[[Template:speedy|speedy]]}} ([[User:Gryllida/js/TagSpam.js|s]])'
			}).done(function (data){
		    	api.get( {
		    		action: 'parse',
		    		page: mw.config.get( 'wgPageName' ),
		    		prop: 'text'
				} ).done( function ( data ) {
					console.log('got html');
					text = data.parse.text['*'];
					$('.mw-parser-output').replaceWith(text);
					$('#tagspam').fadeOut();
				});
			});
	},
	init: function () {
		var t = document.getElementById('t-whatlinkshere');
        	if (!t) return;
		var li = document.createElement('li');
		var a = document.createElement('a');
		a.setAttribute('href', 'javascript:tagspam.tag()');
		a.id = 'tagspam';
		a.appendChild(document.createTextNode('tag spam'));
		li.appendChild(a);
		t.parentNode.appendChild(li);
	}
};

mw.loader.using(['mediawiki.api'], function () {
tagspam.init();
});

// </nowiki>