Advertisement
Degritone

BBS Post Link Preview

Oct 25th, 2021 (edited)
814
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name             BBS Post Link Previews
  3. // @namespace        dollars-bbs.org
  4. // @author           Degritone
  5. // @description      Allows you to hover over a >> link for a preview of the post
  6. // @match            *://*.dollars-bbs.org/*
  7. // @grant            none
  8. // ==/UserScript==
  9.  
  10. function request(url){
  11.   let xmlHttp = new XMLHttpRequest();
  12.   xmlHttp.open("GET",url,false);
  13.   xmlHttp.send(null);
  14.   return xmlHttp.responseText;
  15. }
  16.  
  17. function work(){
  18.   let replies = document.getElementsByClassName("replytext");
  19.   if(!replies){
  20.     setTimeout(work,100);
  21.     return;
  22.   }
  23.   setTimeout(work,500);
  24.   for(let i=0;i<replies.length;i++){
  25.     let as = replies[i].getElementsByTagName("a");
  26.     for(let j=0;j<as.length;j++){
  27.       if(as[j].href.startsWith("https://dollars-bbs.org") && as[j].href.match(/#[0-9]+$/)){
  28.         if(as[j].class == "" || !as[j].class){
  29.           as[j].setAttribute("class","postPreview");
  30.           as[j].addEventListener("mouseenter",preview,false);
  31.         }
  32.       }
  33.     }
  34.   }
  35. }
  36.  
  37. function preview(e){
  38.   while(document.getElementById("previewPost"))
  39.     document.getElementById("previewPost").parentNode.removeChild(document.getElementById("previewPost"));
  40.  
  41.   let parser = new DOMParser();
  42.   let page = parser.parseFromString(request(e.currentTarget.href),"text/html");
  43.   let target = e.currentTarget.href.match(/#[0-9]+$/)[0].replace("#","");
  44.   let post = page.getElementById(target).parentNode.parentNode.parentNode;
  45.   document.body.appendChild(post);
  46.   post.id = "previewPost";
  47.   post.class = "replytext";
  48.   post.style.position = "fixed";
  49.   post.style.topMargin = "auto";
  50.   post.style.bottomMargin = "auto";
  51.   post.style.rightMargin = "0px";
  52.   post.style.width = (600)+"px";
  53.   post.style.backgroundColor = "#4D4D4D";
  54.   post.style.border = "solid #EEEEEE 1px";
  55.   post.style.borderRadius = "7px";
  56.   post.style.fontSize = "13px";
  57.   post.style.overflowY = "auto";
  58.   post.style.maxHeight = ""+(window.innerHeight-2)+"px";78
  59.  
  60.   post.getElementsByClassName("replynum")[0].parentNode.style.fontWeight = "normal";
  61.   post.getElementsByClassName("replynum")[0].parentNode.style.fontSize = "13px";
  62.   post.getElementsByClassName("replynum")[0].parentNode.style.marginLeft = "5px";
  63.   post.getElementsByClassName("replynum")[0].parentNode.style.width = "590px";
  64.   post.getElementsByClassName("replynum")[0].parentNode.style.marginTop = "5px";
  65.  
  66.   post.getElementsByClassName("replynum")[0].getElementsByTagName("a")[0].style.textDecoration = "none";
  67.   post.getElementsByClassName("replynum")[0].getElementsByTagName("a")[0].style.fontWeight = "bold";
  68.   post.getElementsByClassName("postername")[0].style.fontSize = "16px";
  69.   post.getElementsByClassName("postername")[0].style.fontWeight = "bold";
  70.   post.getElementsByClassName("postertrip")[0].style.fontSize = "16px";
  71.   post.getElementsByClassName("postertrip")[0].style.fontStyle = "italic";
  72.  
  73.   if(post.getElementsByTagName("img").length>0){
  74.     let imgdiv = document.createElement("div");
  75.     post.getElementsByTagName("h3")[0].after(imgdiv);
  76.     imgdiv.appendChild(post.getElementsByTagName("img")[0].parentNode);
  77.     imgdiv.style.margin = "auto";
  78.     imgdiv.style.width = "500px";
  79.     imgdiv.style.border = "1px solid #EEEEEE";
  80.   }
  81.  
  82.   let as = post.getElementsByClassName("replytext")[0].getElementsByTagName("a");
  83.   for(let i=0;i<as.length;i++){
  84.     if(as[i].href.startsWith("https://dollars-bbs.org") && as[i].href.match(/#[0-9]+$/)){
  85.       as[i].addEventListener("mouseenter",preview,false);
  86.     }
  87.   }
  88.  
  89.   let width = 600+((post.offsetHeight>=parseInt(post.style.maxHeight.replace("px","")))?15:0);
  90.   post.style.width = width+"px";
  91.   post.style.right = "1px";
  92.   post.style.top = ""+((window.innerHeight-post.offsetHeight)/2+1)+"px";
  93.   post.addEventListener("mouseup",(e)=>{e.stopPropagation();});
  94. }
  95.  
  96. function remove(){
  97.   while(document.getElementById("previewPost"))
  98.     document.getElementById("previewPost").parentNode.removeChild(document.getElementById("previewPost"));
  99. }
  100.  
  101. work();
  102. document.addEventListener("mouseup",remove,false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement