Reformat F95 game pages URLs

Reformat F95 game pages URLs so the blue star showing the page is already bookmarked is still shown even if game updates

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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         Reformat F95 game pages URLs
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Reformat F95 game pages URLs so the blue star showing the page is already bookmarked is still shown even if game updates
// @author       lifeAnime / Yhria
// @match        https://f95zone.to/threads/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=f95zone.to
// @grant        none
// ==/UserScript==

function find_text_not_capsuled(str){
    let i = 0;
    let new_str = "";

    while (i < str.length){
        if (str[i] == '['){
            while (i < str.length && str[i] != ']'){
                i++;
            }
            i++;
        }
        if (/\S/.test(str[i])){
            while (i < str.length && str[i] != '['){
                if (i + 1 < str.length && str[i + 1] == '[' && str[i] == ' '){
                    ;}
                else if (str[i] == ' '){
                    new_str += '-'}
                else{
                    new_str += str[i];}
                i++;
            }
            return new_str;
        }
        i++;
    }
}

(function() {
    'use strict';

    let url = window.location.href;
    let regexp = /(https:\/\/f95zone\.to)(\/threads\/)([^.]+)(\.[0-9]+)(.*)/
    let match = url.match(regexp)
    let game_name = find_text_not_capsuled(document.getElementsByClassName("p-title-value")[0].textContent)
    let new_url = match[2] + game_name.toLowerCase() + match[4] + match[5]

    console.log(match)
    console.log(new_url)
    history.pushState({}, null, new_url);
})();