User:Fenakhay/common.js

From Wiktionary, the free dictionary
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 Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

This JavaScript is executed for Fenakhay on every page load.


jQuery(document).ready(function ($) {
	console.log("executing common.js");

	try {

		mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:BrandonXLF/QuickEdit.js&action=raw&ctype=text/javascript');
		mw.loader.load('https://en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js/load.js&action=raw&ctype=text/javascript');

		importScript("User:Erutuon/scripts/cleanup.js");
		importScript("User:Erutuon/scripts/addAutoCat.js");
		importScript("User:Erutuon/scripts/phonemicGreekTransliteration.js");
		importScript("User:Erutuon/scripts/reconstructedCategories.js");
		importScript("User:Erutuon/scripts/gadgets-definition.js");
		importScript("User:Fenakhay/extraCategoryLinks.js");

		/********* rollback msg *********/
		$('span.mw-rollback-link a').each(function () { if (-~this.href.indexOf('&action=rollback&') && this.href.indexOf('summary=') < 0) this.href += '&summary=Reverted%20edits%20by%20%5B%5BSpecial%3AContributions%2F%242%7C%242%5D%5D.%20If%20you%20think%20this%20rollback%20is%20in%20error%2C%20please%20leave%20a%20message%20on%20my%20%5B%5BUser%20talk%3AFenakhay%7Ctalk%20page%5D%5D.' });

		/********* silent rb *********/
		$('#p-tb ul').append('<li id="fenakhay-t-rb-lta"><a href="javascript:void(0)" id="fenakhay-t-rb-lta-link">Hide RB msgs</a></li>');
		$('#fenakhay-t-rb-lta-link').click(function () {
			$('span.mw-rollback-link a').each(function () {
				if (-~this.href.indexOf('&action=rollback&')) {
					if (this.href.indexOf('summary=') >= 0)
						this.href = this.href.split('&summary=')[0];
					this.href += '&summary=rv%2Fv';
				}
			});
			alert("ok");
		});

		/********* mass revdel *********/
		mw.loader.load('//en.wiktionary.org/w/index.php?title=User:Surjection/massRevdel.js&action=raw&ctype=text/javascript');

		/********* mass rv *********/
		{
			var nukeLink = $('.mw-changeslist-links .mw-contributions-link-nuke');
			if (nukeLink) {
				var linkSpan = nukeLink.parent();
				var rv = $('<a href="#">mass revert</a>');
				rv.click(function (e) {
					if (confirm('Are you sure?')) {
						$('.mw-contributions-current span.mw-rollback-link a').each(function () {
							if (-~this.href.indexOf('&action=rollback&')) {
								window.open(this.href, '_blank');
							}
						});
						alert("OK");
					}
				});
				$('<span></span>').append(rv).insertAfter(linkSpan);
			}
		}

		/********* quick move revert *********/
		$('.mw-logline-move a[href*="wpReason=revert"]').each(function () {
			if (this.href.indexOf('&autosubmitmove=1') < 0)
				this.href += '&wpLeaveRedirect=0&autosubmitmove=1';
		});
		if (mw.config.get("wgPageName").startsWith("Special:MovePage") && new URL(window.location.href).searchParams.get("autosubmitmove") == '1') {
			$('button[name="wpMove"]').click();
		}

		/********* quick LTA block *********/
		var ltaBlockLink = '/wiki/Special:Block/@@@?wpCreateAccount=1&wpDisableUTEdit=1&wpExpiry=indefinite&wpHardBlock=1&wpReason=Vandalism&wpReason-other=LTA&wpDisableEmail=1&autosubmitblock=0';
		var spamBlockLink = '/wiki/Special:Block/@@@?wpCreateAccount=1&wpDisableUTEdit=1&wpExpiry=indefinite&wpHardBlock=1&wpReason=Promotional%20material%2Fspamming&wpDisableEmail=1&autosubmitblock=0';
		var proxyBlockLink = '/wiki/Special:Block/@@@?wpCreateAccount=1&wpDisableUTEdit=1&wpExpiry=6+months&wpHardBlock=1&wpReason=Suspected+%5B%5BWiktionary%3AProject+-+Open+proxies%7Copen+proxy%5D%5D&autosubmitblock=0';
		var botBlockLink = '/wiki/Special:Block/@@@?wpCreateAccount=1&wpDisableUTEdit=1&wpExpiry=indefinite&wpHardBlock=1&wpReason=Unauthorized+bot+%28see+%5B%5BWT%3ABOT%5D%5D%29&wpDisableEmail=1&autosubmitblock=0';
		var hiddenBlockLink = '/wiki/Special:Block/@@@?wpCreateAccount=1&wpDisableUTEdit=1&wpExpiry=indefinite&wpHardBlock=1&wpDisableEmail=1&autosubmitblock=0';
		if (mw.config.get("wgPageName").startsWith("Special:Contributions/")) {
			var isIP = !Array.prototype.find.call(document.getElementsByTagName("a"), function (a) { return (a.getAttribute("title") || '').slice(0, 5) == "User:" });
			var buttons = isIP ? [["proxy block", proxyBlockLink]] : [["LTA block", ltaBlockLink], ["stealth block", hiddenBlockLink], ["spam block", spamBlockLink], ["bot block", botBlockLink]];
			var pn = mw.config.get("wgPageName");
			var usern = pn.slice(pn.indexOf("/") + 1);
			var makeLink = function (url) { return url.replace("@@@", usern); };
			buttons.forEach(function (button) {
				$('#contentSub a[href*="Special:Block/"]').first().after(' | <a href="' + makeLink(button[1]) + '">(' + button[0] + ')</a>');
			});
		}
		if (mw.config.get("wgPageName").startsWith("Special:Block/") && new URL(window.location.href).searchParams.get("autosubmitblock") == '1') {
			$('button[value="Block this user"]').click();
		}

		/********* block IPv6 /64 by default *********/
		if (mw.config.get("wgPageName").startsWith("Special:Contributions/") || mw.config.get("wgDiffNewId")) {
			var blockIPv6 = /Special:Block\/[0-9A-Fa-f]{0,4}:[0-9A-Fa-f]{0,4}:[0-9A-Fa-f]{0,4}:[0-9A-Fa-f]{0,4}:[0-9A-Fa-f]{0,4}:[0-9A-Fa-f]{0,4}:[0-9A-Fa-f]{0,4}:[0-9A-Fa-f]{1,4}$/;
			$('a[href*="/Special:Block/"]').each(function (i, element) {
				element.href = element.href.replace(blockIPv6, function (m) { return m + "/64"; });
			});
		}

		/********* autofeed *********/
		if (mw.config.get('wgAction') == 'edit' && new URLSearchParams(document.location.search).has('autofeedtext')) {
			var editField = $('#wpTextbox1');
			if (editField.val()) {
				var newtext = document.createElement('textarea');
				newtext.setAttribute('readonly', true);
				newtext.setAttribute('rows', 20);
				newtext.textContent = new URLSearchParams(document.location.search).get('autofeedtext');
				document.getElementById('mw-content-text').insertBefore(newtext, document.getElementById('editform'));
			} else {
				editField.val(new URLSearchParams(document.location.search).get('autofeedtext'));
			}
		}
	} catch (e) {
		console.error(e);
	}

	mw.hook("wikipage.content").add(function () { console.log("wikipage.content hook"); });

	console.log("executed common.js");
});