Jump to content

User:AlanM1/common.js

From Wikipedia, the free encyclopedia
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.
// Load RefLinks
mw.loader.load( 'https://meta.wikimedia.org/w/index.php?title=User:Zhaofeng_Li/Reflinks.js&action=raw&ctype=text/javascript' );

mw.loader.load( '/w/index.php?title=User:AlanM1/scripts/CharHexDump.js&action=raw&ctype=text/javascript' );

mw.loader.load( '/w/index.php?title=User:PrimeHunter/Source_links.js&action=raw&ctype=text/javascript' );	// Linkback: [[User:PrimeHunter/Source links.js]]

// Per [[:mw:User:PerfektesChaos/js/resultListSort]] :
mw.loader.load('https://www.mediawiki.org/w/index.php?title=User:PerfektesChaos/js/resultListSort/r.js&action=raw&bcache=1&maxage=86400&ctype=text/javascript');


window.catALotPrefs = { editpages: true };
mw.loader.load( 'https://commons.wikimedia.org/w/index.php?action=raw&ctype=text/javascript&title=MediaWiki:Gadget-Cat-a-lot.js' );
mw.loader.load( 'https://commons.wikimedia.org/w/index.php?action=raw&ctype=text/css&title=MediaWiki:Gadget-Cat-a-lot.css', 'text/css' );


mw.loader.load( '/w/index.php?action=raw&ctype=text/javascript&title=User:AlanM1/scripts/hideHotcatMarkers.js' ); // Linkback: [[User:AlanM1/scripts/hideHotcatMarkers.js]]

// AutoEd stuff
mw.loader.load( '/w/index.php?action=raw&ctype=text/javascript&title=User:AlanM1/autoEdLoader.js' ); // Linkback: [[User:AlanM1/autoEdLoader.js]]


LinkClassifierOnDemand = true;
mw.loader.load( '/w/index.php?action=raw&ctype=text/javascript&title=User:Anomie/linkclassifier.js' ); // Linkback: [[User:Anomie/linkclassifier.js]]
mw.loader.load( '/w/index.php?action=raw&ctype=text/css&title=User:Anomie/linkclassifier.css', 'text/css' ); // Linkback: [[User:Anomie/linkclassifier.css]]
$( function () {
    mw.util.addPortletLink('p-cactions', 'javascript:LinkClassifier.onDemand()', 'linkclassifier');
});

mw.loader.load( '/w/index.php?action=raw&ctype=text/javascript&title=User:DannyS712/Easy-link.js' );// [[User:DannyS712/Easy-link.js]]
mw.loader.load( '/w/index.php?action=raw&ctype=text/javascript&title=User:DannyS712/Readonly.js' );// [[User:DannyS712/Readonly.js]]
mw.loader.load( '/w/index.php?action=raw&ctype=text/javascript&title=User:DannyS712/Redirectify.js' );// [[User:DannyS712/Redirectify.js]]

var myLintHints = { };
myLintHints.rooms = "*";
mw.hook("lintHint.config").fire(myLintHints);
mw.loader.load( '/w/index.php?title=User:PerfektesChaos/js/lintHint/r.js&action=raw&maxage=86400&ctype=text/javascript');// [[User:PerfektesChaos/js/lintHint/r.js]]


mw.loader.load( '/w/index.php?title=User:Writ Keeper/Scripts/teahouseUtility.js&action=raw&ctype=text/javascript');// [[User:Writ Keeper/Scripts/teahouseUtility.js]]



function setoptions() {
}

function setreason() {
}

/*
function regex(search,replace,repeat) {
	var editbox = $('#wpTextbox1');
	
	if(!repeat || repeat<0) {
		var repeat = 1;
	}
	
	var text = editbox.val();
	for(var i=0; i<repeat; i++) {
		text = text.replace(search,replace);
	}
	editbox.val(text);
};
mw.loader.load( '/w/index.php?action=raw&ctype=text/javascript&title=User:Ohconfucius/script/formatgeneral.js' ); // [[User:Ohconfucius/script/formatgeneral.js]]
*/

/* 20191028 

	mw.loader.load( '/w/index.php?action=raw&ctype=text/javascript&title=User:Ohconfucius/test/formatgeneral.js' ); // [[User:Ohconfucius/script/formatgeneral.js]]

	This is the source of these errors:
	Content Security Policy: The page’s settings observed the loading of a resource at https://tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js (“script-src”). A CSP report is being sent.
	Content Security Policy: The page’s settings observed the loading of a resource at https://tools-static.wmflabs.org/meta/scripts/pathoschild.util.js (“script-src”). A CSP report is being sent.

20191028 */

