Draggable Sidebar Elements

Fully mushable sidebar

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name        Draggable Sidebar Elements
// @namespace   pxgamer
// @include     *kat.cr/*
// @exclude     *kat.cr/settings*
// @description Fully mushable sidebar
// @version     2.0
// @grant       GM_setValue
// @grant       GM_getValue
// ==/UserScript==


var setSelector = "#sidebar";
var setCookieName = "sidebarOrder";
console.log(GM_getValue(setCookieName, ''));
$(".sliderbox").css('padding', '3px');

var i = 0;
var s = $(".sliderbox");
$(".sliderbox").each( function() {
    $(this).wrap('<li id="item-'+i+'" style="margin-bottom:2px"></li>');
    i++;
});

$('#sidebar').sortable({ containment: "#sidebar", scroll: false });

function getOrder() {
    GM_setValue(setCookieName, $(setSelector).sortable("toArray"));
}

function restoreOrder() {
    var list = $(setSelector);
    if (list === null) return false;

    var cookie = GM_getValue(setCookieName, '');
    if (!cookie) return false;

    var IDs = cookie;

    var items = list.sortable("toArray");

    var rebuild = [];
    for ( var v=0, len=items.length; v<len; v++ ){
        rebuild[items[v]] = items[v];
    }

    for (var i = 0, n = IDs.length; i < n; i++) {

        var itemID = IDs[i];

        if (itemID in rebuild) {

            var item = rebuild[itemID];

            if (item !== '') {
                var child = $("#sidebar.ui-sortable").children("#" + item);

                var savedOrd = $("#sidebar.ui-sortable").children("#" + itemID);

                child.remove();

                $("#sidebar.ui-sortable").filter(":first").append(savedOrd);
            }
        }
    }
}

jQuery(document).ready(function() {
    jQuery("#sidebar").sortable(
        {axis: "y",
         cursor: "move",
         update: function() { getOrder(); }
        }
    );

    restoreOrder();
});