User:2d37/common.js

const urlIsLocal = function(location) { return location.hostname === mw.config.get('wgServerName'); };

const prefetchNext = function(location) { if (!urlIsLocal(location)) { // Well this is disturbing. Bail out! return false; }	// 2021-10-16: Prefetching a revision marks it as read. I see no way to // stop this other than disabling prefetching, so disable prefetching. //const xhr = new XMLHttpRequest; //xhr.open('GET', location.href); //xhr.send; return true; };

// Faster diff navigation (function {	const prevlink = document.getElementById('differences-prevlink');	const nextlink = document.getElementById('differences-nextlink');	if (prevlink) {		prevlink.accessKey = '[';	}	if (nextlink && prefetchNext(nextlink)) {		nextlink.accessKey = ']';	} });

// Jump to oldest unread change from a page's history (function {	const news = $('.mw-history-line-updated');	if (news.is(':last-child')) {		// This page of history is all unread, so the oldest unread change		// likely isn't on this page.		return;	}	const prevlink = news		.last		.children('.mw-history-histlinks')		.find('a:contains(prev)')[0];	if (prevlink && urlIsLocal(prevlink)) {		// Do NOT prefetch, or the edit will be marked as read.		prevlink.accessKey = '\\';	} });

// On talk pages, add button to view content page's history (function {	const $talkTab = $('[accesskey=t]').parents('li.selected').first;	if ($talkTab.length === 0) {		// This is not a talk page		return false;	}	const $conLink = $talkTab.prev.find('a');	const $histLink = $('[accesskey=h]');	const $histTab = $histLink.parents('li').first;	const conPage = /^\/wiki\/(.*)/.exec($conLink[0].pathname)[1];	if (!urlIsLocal($conLink[0]) || !conPage) {		return false;	}	$histLink.contents.text(function(_, curr) { return curr == 'View history' ? 'History' : curr; });	const conHistPath = '/w/index.php?title=' + conPage + '&action=history';	const $conHistTab = $histTab.clone;	$conHistTab.find('[accesskey=h]')		.attr('href', conHistPath)		.text($conLink.text + ' history');	$conHistTab.find('*')		.addBack		.removeAttr('accesskey id')		.removeClass('selected');	$histTab.after($conHistTab); });

// Indicate a section's number of references per paragraph (function {	$('.mw-body h1,h2,h3,h4,h5,h6').each(function { const heading = $(this); const section = heading.nextUntil('h1,h2,h3,h4,h5,h6'); const pQty = section.filter('p').length; if (pQty === 0) { return; }		const refQty = section.find('sup.reference').length; const refToPRatioText = Number(refQty/pQty).toFixed(2); const markHTML = ' &#8239;(‹ref›/‹p›&#8239;=&#8239;' + refQty + '/' + pQty			+ '&#8239;&approx;&#8239;' + refToPRatioText +')'; heading.find('.mw-editsection > a').append(markHTML); }); });

// Disable Special:EditWatchlist's link to Special:EditWatchlist/clear (function {	if (location.pathname === '/wiki/Special:EditWatchlist') {		$('a[href="/wiki/Special:EditWatchlist/clear"]').attr('href', 'javascript:alert("Link to Special:EditWatchlist/clear disabled by user script for safety")' );	} });

// Disable watchlist's "Mark all changes as seen" button // // This fails because the button apparently does not exist until some unclear // time. /*$(function {	if (!document.body.classList.contains('mw-special-Watchlist')) {		return;	}	$(':contains(Mark all changes as seen)')		.parents.addBack.filter('.mw-special-Watchlist a').first		.css('display', 'none'); });*/

// Navigation Popups settings window.popupModifier = 'shift'; if (window.popupModifier) { window.popupDelay = 1/8; } window.popupHideDelay = 1;