Startpage - Remove Google Merchant Center Tracking Parameters

Remove Google Merchant Center query parameters from links and their corresponding text on Startpage.com results

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Startpage - Remove Google Merchant Center Tracking Parameters
// @version      1.1.2
// @description  Remove Google Merchant Center query parameters from links and their corresponding text on Startpage.com results
// @namespace    August4067
// @author       August4067
// @match        https://www.startpage.com/*
// @license      MIT
// @grant        none
// @icon         https://www.startpage.com/favicon.ico
// @require      https://update.greatest.deepsurf.us/scripts/502635/1422102/waitForKeyElements-CoeJoder-fork.js
// ==/UserScript==

/**
 * Removes the 'srsltid' parameter from a URL if it exists.
 * @param {string} url - The original URL.
 * @returns {string} - The cleaned URL.
 */
function removeSrsltidParam(url) {
  const urlObj = new URL(url);

  if (urlObj.searchParams.has("srsltid")) {
    urlObj.searchParams.delete("srsltid");
    return urlObj.toString();
  }

  return url;
}

/**
 * Cleans up links on the page by removing 'srsltid' parameters from hrefs and link text.
 */
function cleanUpLinks() {
  console.debug("Cleaning up links");
  const wgl = document.querySelector("div[class~='w-gl']");

  if (wgl) {
    const links = wgl.querySelectorAll("a");

    links.forEach((link) => {
      const originalHref = link.href;
      const newHref = removeSrsltidParam(originalHref);

      if (newHref !== originalHref) {
        console.debug(`Removing srsltid: ${originalHref}`);
        link.href = newHref;
        link.ariaLabel = newHref;
        
        const linkTexts = link.querySelectorAll('span[class~="link-text"]');
        linkTexts.forEach(linkText => {
          if (linkText.innerText === originalHref) {
            linkText.innerText = newHref;
          }
        });
        
        console.debug(`Result: ${newHref}`);
      }
    });
  }
  console.debug("Cleaned up links");
}

(function () {
  "use strict";
  waitForKeyElements("section[id='main']", () => {
    cleanUpLinks();
  }, false);
})();