Jump to content

User:Zackmann08/scripts/tfdlink.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.
//<nowiki>
jQuery(document).ready(function($) {
	if(window.location.href.match(/.*\en.wikipedia.org\/wiki\/Wikipedia:Templates_for_discussion\/Log\//)) {	
		
		const editlinks = document.querySelectorAll('.mw-editsection');
		editlinks.forEach(link => {
			if (link && link.closest('div') && link.closest('div').querySelector('h4')) {
				var editlink = link.closest('div').querySelector('h4').id;
				var newhtml = '<span class="mw-editsection tfdlink">' + 
					'<span class="mw-editsection-bracket">[</span>' + 
					'<span>'+
					`<a href="javascript:getcurrentlink(\'${editlink}\')">` +
					'TFD</a></span>' + 
					'<span class="mw-editsection-bracket">]</span></span>';
				link.insertAdjacentHTML('afterend', newhtml);
			}
		});
	}
});

function getcurrentlink(link)
{
	navigator.clipboard.writeText(mw.config.get('wgPageName') + '#' + link);
	mw.notify('TFD link copied to clipboard');
}
//</nowiki>