As a French person I feel like it's my duty to explain strikes to you. - AdrienIer

Create an account  

 
Greasemonkey script to avoid spoiler threads

(November 5th, 2018, 11:00)Krill Wrote: Does anyone have a copy of this? The link doesn't work anymore.

Wow, I'd forgotten I helped work on this until I suddenly got an email notification that this thread was replied to...

The version I'd made available and linked to later in this thread ( https://nwcs.com/~jvc/gaming/rb/newstyle...er.user.js ) is still out there. No idea if it still works, though, I haven't been using it lately. (Civ5 ruined everything for me. frown )
Participant in:
PBEM45, "Greens" Division (Sury of Carthage)
RB Demogame 1 pirate
Reply

Thank you!
Current games (All): RtR: PB80 Civ 6: PBEM23

Ended games (Selection): BTS games: PB1, PB3, PBEM2, PBEM4, PBEM5B, PBEM50. RB mod games: PB5, PB15, PB27, PB37, PB42, PB46, PB71. FFH games: PBEMVII, PBEMXII. Civ 6:  PBEM22 Games ded lurked: PB18
Reply

still doesnt work frown
Youtube Channel Twitch aka Mistoltin
Reply

I reinstalled it, and it's working again for me now.
Current games (All): RtR: PB80 Civ 6: PBEM23

Ended games (Selection): BTS games: PB1, PB3, PBEM2, PBEM4, PBEM5B, PBEM50. RB mod games: PB5, PB15, PB27, PB37, PB42, PB46, PB71. FFH games: PBEMVII, PBEMXII. Civ 6:  PBEM22 Games ded lurked: PB18
Reply

This had been working for me on Chrome, now it's suddenly not (as of yesterday?), both on Windows 7 and Windows 10. Stop me before I click on a spoiler thread again!
Reply

Tried installing it, but I don't see any new buttons appear. I disabled all cookie/content blockers I have installed, but to no avail.
Reply

Apparently the old script wouldn't run because it used a prefix of http: instead of https: (thanks, Brick!). Here's a modified script that seems to be working for me:

Code:
// ==UserScript==
// @name    Realms Beyond Thread Blocker
// @namespace   realmsbeyond
// @description Allows you to block access to specific threads to avoid spoiler information.
// @include http://realmsbeyond.net/forums/*
// @include http://www.realmsbeyond.net/forums/*
// @include https://realmsbeyond.net/forums/*
// @include https://www.realmsbeyond.net/forums/*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_log
// ==/UserScript==

// Chrome compatibility:
if (!this.GM_getValue || (this.GM_getValue.toString && this.GM_getValue.toString().indexOf("not supported")>-1)) {
   this.GM_getValue=function (key,def) {
       return localStorage[key] || def;
   };
   this.GM_setValue=function (key,value) {
       localStorage[key]=value;
       return localStorage[key];
   };
   this.GM_deleteValue=function (key) {
       return delete localStorage[key];
   };
}

function xpath(path, root)
{
   if (!root) {
       root = document;
   }
   var result = document.evaluate(path, root, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
   var nodes = [];
   for (var i = 0; i < result.snapshotLength; i++) {
       nodes[i] = result.snapshotItem(i);
   }
   return nodes;
}

function xpath1(path, root)
{
   var nodes = xpath(path, root);
   if (nodes.length < 1) {
       return undefined;
   }
   return nodes[0];
}

function fixForumDisplay(blocked)
{
   //var r = xpath("//tr/td[contains(@class, 'forumdisplay')]/div/span/a[starts-with(@href, 'showthread.php')]");  //JVC the 'forumdisplay' check is unnecessary if we're looking for showthread.php
   var r = xpath("//tr/td/div/span/a[starts-with(@href, 'showthread.php')]");
   if (!r) { GM_log("error 10"); return; }
   for (var i = 0; i < r.length; i++) {
       var href = r[i].getAttribute("href");
       if (href.match(/showthread\.php.*(\?|\&)tid=(\d+)/)) {
           var t = RegExp.$2;
           var row = r[i].parentNode.parentNode.parentNode.parentNode;
           if (!row || row.nodeName != "TR") { GM_log("error 11"); return }
           if (row.done) continue;
           row.done = true;
           //var cell = row.cells[1];  //JVC cells[1] in newer styles is now the thread link, not the thread icon!
           var cell = row.cells[0];
           var link = document.createElement("a");
           link.setAttribute("thread", t);
           if (blocked[t]) {
               link.innerHTML = "<div style='color: #ff7777; cursor: pointer;'><b>&#x2573;</b></div>";
               link.setAttribute("title", "Unblock this thread");
           }
           else {
               link.innerHTML = "<div style='color: #77ff77; cursor: pointer;'><b>&#x2713;</b></div>";
               link.setAttribute("title", "Block this thread");
           }
           function listener(e) {
               var t = e.target.parentNode.parentNode.getAttribute("thread");
               blocked[t] = !blocked[t];
               setBlockedThreads(blocked);
               location.href = "";
           }
           link.addEventListener("click", listener, false);
           //cell.innerHTML = '';      //JVC we don't want to wipe the existing content now that we're using a different column
           cell.appendChild(link);
       }
   }
}

function fixThreadLinks(blocked)
{
   var links = xpath("//a[starts-with(@href, 'showthread.php')]");
   for (var i = 0; i < links.length; i++) {
       var link = links[i];
       var href = link.getAttribute("href");
       if (href.match(/showthread\.php.*(\?|\&)tid=(\d+)/)) {
           var t = RegExp.$2;
           if (blocked[t]) {
               link.removeAttribute("href");
               var style = link.getAttribute("style");
               if (style) {
                   style += "; ";
               }
               else {
                   style = "";
               }
               style += "color: #ff7777; cursor: pointer;";
               link.setAttribute("style", style);
               link.setAttribute("title", "Blocked thread");
           }
       }
   }
}

function blockThread(t)
{
   var blocked = getBlockedThreads();
   blocked[t] = true;
   setBlockedThreads(blocked);
}

function unblockThread(t)
{
   var blocked = getBlockedThreads();
   blocked[t] = false;
   setBlockedThreads(blocked);
}

function getBlockedThreads()
{
   var r = {};
   var t = GM_getValue("blockedThreads");
   if (t) {
       t = t.split(/;/);
       for (var i = 0; i < t.length; i++) {
           r[t[i]] = true;
       }
   }
   return r;
}

function setBlockedThreads(blocked)
{
   var s = [];
   for (var t in blocked) {
       if (blocked[t]) {
           s.push(t);
       }
   }
   GM_setValue("blockedThreads", s.join(";"));
}

function main()
{
   var blocked = getBlockedThreads();
   var path = document.location.pathname;
//    if (path.match(/forumdisplay\.php/) || path.match(/index\.php/)) {*/  //JVC we also want to check the "New Posts" results page
   if (path.match(/forumdisplay\.php/) || path.match(/index\.php/) || path.match(/search\.php/)) {
       fixForumDisplay(blocked);
   }
   fixThreadLinks(blocked);
}

main();
Reply



Forum Jump: