BS_Library

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

2018/12/02のページです。最新版はこちら

このスクリプトは単体で利用できません。右のようなメタデータを含むスクリプトから、ライブラリとして読み込まれます: // @require https://update.greatest.deepsurf.us/scripts/375096/650122/BS_Library.js

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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;