// Per [[WP:LOCO]]
LocalComments = {
	dateDifference: true,
	dateFormat: 'ymd',
	timeFirst: false,
	twentyFourHours: true,
	dayOfWeek: true,
	dropDays: 0,
	dropMonths: 0,
	dropOffset: 1,
	diffLast: true
};


// Per [[Wikipedia:RefToolbar/2.0]]

$('head').one('reftoolbarbase', function() {
	var nIndex = -1;

	CiteTB.UserOptions['date format'] = "<monthname> <date>, <year>";
	CiteTB.UserOptions['autodate fields'] = ['access-date'];
	CiteTB.UserOptions['modal'] = false;

	// Add oclc to cite book
	if (CiteTB.Templates["cite book"]) {
		console.log("*** cite book found");
		CiteTB.Templates["cite book"]["basic"].push({"field":"oclc", "autofillid":"oclc", "autofillprop":"oclc"});
	}
	else {
		console.log("*** cite book NOT found");
	}

	// Move cite web date field from extra to basic
	if (CiteTB.Templates["cite web"]) {
		nIndex = CiteTB.Templates["cite web"]["extra"].findIndex(function(t) { return (t.field === "date"); });
		if (nIndex >= 0) { 
			if (CiteTB.Templates["cite web"]["basic"].push(CiteTB.Templates["cite web"]["extra"][nIndex])) {
				CiteTB.Templates["cite web"]["extra"].splice(nIndex, 1);
			}
			// else ?
		}
		// else ?
	}

	// Add volume to cite news
	if (CiteTB.Templates["cite news"]) {
		nIndex = CiteTB.Templates["cite news"]["basic"].findIndex(function(t) { return (t.field === "issue"); });
		if (nIndex >= 0) { 
			CiteTB.Templates["cite news"]["basic"].splice(nIndex, 0, {"field": "volume", "autofillprop":"volume"});
		}
	}
});

/*
	Don't submit when hitting enter in the summary field
	From [[User:Anomie/nosubmitsummary.js]]
*/

$(document).ready(function(){
    $('input#wpSummary').keypress(function(e){
        if(e.which==13) e.preventDefault();
    });
    // Example of how to change one of the pt- portlet links
    // Maybe add &title=Special%3AContributions
    //$('#pt-mycontris a')[0].href += '?namespace=2&wpfilters%5B%5D=nsInvert';

	// Per [[WP:LOCO]]
	mw.loader.load( '/w/index.php?action=raw&ctype=text/javascript&title=User:AlanM1/comments in local time.js' ); // [[User:AlanM1/comments in local time.js]] based on [[User:Gary/comments in local time.js]]
});

mw.loader.load( '/w/index.php?action=raw&ctype=text/javascript&title=User:Anomie/unsignedhelper.js'); // Linkback: [[User:Anomie/unsignedhelper.js]]


// NavPops config per [[WP:POP#Options]]
window.popupOnlyArticleLinks = false;
window.popupInitialWidth = 350;
window.popupMaxWidth = 700;
window.popupTocLinks = true;
window.popupHistoryPreviewLimit = 100;
window.popupContribsPreviewLimit = 100;
window.popupPreviewKillTemplates = false;
window.popupPreviewFirstParOnly = false;
window.popupMaxPreviewSentences = 1000;
window.popupMaxPreviewCharacters = 2000;
window.popupSimplifyMainLink = false;
window.popupImageSize = 120;
window.popupDiffMaxLines = 500;
window.popupDiffContextLines = 3;
window.popupDiffContextCharacters = 100;
window.popupThumbAction = "sizetoggle";

function am1SecNavInsert() {
	aElems = Array.from(document.getElementsByClassName("mw-editsection"));
	aTitles = Array.from(document.getElementsByClassName("mw-headline"));
	var lastElemNum = aElems.length - 1;
	if (lastElemNum >= 0) {
		var lastId = '#' + aTitles[lastElemNum].id;
		for (i = 0; i <= lastElemNum; i++) {
			if (aElems[i].firstChild.className === "mw-editsection-bracket") {
				var span = document.createElement('span');
				span.id = "am1-secnav" + i;
				span.appendChild(document.createTextNode(i + ': '));
	
				if (i > 0) {
					var link = document.createElement('a');
					link.href = '#top';
					link.appendChild(document.createTextNode('↑↑top'));
					span.appendChild(document.createTextNode('['));
					span.appendChild(link);
					span.appendChild(document.createTextNode('] '));
		
					var linku = document.createElement('a');
					linku.href = '#' + aTitles[i - 1].id;
					linku.appendChild(document.createTextNode('↑up'));
					span.appendChild(document.createTextNode('['));
					span.appendChild(linku);
					span.appendChild(document.createTextNode('] '));
				}
		
				if (i < lastElemNum) {
					var linkd = document.createElement('a');
					linkd.href = '#' + aTitles[(i) ? (i + 1) : 0].id;
					linkd.appendChild(document.createTextNode('↓down'));
					span.appendChild(document.createTextNode('['));
					span.appendChild(linkd);
					span.appendChild(document.createTextNode('] '));
		
					var linke = document.createElement('a');
					linke.href = lastId;
					linke.appendChild(document.createTextNode('↓↓end'));
					span.appendChild(document.createTextNode('['));
					span.appendChild(linke);
					span.appendChild(document.createTextNode('] '));
				}

				aElems[i].insertBefore(span, aElems[i].firstChild);
			}
		}
	}
}

