Degritone

Better Board Menu

Oct 25th, 2021 (edited)
353
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name             Better Board Menu
  3. // @namespace        dollars-bbs.org
  4. // @author           Degritone
  5. // @description      Makes the board menu stick to the screen and have drop-down arrows to expand sub-buards
  6. // @match            *://*.dollars-bbs.org/*
  7. // @grant            none
  8. // ==/UserScript==
  9.  
  10. function work(loaded){
  11.   if(!document.getElementById("boardmenu")){
  12.     setTimeout(work,100,false);
  13.     return;
  14.   }
  15.   if(!loaded){
  16.     setTimeout(work,1000,true);
  17.     return;
  18.   }
  19.   window.onscroll = ()=>document.getElementById("boardmenu").style.top=""+Math.max(189-window.scrollY,0)+"px";
  20.   let boardmenu = document.getElementById("boardmenu");
  21.   boardmenu.style.position = "fixed";
  22.   boardmenu.style.top = ""+Math.max(189-window.scrollY,0)+"px";
  23.   if(document.getElementById("posts"))
  24.     document.getElementById("posts").style.marginLeft = "180px";
  25.   if(document.getElementById("threadbox"))
  26.     document.getElementById("threadbox").style.marginLeft = "180px";
  27.   if(document.getElementById("contentarea"))
  28.     document.getElementById("contentarea").style.marginLeft = "180px";
  29.   if(document.getElementById("threads"))
  30.     document.getElementById("threads").style.marginLeft = "180px";
  31.  
  32.   removeAllSubBoards(boardmenu);
  33.   if(document.getElementById("testbutton"))
  34.     removeAllSubBoards(boardmenu);
  35.  
  36.   let brs = boardmenu.getElementsByTagName("br");
  37.   for(let i=brs.length-1;i>=0;i--){
  38.     if(brs[i].previousElementSibling){
  39.       if(brs[i].nextElementSibling){
  40.         if(brs[i].previousElementSibling.outerHTML == brs[i].nextElementSibling.outerHTML)
  41.           boardmenu.removeChild(brs[i]);
  42.       }
  43.     }
  44.   }
  45.  
  46.   let styleBase = 'style="border-radius:7px; border:solid 2px #EEEEEE; background-color:#151515; padding:5px; text-decoration:none; font-size:13px; ';
  47.   let mainsubs = '<br><a href="https://dollars-bbs.org/intro/" id="introbutton" name="inbu" '+styleBase+'padding-left:16px; padding-right:16px;">Introductions</a><br><br>'+
  48.                  '<a href="https://dollars-bbs.org/countries/" id="countriesbutton" name="cobu" '+styleBase+'padding-left:26px; padding-right:26px;">Countries</a><br><br>'+
  49.                  '<a href="https://dollars-bbs.org/missions/" id="missionsbutton" name="mibu" '+styleBase+'padding-left:29px; padding-right:29px;">Missions</a><br><br>'+
  50.                  '<a href="https://dollars-bbs.org/suggestions/" id="suggestionsbutton" name="subu" '+styleBase+'padding-left:19px; padding-right:18px;">Suggestions</a>';
  51.   let gamessubs = '<br><a href="https://dollars-bbs.org/vn/" id="vnbutton" name="vnbu" '+styleBase+'padding-left:15px; padding-right:15px;">Visual Novels</a>';
  52.   let randomsubs = '<br><a href="https://dollars-bbs.org/test/" id="testbutton" name="tebu" '+styleBase+'padding-left:39px; padding-right:39px;">Test</a>';
  53.  
  54.   let ms = document.createElement("div");
  55.   let gs = document.createElement("div");
  56.   let rs = document.createElement("div");
  57.  
  58.   initializeDiv(ms,mainsubs,"main");
  59.   initializeDiv(gs,gamessubs,"games");
  60.   initializeDiv(rs,randomsubs,"random");
  61.  
  62.   let md = document.createElement("button");
  63.   let gd = document.createElement("button");
  64.   let rd = document.createElement("button");
  65.  
  66.   initializeButton(md,20,"main",boardmenu);
  67.   initializeButton(gd,200,"games",boardmenu);
  68.   initializeButton(rd,400,"random",boardmenu);
  69. }
  70.  
  71. function removeAllSubBoards(boardmenu){
  72.   remove("introbutton",boardmenu);
  73.   remove("countriesbutton",boardmenu);
  74.   remove("missionsbutton",boardmenu);
  75.   remove("suggestionsbutton",boardmenu);
  76.   remove("vnbutton",boardmenu);
  77.   remove("testbutton",boardmenu);
  78. }
  79.  
  80. function remove(name,boardmenu){
  81.   let child = document.getElementById(name);
  82.   if(!child)
  83.     return;
  84.   if(child.name)
  85.     return;
  86.   boardmenu.removeChild(child);
  87. }
  88.  
  89. function isolateBoard(){
  90.   return window.location.href.replace(/https:\/\/dollars-bbs\.org\//,"").replace("/","").replace("index.html","").replace(/res[0-9]+.html/,"");
  91. }
  92.  
  93. function initializeDiv(d,s,b){
  94.   d.innerHTML = s;
  95.   d.style.display = "none";
  96.   document.getElementById(b+"button").after(d);
  97.   d.id = b+"dropdown";
  98.   d.style.marginBottom = "-21px";
  99. }
  100.  
  101. function showBoards(div,b){
  102.   let thisLink = document.getElementById(b+"link");
  103.   if(div.style.display == "none"){
  104.     div.style.display = "";
  105.     thisLink.innerHTML = "▲";
  106.     thisLink.style.paddingBottom = "5px";
  107.     thisLink.style.paddingTop = "3px";
  108.     if(div.innerHTML.includes(isolateBoard())){
  109.       document.getElementById(isolateBoard()+"button").style.backgroundColor = "#4D4D4D";
  110.     }
  111.   } else {
  112.     div.style.display = "none";
  113.     thisLink.innerHTML = "▼";
  114.     thisLink.style.paddingBottom = "3px";
  115.     thisLink.style.paddingTop = "5px";
  116.   }
  117.   if(document.getElementById("mainlink") && document.getElementById("gameslink") && document.getElementById("randomlink")){
  118.     document.getElementById("mainlink").style.top = document.getElementById("mainbutton").offsetTop+4+"px";
  119.     document.getElementById("gameslink").style.top = document.getElementById("gamesbutton").offsetTop+4+"px";
  120.     document.getElementById("randomlink").style.top = document.getElementById("randombutton").offsetTop+4+"px";
  121.   }
  122. }
  123.  
  124. function initializeButton(d,t,b,boardmenu){
  125.   boardmenu.appendChild(d);
  126.   d.innerHTML = "▼";
  127.   d.onclick = ()=>showBoards(document.getElementById(b+"dropdown"),b);
  128.   d.style = "position:absolute; right:25px; border-radius:7px; border:solid 2px #EEEEEE; background-color:#151515; padding:5px; padding-bottom:3px; text-decoration:none; font-size:10px; cursor:pointer; color:#EEEEEE;";
  129.   d.style.top = document.getElementById(b+"button").offsetTop+4+"px";
  130.   d.id = b+"link";
  131.   if(document.getElementById(b+"dropdown").innerHTML.includes(isolateBoard()) || b == isolateBoard()){
  132.     showBoards(document.getElementById(b+"dropdown"),b);
  133.   }
  134.   removeAllSubBoards(boardmenu);
  135. }
  136.  
  137. work(false);
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
RAW Paste Data