Preferred language setter

Bored from codeforces changing your language? Use this

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         Preferred language setter
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Bored from codeforces changing your language? Use this
// @author       SuperJava
// @match        http://codeforces.com/*/submit
// @match        http://codeforces.com/*/submit?*
// @match        http://codeforces.com/*/*/*/*
// @grant        none
// ==/UserScript==

var z = document.getElementsByName('programTypeId')[0];
if(checkCookie('preflang')){
    z.value = getCookie('preflang');
}
$('<button type="button" id="SuperJava" style="margin-left:10px;">Save Option</button><span id="norsq" style="margin-left:10px;"> </span>').insertAfter(z);
$('#SuperJava').click(function(){
    setCookie('preflang',z.value,30);
    $('#norsq').text('Updated!');
    setTimeout(function(){$('#norsq').text('');},2000);
});

function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = "expires="+ d.toUTCString();
    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

function getCookie(cname) {
    var name = cname + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for(var i = 0; i <ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
        }
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}

function checkCookie(cname) {
    var username = getCookie(cname);
    if (username != "") {
        return true;
    } else {
        return false;
    }
}