User:Technical 13/vector.js

/* Special:DoubleRedirects project */ if(mw.config.get("wgCanonicalSpecialPageName") === "DoubleRedirects"){ if(mw.config.get('wgUserGroups').indexOf('steward') !== -1 || mw.config.get('wgUserGroups').indexOf('bot') !== -1){ //		if(mw.config.get('wgUserGroups').indexOf('bot') === -1){ function demoteSelf{ $.ajax({					url: mw.config.get('wgScriptPath') + '/api.php?action=userrights&remove=bot&token=' + rightsToken + '&user=' + encodedUsername + '&reason=' + encodeURIComponent("Done with bot bit for processing Special:DoubleRedirects auto-magically"),					type: 'POST',					success: function{						alert("You have removed yourself from the bot group."); console.warn("You have removed yourself from the bot group.");					},					fail: function{						alert("Something went wrong and you have NOT removed yourself from the bot group!"); console.error("Something went wrong and you have NOT removed yourself from the bot group!");					}				}); }			function fixDoublesRedirects{ var succeeded = false; var editToken = mw.user.tokens.get("editToken").replace(/\+\\$/g, '%2B%5C'); var nextLink = $(".mw-nextlink").html; var limit = document.location.href.slice(document.location.href.search("limit=")+6, document.location.href.search("&")); var editSummary = encodeURIComponent("Fixing Special:DoubleRedirects using Double redirect fixer"); if(nextLink !== null && (!$.isNumeric(limit) || limit === "")){ limit = document.location.href.slice(document.location.href.search("limit=")+6); }				else if(nextLink !== null && limit !== 1000){ setTimeout(function{location = '?limit=1000'},1); }				$("ol.special").find("li").each(function{					var doubleRedirect = $(this).find("a:first").attr("title");					var redirectTarget = $(this).find("a:last").attr("title");					var writeRedirect = encodeURIComponent("#REDIRECT " + redirectTarget + ""); /* Let's not make any edits just yet... Get the rest of the logic ready first. Log to console what "would be edited" though for now */ // TRON console.info('url: ' + mw.config.get('wgScriptPath') + '/api.php?action=edit&title=' + encodeURIComponent(doubleRedirect) + '&summary=' + editSummary + '&minor=1&recreate=1&bot=1&text=' + writeRedirect + '&token=' + editToken);				/*					$.ajax({ url: mw.config.get('wgScriptPath') + '/api.php?action=edit&title=' + encodeURIComponent(doubleRedirect) + '&summary=' + editSummary + '&minor=1&recreate=1&bot=1&text=' + writeRedirect + '&token=' + editToken, type: 'POST', success: function { succeeded = true; }					});				*/				});				demoteSelf; }			function promoteSelf{ var isBot = confirm("You must manually assign yourself into the bot group to run this script for now.\nCopy and paste URL is:\n\t\thttp://ddowiki.com/page/Special:UserRights/" + encodedUsername + "\nCustom reason to use is:\n\tAdding bot bit to process Special:DoubleRedirects auto-magically."); if (!isBot){ throw ''; } else { fixDoublesRedirects; } /*				$.ajax({					url:mw.config.get('wgScriptPath') + '/api.php?action=userrights&add=bot&token=' + rightsToken + '&user=' + encodedUsername + '&reason=' + encodeURIComponent("Adding bot bit to process Special:DoubleRedirects auto-magically"),					type: 'POST',					success: function {						alert("You have temporarily assigned yourself to the bot group."); console.warn("You have temporarily assigned yourself to the bot group.");						fixDoublesRedirects;					},					fail: function {						alert("You have NOT assigned yourself to the bot group!"); console.error("You have NOT assigned yourself to the bot group!");					}				}); }			var rightsToken = ""; var encodedUsername = encodeURIComponent(mw.config.get('wgUserName')); $.ajax({				url: mw.config.get('wgScriptPath') + '/api.php?action=query&format=json&list=users&ustoken=userrights&ususers=' + encodedUsername,				dataType: 'json',				success: function(getToken) {					rightsToken = getToken.query.users[0].userrightstoken.replace(/\+\\$/, '%2B\\'); console.info(rightsToken);					promoteSelf;				}			}); //		}	} }