derevnia / kinokopilka.tv imdb

// ==UserScript==
// @name           kinokopilka.tv imdb
// @namespace      derevnia
// @author		   vk.com/derevnia
// @description    Добавляет сортировку по рейтингу IMDB
// @version		   0.2
// @include        *kinokopilka.*
// @updateURL	   https://openuserjs.org/install/derevnia/kinokopilka.tv_imdb.user.js
// @downloadURL    https://openuserjs.org/install/derevnia/kinokopilka.tv_imdb.user.js
// @grant		   none
// ==/UserScript==
window.onload = function () {
    function getCookie(imdb) {// получение cookie
        var matches = document.cookie.match(new RegExp(
            "(?:^|; )" + imdb.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
        ));
        return matches ? decodeURIComponent(matches[1]) : undefined;
    }
var chosenoption = getCookie('imdb');
	function setCookie(imdb) {// установка cookie
        now = new Date();
        var date = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59);
        document.cookie = "imdb=" + escape(imdb) + "; expires=" + date.toUTCString();
    }
	function delCookie(name) {// удаление cookie
		document.cookie = name + "=" + "; expires=Thu, 01 Jan 1970 00:00:01 GMT";
	}
    if (chosenoption === undefined) {// сбой cookie
	delCookie('imdb');
	setCookie('0');
	chosenoption = 0;
    }
setTimeout(function(){

document.getElementById("year_selector").parentNode.parentNode.innerHTML += "<br /><label>IMDB:<br /><select id='imdb_selector' name='imdb' onchange='$(this).parent().parent().submit();'><option selected=\"selected\" value='0'>Любой</option><option value='8'>> 8</option><option value='7'>> 7</option><option value='6'>> 6</option><option value='5'>> 5</option><option value='4'>> 4</option></select></label>";
var selectmenu=document.getElementById("imdb_selector");
selectmenu.onchange=function(){
	var chosenoption=selectmenu.value;
	setCookie(chosenoption);
	location.reload();
};
function displayDate() {
	location.reload();
}
var pagination=document.getElementsByClassName("ajax pagination");
var anchors = pagination[0].getElementsByTagName("a");
for (var a = 0; a < anchors.length; a++) {
	anchors[a].addEventListener("click", displayDate);
}
var hide=document.getElementsByClassName("add-info");
for (var i = 0; i < hide.length; i++) {
	z=hide[i].innerHTML.split(',');
	q=z[1].indexOf('imdb');
		if (q!=-1)
		{
			l=z[1].split(' ');
			s=l[10];
				if (s<chosenoption)
				{
					hide[i].parentNode.setAttribute("style", "display: none;");
				}
		}
		else{hide[i].parentNode.setAttribute("style", "display: none;");}
}
var options=selectmenu.getElementsByTagName("option");
for (var s = 0; s < options.length; s++) {
	if (options[s].value==chosenoption) {
		options[s].selected=true;
	}
}
}, 200);
};