Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name BBS Master Script
- // @namespace dollars-bbs.org
- // @author Degritone
- // @description Allows Degritone's BBS scripts to auto-update
- // @match *://*/*
- // @grant GM.setValue
- // @grant GM.getValue
- // @grant GM.deleteValue
- // ==/UserScript==
- let version = 1.02;
- function request(url){
- let xmlHttp = new XMLHttpRequest();
- xmlHttp.open("GET",url,false);
- xmlHttp.send(null);
- return xmlHttp.responseText;
- }
- let scriptToggles = [];
- function settings(scriptNames,scriptDescriptions,runnable){
- if(scriptNames.length<1){
- setTimeout(run,1000);
- return;
- }
- if(window.location.href.startsWith("https://dollars-bbs.org")){
- settingHeader();
- }
- if(window.location.href == "https://dollars-bbs.org/settings"){
- let div = document.createElement("html");
- div.innerHTML = request("https://dollars-bbs.org/updates.html");
- document.getElementsByTagName("html")[0].innerHTML = div.innerHTML;
- let container = document.getElementById("contentarea");
- if(!container){
- settings(scriptNames,scriptDescriptions,runnable);
- return;
- }
- container.innerHTML = "<div>Here, you can select which of Name's/Degritone's Scripts to activate.</div><br><br>";
- let toggles = [];
- for(let i=0;i<scriptNames.length;i++){
- let label = document.createElement("label");
- let checkbox = document.createElement("input");
- toggles[i] = document.createElement("div");
- toggles[i].appendChild(checkbox);
- toggles[i].appendChild(label);
- container.appendChild(toggles[i]);
- checkbox.type = "checkbox";
- checkbox.id = scriptNames[i];
- checkbox.checked = scriptToggles[i];
- label.htmlFor = scriptNames[i];
- label.innerHTML = scriptNames[i]+": "+scriptDescriptions[i];
- }
- let d = document.createElement("button");
- container.appendChild(d);
- d.innerHTML = "Apply";
- d.onclick = ()=>saveMCookie(toggles,runnable);
- d.style = "position:relative; margin:auto; border-radius:7px; border:solid 2px #EEEEEE; background-color:#151515; padding:5px; padding-top:3px; text-decoration:none; font-size:14px; cursor:pointer; color:#EEEEEE;";
- container.style.width = "calc(100% - 180px)";
- container.appendChild(document.createElement("br"));
- container.appendChild(document.createElement("br"));
- document.title = "Dollars BBS | Settings";
- }
- }
- function settingHeader(){
- let pmenu = document.getElementById("pagemenu");
- if(!pmenu){
- setTimeout(settingHeader,1000);
- return;
- }
- let li = document.createElement("li");
- li.innerHTML = "<a href='https://dollars-bbs.org/settings'>Settings</a>";
- pmenu.appendChild(li);
- }
- function saveMCookie(toggles,runnable){
- for(let i=0;i<toggles.length;i++){
- for(let j=0;j<runnable[i].length;j++){
- GM.setValue("bbsMasterSettings."+toggles[i].children[0].id.replace(" ",""),toggles[i].children[0].checked);
- }
- }
- window.location.reload();
- }
- async function getMCookie(scriptNames){
- for(let i=0;i<scriptNames.length;i++){
- scriptToggles[i] = await GM.getValue("bbsMasterSettings."+scriptNames[i].replace(" ",""),false);
- }
- }
- async function run(){
- let runnable = [];
- let scriptURLs = [];
- let scriptNames = [];
- let scriptDescriptions = [];
- let masterURL = "https://pastebin.com/raw/y2wJrPKb";
- let aoonline = getAOOnline();
- let scriptContainer = await getScript(aoonline,"container",masterURL);
- if(!scriptContainer)
- return;
- eval(scriptContainer);
- await getMCookie(scriptNames);
- settings(scriptNames,scriptDescriptions,runnable);
- for(let i=0;i<scriptToggles.length;i++){
- if(!scriptToggles[i])
- continue;
- let c = false;
- for(let j=0;j<runnable[i].length;j++){
- c = c || window.location.href.startsWith(runnable[i][j]);
- }
- if(!c)
- continue;
- let script = await getScript(aoonline,scriptNames[i].replace(" ",""),scriptURLs[i]);
- if(!script)
- continue;
- runScript(script);
- }
- }
- async function runScript(script){
- eval(script);
- }
- function getAOOnline(){
- let xmlHttp = new XMLHttpRequest();
- xmlHttp.open("GET","https://api.allorigins.win/raw?url=https://pastebin.com/",false);
- try{
- xmlHttp.send(null);
- }catch(e){
- return false;
- }
- return xmlHttp.status==200;
- }
- async function getScript(aoonline,name,URL){
- let allorigins = "https://api.allorigins.win/raw?cacheMaxAge=0&disableCache=true&url=";
- if(aoonline){
- let script;
- try{
- script = request(allorigins+URL);
- if(script.match(/<!DOCTYPE html>/))
- throw {message:"request error"};
- }catch(e){
- console.log("allorigins online, failed to load script for unknown reasons.");
- console.log("Attempting to load script from local backup.");
- console.log("Error: "+e.message);
- return await GM.getValue("bbsMasterSettings.script."+name,null);
- }
- GM.setValue("bbsMasterSettings.script."+name,script);
- return script;
- }else
- return await GM.getValue("bbsMasterSettings.script."+name,null);
- }
- run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement