Remove Roblox URL Tracking

Removes the newly implemented roblox URL tracking parameters.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Remove Roblox URL Tracking
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Removes the newly implemented roblox URL tracking parameters.
// @author       ImFirstPlace
// @match        *://www.roblox.com/*
// @match        *://web.roblox.com/*
// @icon         https://www.google.com/s2/favicons?domain=roblox.com
// @grant        none
// @run-at       document-start
// @noframes
// @license      GPL-3.0 License
// ==/UserScript==

// For some reason userscripts run multiple times on roblox so noframes is added

(function() {
    'use strict';

    const knownTrackingParams = [
        "gameSetTypeId",
        "homePageSessionInfo",
        "SearchId",
        "gameSearchSessionInfo"
    ]

    function sanitizeURL(Url) {
        var urlSplit = Url.split("?")
        if (urlSplit.length >= 2) {
            const urlParams = new URLSearchParams(Url)

            // Game referring
            if (Url.includes("refer?") && urlParams.has("PlaceId")) {
                return `https://www.roblox.com/games/${urlParams.get("PlaceId")}`
            }

            // Library referring
            if (urlSplit[0].includes("/library/refer")) {
                const slashSplit = urlSplit[0].split("/")
                return `https://www.roblox.com/library/${slashSplit[5]}`
            }

            // General parameters
            for (const param of knownTrackingParams) {
                if (urlSplit[1].includes(param)) { // urlParams.has seems to not work with the homePageSessionInfo param
                    return urlSplit[0]
                }
            }
        }
        return false // Don't bother setting the url exact same thing!
    }

    function handleClick(e) {
        var a = e.target;

        while (a && !a.href) {
            a = a.parentElement;
        }

        if (!a) {
            return;
        }

        var realUrl = sanitizeURL(a.href)
        if (realUrl) {
            a.href = realUrl
        }
    }
    document.addEventListener('click', handleClick, true);
    document.addEventListener('mousedown', handleClick, true);
    document.addEventListener('touchstart', handleClick, true);
})();