User:Ciencia Al Poder/unwatchapi.js

// Performs an endless loop to unwatch items from your watchlist (function {	var _wait = 1000, // Time to wait between requests, in milliseconds	_limit = 50, // Quantity of elements to unwatch on each request	_init = function {		if (window.confirm('do you want to start?')) {			mw.loader.using('mediawiki.api', _start);		}	},	_start = function {		var api = new mw.Api;		api.get({action: 'query', prop: 'info', intoken: 'watch', generator: 'watchlistraw', gwrlimit: '1'/*, gwrnamespace: '6'*/}).done(_tokenReceived);	},	_tokenReceived = function(data) {		var token = null;		if (data && data.query && data.query.pages) {			for (var pg in data.query.pages) {				token = data.query.pages[pg].watchtoken;				break;			}		}		if (!token) {			console.log('DONE');			return;		}		window.setTimeout(function(ptoken) { return function { _unwatchBatch(ptoken); };		}(token), _wait);	},	_unwatchBatch = function(token) {		var api = new mw.Api;		api.post({action: 'watch', token: token, unwatch: '', generator: 'watchlistraw', gwrlimit: _limit/*, gwrnamespace: '6'*/}).done(_unwatchDone);	},	_unwatchDone = function(data) {		if (data && data.watch) {			for (var wp in data.watch) {				if (typeof data.watch[wp].unwatched == 'string') {					console.log('Unwatched: '+data.watch[wp].title);				}			}		}		// Start over again		window.setTimeout(_start, _wait);	};	$(_init); });