Steam Fix RU

Убирает параметр `l=russian` из URL для CSS и JS

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Steam Fix RU
// @namespace    Steam Fix RU
// @version      1.1
// @author		Danzo
// @description  Убирает параметр `l=russian` из URL для CSS и JS
// @match        *://store.steampowered.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    function removeLanguageParam() {
        // Находим все CSS и JavaScript ресурсы
        document.querySelectorAll('link[rel="stylesheet"], script[src]').forEach(resource => {
            // Определяем нужный атрибут (href для link и src для script)
            const urlAttr = resource.tagName === 'LINK' ? 'href' : 'src';
            
            // Проверяем, что атрибут существует и начинается с 'http'
            if (resource[urlAttr] && resource[urlAttr].startsWith('http')) {
                try {
                    let url = new URL(resource[urlAttr]);

                    // Удаляем параметр l=russian, если он присутствует
                    if (url.searchParams.get('l') === 'russian') {
						// Логируем исходный URL
						// console.log("Detected resource:", url.toString());
						
                        url.searchParams.delete('l');
                        resource[urlAttr] = url.toString();

                        // Логируем новый URL после удаления параметра
                        // console.log("Updated resource:", resource[urlAttr]);
                    }
                } catch (e) {
                    console.error("Invalid URL detected:", resource[urlAttr], e);
                }
            }
        });
    }

    // Запускаем функцию сразу при загрузке страницы
    removeLanguageParam();

    // Используем MutationObserver для обработки новых ресурсов, добавленных динамически
    const observer = new MutationObserver(removeLanguageParam);
    observer.observe(document.head || document.documentElement, { childList: true, subtree: true });
})();