Steam - Default language

Make sure you always see the steam page in your preferred language. You can configure the language in the language variable.

Från och med 2016-05-04. Se den senaste versionen.

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 or Violentmonkey 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 - Default language
// @version      0.3
// @description  Make sure you always see the steam page in your preferred language. You can configure the language in the language variable.
// @author       Royalgamer06
// @include      /(http|https)\:\/\/(.+\.steampowered|steamcommunity)\.com.*/
// @run-at       document-start
// @grant        none
// @namespace    https://greatest.deepsurf.us/users/13642
// ==/UserScript==

//SET YOUR LANGUAGE HERE
var language = "en";
/*
bulgarian: bg,
czech: cs,
danish: da,
dutch: nl,
finnish: fi,
french: fr,
greek: el,
german: de,
hungarian: hu,
italian: it,
japanese: ja,
koreana: ko,
norwegian: no,
polish: pl,
portuguese: pt-PT,
brazilian: pt-BR,
russian: ru,
romanian: ro,
schinese: zh-CN,
spanish: es-ES,
swedish: sv-SE,
tchinese: zh-TW,
thai: th,
turkish: tr,
ukrainian: uk
*/

//DO NOT TOUCH BELOW
window.onload = function() {
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
        if (anchors[i].href.indexOf("l=" + language) == -1 && (anchors[i].href.indexOf("steamcommunity") > -1 || anchors[i].href.indexOf("steampowered") > -1)) {
            anchors[i].href = addParameter(anchors[i].href, "l", language, false);
        }
    }
};

if (location.href.indexOf("l=" + language) == -1) {
    location.href = addParameter(location.href, "l", language, false);
}

//Nice solution from http://stackoverflow.com/a/6954277/4356020
function addParameter(url, parameterName, parameterValue, atStart) {
    replaceDuplicates = true;
    var cl = "";
    if(url.indexOf('#') > 0){
        cl = url.indexOf('#');
        urlhash = url.substring(url.indexOf('#'),url.length);
    } else {
        urlhash = '';
        cl = url.length;
    }
    sourceUrl = url.substring(0,cl);

    var urlParts = sourceUrl.split("?");
    var newQueryString = "";

    if (urlParts.length > 1)
    {
        var parameters = urlParts[1].split("&");
        for (var i=0; (i < parameters.length); i++)
        {
            var parameterParts = parameters[i].split("=");
            if (!(replaceDuplicates && parameterParts[0] == parameterName))
            {
                if (newQueryString === "")
                    newQueryString = "?";
                else
                    newQueryString += "&";
                newQueryString += parameterParts[0] + "=" + (parameterParts[1]?parameterParts[1]:'');
            }
        }
    }
    if (newQueryString === "")
        newQueryString = "?";

    if(atStart){
        newQueryString = '?'+ parameterName + "=" + parameterValue + (newQueryString.length>1?'&'+newQueryString.substring(1):'');
    } else {
        if (newQueryString !== "" && newQueryString != '?')
            newQueryString += "&";
        newQueryString += parameterName + "=" + (parameterValue?parameterValue:'');
    }
    return urlParts[0] + newQueryString + urlhash;
}