BS_Library

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

Fra 02.12.2018. Se den seneste versjonen.

Dette scriptet burde ikke installeres direkte. Det er et bibliotek for andre script å inkludere med det nye metadirektivet // @require https://update.greatest.deepsurf.us/scripts/375096/650122/BS_Library.js

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 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         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;