User:SeaDragon1/common.js: Difference between revisions – Wikipedia

From Wikipedia, the free encyclopedia

Content deleted Content added


 

Line 14: Line 14:

// Get the utm_source parameter

// Get the utm_source parameter

let source = new URL(href).searchParams.get(“utm_source”);

let source = new URL(href).searchParams.get(“utm_source”);

if (source !== null && source !== ”) {

if (source !== null) {

// Remove external link icon

// Remove external link icon

link.classList.remove(“external”);

link.classList.remove(“external”);

Line 20: Line 20:

link.setAttribute(“title”, source);

link.setAttribute(“title”, source);

// Highlight the link

// Highlight the link

if (source === ”) link.style.color = “orange”;

matched = false;

matched = false;

for (var name of aiNames) {

for (var name of aiNames) {

Line 25: Line 26:

}

}

link.style.color = matched ? “red” : “#ff7800”;

link.style.color = matched ? “red” : “#ff7800”;

// Dot the link

link.style.textDecoration = “underline dotted”;

link.style.textDecoration = “underline dotted”;

}

}


Latest revision as of 14:40, 28 January 2026

function highlightUTM() {
	// AI utm_source giveaways
	let aiNames = ["chatgpt","openai","gemini","claude","grok"];
	// Get all HTML links
	let links = document.getElementsByTagName("a");
	// Iterate through the links
	for (var link of links) {
	    // Get the HREF of the link
	    let href = link.getAttribute("href");
	    // Skip if it doesn't have an HREF
	    if (!href) continue;
	    if (href[0] == "#") href = location.href + href;
	    else if (href[0] == "/") href = location.protocol + "//" + location.pathname;
		// Get the utm_source parameter
		let source = new URL(href).searchParams.get("utm_source");
		if (source !== null) {
			// Remove external link icon
			link.classList.remove("external");
			// Set the title
			link.setAttribute("title", source);
			// Highlight the link
			if (source === '') link.style.color = "orange";
			matched = false;
			for (var name of aiNames) {
				matched |= source.toLowerCase().includes(name);
			}
			link.style.color = matched ? "red" : "#ff7800";
			// Dot the link
			link.style.textDecoration = "underline dotted";
		}
	}
}

// Override annoying purge dialog
wgAction = mw.config.get('wgAction');
if (wgAction == 'purge') $('form.mw-htmlform').submit();
else highlightUTM();

Leave a Comment

Your email address will not be published. Required fields are marked *

Exit mobile version