User:Chlod/Scripts/SectionLink.js

mw.hook('wikipage.content').add(function {	setTimeout(function { $('.mw-heading').each(function (i, heading) {			var headingId = $(heading).children("h1,h2,h3,h4,h5,h6")[0].id;			$(heading).children(".mw-editsection").each(function { if ($(this).hasClass("section-link")) return; var apiSingleton, titleRegexp = new RegExp(						mw.config.get('wgArticlePath').replace(/[.*+?^${}|[\]\\]/g, '\\$&').replace(/\\\$1/, '([^?]+)') +						'|[?&]title=([^&#]*)'					); if (mw.config.get('skin') === 'minerva') return; var y = document.createElement("span"); var y1 = document.createElement("span"); y1.innerText = " | "; var y2 = document.createElement("span"); y2.innerText = " | "; var x = document.createElement("a"); x.innerText = "anchor"; x.setAttribute("href", "#"); x.onclick = function(e) { e.preventDefault; navigator.clipboard.writeText(						mw.config.get("wgPageName").replace(/_/g, " ") + 						"#" + 						headingId.replace(/_/g, " ")					).then(function {						mw.notify("Section link copied to clipboard.");					}); return false; };				var z = document.createElement("a"); z.innerText = "link"; z.setAttribute("href", "#"); z.onclick = function(e) { e.preventDefault; var target = new URL(window.location); target.hash = headingId; navigator.clipboard.writeText(						target.toString					).then(function {						mw.notify("Section link copied to clipboard.");					}); return false; };				$(this).children.last.before(					y1, x, y2, z				); $(this).addClass('section-link'); });		});	}, 400); });