This is an old revision of this page, as edited by MusikAnimal(talk | contribs) at 05:02, 12 May 2014(←Created page with 'if($("#mw-watchlist-resetbutton").is(":visible")) { $("#mw-watchlist-resetbutton").after( "<form id='import_watchlist_form'><fieldset style='margin:20px 0px'>...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.Revision as of 05:02, 12 May 2014 by MusikAnimal(talk | contribs)(←Created page with 'if($("#mw-watchlist-resetbutton").is(":visible")) { $("#mw-watchlist-resetbutton").after( "<form id='import_watchlist_form'><fieldset style='margin:20px 0px'>...')
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page.
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.
if($("#mw-watchlist-resetbutton").is(":visible")){$("#mw-watchlist-resetbutton").after("<form id='import_watchlist_form'><fieldset style='margin:20px 0px'>"+"<legend>Import watchlist</legend>"+"<div><label for='import_watchlist_username'>Source watchlist username:</label><input type='text' id='import_watchlist_username' /></div>"+"<div><label for='import_watchlist_token'>Source watchlist token:</label><input type='text' id='import_watchlist_token' /></div>"+"<div id='import_watchlist_progress'></div>"+"<button id='import_watchlist_submit'>Import</button>"+"</fieldset></form>");$("#import_watchlist_form").submit(function(e){$("#import_watchlist_form").find("input,button").prop("disabled",true);$("#import_watchlist_progress").html("Fetching watchlist...")importWatchlistArray=[];// do this craziness until Promises are more well supportedtempCount=0;tempFn=function(){deletetempFn;// no dup calls$("#import_watchlist_progress").html(importWatchlistArray.length+" watches queued for import");for(vari=0;i<importWatchlistArray.length;i+=50){importWatches(importWatchlistArray.slice(i,i+49),function(ret){tempCount+=50;if(tempCount<importWatchlistArray.length){$("#import_watchlist_progress").html("Working... "+tempCount+" of "+importWatchlistArray.length+" imported");}else{// done$("#import_watchlist_progress").html("<div style='font-weight:bold;color:#006400'>Complete! "+importWatchlistArray.length+" pages imported to watchlist :)</div>");deletetempCount;// why not}if(!ret){$("#import_watchlist_progress").after("<div style='color:red'>Error while importing batch "+parseInt(i/50)+". Not all pages may have imported.</div>")}});}}getWatchlist(null,tempFn);e.preventDefault();});}functionimportWatches(watches,fn){data={action:"watch",format:"json",titles:watches.join("|"),token:mw.user.tokens.get('watchToken')}$.ajax({type:"POST",dataType:"json",url:mw.util.wikiScript('api'),data:data,success:function(data){returnfn(true);},error:function(data){returnfn(false);}});}functiongetWatchlist(wrcontinue,fn){$.getJSON(mw.util.wikiScript('api')+"?action=query&list=watchlistraw&wrowner="+$('#import_watchlist_username').val()+"&wrtoken="+$('#import_watchlist_token').val()+(wrcontinue?"&wrcontinue="+wrcontinue:"")+"&wrlimit=500&format=json",null,function(data){// first push to arrayfor(vari=0;i<data.watchlistraw.length;i++){importWatchlistArray.push(data.watchlistraw[i].title);}if(data.watchlistraw.length===500){// may still be more to exportif(data['query-continue']&&data['query-continue'].watchlistraw&&data['query-continue'].watchlistraw.wrcontinue){getWatchlist(data['query-continue'].watchlistraw.wrcontinue,function(){if(data.watchlistraw.length<500){// we're at the endtempFn();}});}}else{tempFn();}});}functiongetAjax(url){// Return a new promise.returnnewPromise(function(resolve,reject){// Do the usual XHR stuffvarreq=newXMLHttpRequest();req.open('GET',url);req.onload=function(){// This is called even on 404 etc// so check the statusif(req.status==200){// Resolve the promise with the response textresolve(req.response);}else{// Otherwise reject with the status text// which will hopefully be a meaningful errorreject(Error(req.statusText));}};// Handle network errorsreq.onerror=function(){reject(Error("Network Error"));};// Make the requestreq.send();});}