Affiliate Links Chrome Extension JavaScript Source Code

Chrome Extension to Discover Affiliate Links [JavaScript Source Code]

I wrote JavaScript that detects affiliate links, so I turned it into a Chrome extension.

Shou Arisaka
3 min read
Nov 9, 2025

Created a Chrome extension: Discover affiliate links - Chrome Web Store

I wrote JavaScript that detects affiliate links.

I have nothing against affiliate links, but I wondered about people casually recommending insurance products just because the commission is high, saying "Highly recommended!"

Insurance is important anyway. Let's get some. โ†’ [Link]

When you see text like that, well, nine times out of ten it's an affiliate link. But if it's not an affiliate link, it does make you a bit curious. That person might genuinely be recommending it.

In Chrome, you can see the URL by hovering over a link, but checking them one by one that way can be tedious.

For those times, please use this.

Example for a8.net

var i;

for (i = 0; i < document.getElementsByTagName('a').length; i++){
    var result = document.getElementsByTagName('a')[i].href;
    if (document.getElementsByTagName('a')[i].href.match(/px\.a8\.net/)==null ){
        } else {
            // console.log(document.getElementsByTagName('a')[i]) ;

            var linkinfo = document.createElement("span");
            linkinfo.id = "linkinfo";
            linkinfo.innerHTML = [
            'a8',
            ].join("");
            // document.getElementsByTagName('a')[27].appendChild(linkinfo);
            document.getElementsByTagName('a')[i].appendChild(linkinfo);

            var linkinfoStyle = document.createElement("style");
            linkinfoStyle.type = "text/css";
            linkinfoStyle.innerHTML = [
            "#linkinfo {",
            "    background-color: black;",
            "    color: white;",
            "}",
            ].join("");
            document.getElementsByTagName('a')[i].appendChild(linkinfoStyle);
        }
}

What it does: Loops through `` tags, and if .href contains the a8.net domain, inserts a string to the right of the link.

Major ASP-compatible affiliate link discovery userscript (tampermonkey) Compatible with: a8.net; afb; valuecommerce

// ==UserScript==
// @name         Discover affiliate links
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       https://yuis-programming.com
// @match        *://*/*
// @grant        none
// ==/UserScript==

var i;
var linkinfo;
var linkinfoStyle;
var result;

// a8.net
for (i = 0; i < document.getElementsByTagName('a').length; i++){
    result = document.getElementsByTagName('a')[i].href;
    if (document.getElementsByTagName('a')[i].href.match(/px\.a8\.net/)==null ){
        } else {
            // console.log(document.getElementsByTagName('a')[i]) ;

            linkinfo = document.createElement("span");
            linkinfo.id = "linkinfo";
            linkinfo.innerHTML = [
            'a8',
            ].join("");
            // document.getElementsByTagName('a')[27].appendChild(linkinfo);
            document.getElementsByTagName('a')[i].appendChild(linkinfo);

            linkinfoStyle = document.createElement("style");
            linkinfoStyle.type = "text/css";
            linkinfoStyle.innerHTML = [
            "#linkinfo {",
            "    background-color: black;",
            "    color: white;",
            "}",
            ].join("");
            document.getElementsByTagName('a')[i].appendChild(linkinfoStyle);
        }
}

// afb
for (i = 0; i < document.getElementsByTagName('a').length; i++){
    result = document.getElementsByTagName('a')[i].href;
    if (document.getElementsByTagName('a')[i].href.match(/affiliate-b\.com/)==null ){
        } else {
            // console.log(document.getElementsByTagName('a')[i]) ;

            linkinfo = document.createElement("span");
            linkinfo.id = "linkinfo";
            linkinfo.innerHTML = [
            'affiliate-b',
            ].join("");
            // document.getElementsByTagName('a')[27].appendChild(linkinfo);
            document.getElementsByTagName('a')[i].appendChild(linkinfo);

            linkinfoStyle = document.createElement("style");
            linkinfoStyle.type = "text/css";
            linkinfoStyle.innerHTML = [
            "#linkinfo {",
            "    background-color: black;",
            "    color: white;",
            "}",
            ].join("");
            document.getElementsByTagName('a')[i].appendChild(linkinfoStyle);
        }
}

// valuecommerce
for (i = 0; i < document.getElementsByTagName('a').length; i++){
    result = document.getElementsByTagName('a')[i].href;
    if (document.getElementsByTagName('a')[i].href.match(/valuecommerce\.com/)==null ){
        } else {
            // console.log(document.getElementsByTagName('a')[i]) ;

            linkinfo = document.createElement("span");
            linkinfo.id = "linkinfo";
            linkinfo.innerHTML = [
            'valuecommerce',
            ].join("");
            // document.getElementsByTagName('a')[27].appendChild(linkinfo);
            document.getElementsByTagName('a')[i].appendChild(linkinfo);

            linkinfoStyle = document.createElement("style");
            linkinfoStyle.type = "text/css";
            linkinfoStyle.innerHTML = [
            "#linkinfo {",
            "    background-color: black;",
            "    color: white;",
            "}",
            ].join("");
            document.getElementsByTagName('a')[i].appendChild(linkinfoStyle);
        }
}

JavaScript is fun after all.

Share this article

Shou Arisaka Nov 9, 2025

๐Ÿ”— Copy Links