$( function() { am1SecNavInsert(); });

function getTimeOffset() {
	var tz = mw.user.options.get('timecorrection');
	console.log('\ntimecorrection: ' + tz + '\n');
	if(tz) {
		if( tz.indexOf('|') > -1 ) {
			// New format
			return parseInt(tz.split('|')[1],10);
		} else if ( tz.indexOf(':') > -1 ) {
			// Old format
			return( parseInt(tz,10)*60 + parseInt(tz.split(':')[1],10) );
		}
	}
	return 0;
}

function reAssignLKey() {
  // Steal Alt-Shift-L hotkey from Watchlist for Easy Link
  // console.log("Watchlist accesskey before: '" + $("#pt-watchlist")[0].firstChild.accessKey + "'");
  var wl = $("#pt-watchlist")[0];
  if(wl)wl.firstChild.accessKey = "";
  // console.log("Watchlist accesskey after: '" + $("#pt-watchlist")[0].firstChild.accessKey + "'");

  // console.log("EasyLink accesskey before: '" + $("#ca-copy-link")[0].firstChild.accessKey + "'");
  $("#ca-copy-link")[0].firstChild.accessKey = "l";
  // console.log("EasyLink accesskey after: '" + $("#ca-copy-link")[0].firstChild.accessKey + "'");
}

$.when( mw.loader.using( ['mediawiki.util'] ), $.ready ).done( function() {
  mw.util.addPortletLink(
    'p-personal',
    'javascript:void(0)',
    'Skip to bottom',
    'pt-skiptobottom',
    'Instantly skip to the bottom of the page',
    null,
    '#pt-preferences'
  );

  mw.util.addPortletLink(
    'p-personal',
    'javascript:void(0)',
    'HideAll',
    'pt-hideall',
    'Hide all shown collapsibles',
    null,
    '#pt-skiptobottom'
  );

  mw.util.addPortletLink(
    'p-personal',
    'javascript:void(0)',
    'ShowAll',
    'pt-showall',
    'Show all hidden collapsibles',
    'a',
    '#pt-hideall'
  );

  $('#pt-skiptobottom').on('click', function() {
    var scrollingElement = (document.scrollingElement || document.body);
    scrollingElement.scrollTop = scrollingElement.scrollHeight;
  });

  function clickAll(sClass, sValue) {
  	// console.log("In clickAll('" + sClass + "', '" + sValue + "')");
  	var nCount = 0;
    Array.from(document.getElementsByClassName(sClass)).forEach(function(xItem) {
		// console.log(sClass + ": id='" + xItem.offsetParent.lastChild.id + "', innerHTML='" + xItem.innerHTML + "'");
		if (xItem.innerHTML === sValue) {
			xItem.click();
			++nCount;
		}
    });
    return nCount;
  }

  $('#pt-showall').on('click', function(e) {
  	e.preventDefault();
  	clickAll("NavToggle", "[show]");
  	clickAll("mw-collapsible-text", "show");
  	var nLoops = 0;
  	while (clickAll("CategoryTreeToggle", "►") > 0 && ++nLoops <= 10);
  	$('#pt-showall')[0].firstChild.accessKey = "";
  	$('#pt-hideall')[0].firstChild.accessKey = "a";
  });

  $('#pt-hideall').on('click', function(e) {
  	e.preventDefault();
  	clickAll("NavToggle", "[hide]");
  	clickAll("mw-collapsible-text", "hide");
  	var nLoops = 0;
  	while (clickAll("CategoryTreeToggle", "▼") > 0 && ++nLoops <= 10);
  	$('#pt-hideall')[0].firstChild.accessKey = "";
  	$('#pt-showall')[0].firstChild.accessKey = "a";
  });

//  am1SecNavInsert();

  // This is ugly, but put it inline or in other ready()s and the ca-copy-link isn't there yet. 
  // Probably need to just fork the script that adds it to provide the key (though when will the 
  // pt-watchlist be ready? Can I wait on it efficiently?)
  window.setTimeout(reAssignLKey, 2000);	
});