Jump to content

User:BrandonXLF/NoRedirect.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.
/*** No Redirect Link ***/

// Adds a link beside links to redirects that doesn't get redirected
// Documentation at [[en:w:User:BrandonXLF/NoRedirect]]
// By [[en:w:User:BrandonXLF]]

mw.hook('wikipage.content').add(function(content) {
	content.find('.mw-redirect')
		.filter(function() {
			return this.href.indexOf('redirect=no') == -1 &&
				this.href.indexOf('oldid=') == -1 &&
				this.href.indexOf('diff=') == -1 &&
				(this.href.indexOf('action=') == -1 || this.href.indexOf('action=view') != -1);
		})
		.after(function() {
			return $('<a>')
				.attr('href', this.href   (this.href.includes('?') ? '&' : '?')   'redirect=no')
				.attr('title', this.title   ' (no redirect)')
				.css('cssText', 'margin-left: 1px; user-select: none;')
				.append(
					$('<img>')
						.attr('alt', 'no redirect')
						.attr('src', 'data:image/svg xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="14" viewBox="0 0 16 14" version="1.1"><path d="m 1,0 v 8.5 c 0,1.04 1.02,1.98 2.02,1.98 h 6 l 3,0.02" style="fill:none;stroke:#000000;stroke-width:2;"/><path d="m 9.5,7 0.02,7 6.5,-3.5 z" id="path4"/></svg>')
						.css('cssText', 'height: 0.6em !important; vertical-align: text-top;')
				);
		});
});