Draggable Sidebar Elements

Fully mushable sidebar

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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();
});