Greasy Fork is available in English.
Bibliothek mit nützlichen Funktionen für BS Userscripte.
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/375096/650404/BS_Library.js
// ==UserScript==
// @name BS_Library
// @namespace https://bs.to
// @version 1.2
// @description Bibliothek mit nützlichen Funktionen für BS Userscripte.
// @author Asu_nyan
// @match https://bs.to/*
// @grant none
// ==/UserScript==
// jshint esversion: 6
window.BS = {};
window.BS.Global = {};
window.BS.Series = {};
window.BS.Audio = {};
window.BS.Image = {};
window.BS.Module = {};
window.BS.Helper = {};
// BS / Global ---------------------------------------------------------------------------------------------------------------------------------------
window.BS.Global.SecurityToken = () => document.head.querySelector('meta[name="security_token"]').content;
// BS / Series
window.BS.Series.ID = () => {
if(window.location.href.includes('https://bs.to/serie/')) {
let link = document.body.querySelector('img[alt="Cover"]').src;
let id = link.split('/')[link.split('/').length-1].split('.')[0];
return parseInt(id);
}
};
// BS / Audio ----------------------------------------------------------------------------------------------------------------------------------------
window.BS.Audio.Notification = 'https://board.bs.to/applications/core/interface/sounds/notification.mp3';
// BS / Image ----------------------------------------------------------------------------------------------------------------------------------------
window.BS.Image.PN = 'https://d30y9cdsu7xlg0.cloudfront.net/png/23598-200.png';
window.BS.Image.Favicon = 'https://bs.to/favicon.ico';
// BS / Module ----------------------------------------------------------------------------------------------------------------------------------------
window.BS.Module.Update = (selector) => {
let x = document.querySelector(selector);
if(selector.includes('new')) {
x.children[0].children[0].innerHTML += " <small>aktualisieren...</small>";
}
fetch('https://bs.to').then(res => res.text()).then(text => {
let div = document.createElement('div');
div.innerHTML = text;
x.innerHTML = div.querySelector(selector).innerHTML;
});
};
window.BS.Module.MultiUpdate = (selector_list) => {
let module_list = [];
selector_list.forEach(selector => {
let x = document.querySelector(selector);
if(selector.includes('new')) {
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;
});
});
};
window.BS.Module.Get = (selector) => {
return document.querySelector(selector);
};
// BS / Helper ----------------------------------------------------------------------------------------------------------------------------------------
window.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.head.appendChild(cdn);
};
window.BS.Helper.InjectScript = (link, code) => {
let cdn = document.createElement('script');
if(link) cdn.src = link;
else if(code) cdn.innerText = code;
document.body.appendChild(cdn);
};
window.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);
});
};