BS_Library

Bibliothek mit nützlichen Funktionen für BS Userscripte.

Verze ze dne 02. 12. 2018. Zobrazit nejnovější verzi.

Tento skript by neměl být instalován přímo. Jedná se o knihovnu, kterou by měly jiné skripty využívat pomocí meta příkazu // @require https://update.greatest.deepsurf.us/scripts/375096/650122/BS_Library.js

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         BS_Library
// @namespace    https://bs.to
// @version      1.1
// @description  Bibliothek mit nützlichen Funktionen für BS Userscripte.
// @author       Asu_nyan
// @match        https://bs.to/*
// @grant        none
// ==/UserScript==
// jshint esversion: 6


const BS = {};
BS.Global = {};
BS.Audio = {};
BS.Image = {};
BS.Module = {};
BS.Helper = {};


// BS / Global ---------------------------------------------------------------------------------------------------------------------------------------
BS.Global.SecurityToken = () => document.head.querySelector('meta[name="security_token"]').content;

// BS / Audio ----------------------------------------------------------------------------------------------------------------------------------------
BS.Audio.Notification = 'https://board.bs.to/applications/core/interface/sounds/notification.mp3';

// BS / Image ----------------------------------------------------------------------------------------------------------------------------------------
BS.Image.PN = 'https://d30y9cdsu7xlg0.cloudfront.net/png/23598-200.png';
BS.Image.Favicon = 'https://bs.to/favicon.ico';

// BS / Module ----------------------------------------------------------------------------------------------------------------------------------------
BS.Module.Update = (selector) => {
    let x = document.querySelector(selector);
    x.children[0].children[0].innerHTML += " <small>aktualisieren...</small>";
    fetch('https://bs.to').then(res => res.text()).then(text => {
        console.log(text); // remove in production
        let div = document.createElement('div');
        div.innerHTML = text;
        x.innerHTML = div.querySelector(selector).innerHTML;
    });
}
BS.Module.MultiUpdate = (selector_list) => {
    let module_list = [];
    selector_list.forEach(selector => {
        let x = document.querySelector(selector);
        x.children[0].children[0].innerHTML += " <small>aktualisieren...</small>";
        module_list.push(x)
    });
    fetch('https://bs.to').then(res => res.text()).then(text => {
        console.log(text); // remove in production
        let div = document.createElement('div');
        div.innerHTML = text;
        module_list.forEach(module => {
            module.innerHTML = div.querySelector(`#${module.id}`).innerHTML;
        });
    });
}
BS.Module.Get = (selector) => {
    return document.querySelector(selector);
}

// BS / Helper ----------------------------------------------------------------------------------------------------------------------------------------
BS.Helper.InjectCSS = (link, css) => {
    let cdn;
    if(link) {
        cdn = document.createElement('link');
        cdn.href = link;
        cdn.rel = 'stylesheet';
    }
    else if(css) {
        cdn = document.createElement('style');
        cdn.innerText = css;
    }
    document.querySelector('head').appendChild(cdn);
}
BS.Helper.RemoveDuplicates = (array) => {
    let contains = (array, obj) => {
        for (var i = 0; i < array.length; i++) {
            if (isEqual(array[i], obj)) return true;
        }
        return false;
    }
    let isEqual = (obj1, obj2) => {
        if (obj1 == obj2) return true;
        return false;
    }
    let arr = [];
    return array.filter(function(x) {
        return !contains(arr, x) && arr.push(x);
    });
}
window.BS = BS;