Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name BBS Post Link Previews
- // @namespace dollars-bbs.org
- // @author Degritone
- // @description Allows you to hover over a >> link for a preview of the post
- // @match *://*.dollars-bbs.org/*
- // @grant none
- // ==/UserScript==
- function request(url){
- let xmlHttp = new XMLHttpRequest();
- xmlHttp.open("GET",url,false);
- xmlHttp.send(null);
- return xmlHttp.responseText;
- }
- function work(){
- let replies = document.getElementsByClassName("replytext");
- if(!replies){
- setTimeout(work,100);
- return;
- }
- setTimeout(work,500);
- for(let i=0;i<replies.length;i++){
- let as = replies[i].getElementsByTagName("a");
- for(let j=0;j<as.length;j++){
- if(as[j].href.startsWith("https://dollars-bbs.org") && as[j].href.match(/#[0-9]+$/)){
- if(as[j].class == "" || !as[j].class){
- as[j].setAttribute("class","postPreview");
- as[j].addEventListener("mouseenter",preview,false);
- }
- }
- }
- }
- }
- function preview(e){
- while(document.getElementById("previewPost"))
- document.getElementById("previewPost").parentNode.removeChild(document.getElementById("previewPost"));
- let parser = new DOMParser();
- let page = parser.parseFromString(request(e.currentTarget.href),"text/html");
- let target = e.currentTarget.href.match(/#[0-9]+$/)[0].replace("#","");
- let post = page.getElementById(target).parentNode.parentNode.parentNode;
- document.body.appendChild(post);
- post.id = "previewPost";
- post.class = "replytext";
- post.style.position = "fixed";
- post.style.topMargin = "auto";
- post.style.bottomMargin = "auto";
- post.style.rightMargin = "0px";
- post.style.width = (600)+"px";
- post.style.backgroundColor = "#4D4D4D";
- post.style.border = "solid #EEEEEE 1px";
- post.style.borderRadius = "7px";
- post.style.fontSize = "13px";
- post.style.overflowY = "auto";
- post.style.maxHeight = ""+(window.innerHeight-2)+"px";78
- post.getElementsByClassName("replynum")[0].parentNode.style.fontWeight = "normal";
- post.getElementsByClassName("replynum")[0].parentNode.style.fontSize = "13px";
- post.getElementsByClassName("replynum")[0].parentNode.style.marginLeft = "5px";
- post.getElementsByClassName("replynum")[0].parentNode.style.width = "590px";
- post.getElementsByClassName("replynum")[0].parentNode.style.marginTop = "5px";
- post.getElementsByClassName("replynum")[0].getElementsByTagName("a")[0].style.textDecoration = "none";
- post.getElementsByClassName("replynum")[0].getElementsByTagName("a")[0].style.fontWeight = "bold";
- post.getElementsByClassName("postername")[0].style.fontSize = "16px";
- post.getElementsByClassName("postername")[0].style.fontWeight = "bold";
- post.getElementsByClassName("postertrip")[0].style.fontSize = "16px";
- post.getElementsByClassName("postertrip")[0].style.fontStyle = "italic";
- if(post.getElementsByTagName("img").length>0){
- let imgdiv = document.createElement("div");
- post.getElementsByTagName("h3")[0].after(imgdiv);
- imgdiv.appendChild(post.getElementsByTagName("img")[0].parentNode);
- imgdiv.style.margin = "auto";
- imgdiv.style.width = "500px";
- imgdiv.style.border = "1px solid #EEEEEE";
- }
- let as = post.getElementsByClassName("replytext")[0].getElementsByTagName("a");
- for(let i=0;i<as.length;i++){
- if(as[i].href.startsWith("https://dollars-bbs.org") && as[i].href.match(/#[0-9]+$/)){
- as[i].addEventListener("mouseenter",preview,false);
- }
- }
- let width = 600+((post.offsetHeight>=parseInt(post.style.maxHeight.replace("px","")))?15:0);
- post.style.width = width+"px";
- post.style.right = "1px";
- post.style.top = ""+((window.innerHeight-post.offsetHeight)/2+1)+"px";
- post.addEventListener("mouseup",(e)=>{e.stopPropagation();});
- }
- function remove(){
- while(document.getElementById("previewPost"))
- document.getElementById("previewPost").parentNode.removeChild(document.getElementById("previewPost"));
- }
- work();
- document.addEventListener("mouseup",remove,false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement