Enquirer Home Page | Twitter | Back to Improbable Island


// ==UserScript==
// @name            ii-block
// @namespace       http://enquirer.improbableisland.com/dokuwiki/doku.php?id=greasemonkey
// @author          Full Metal Lion
// @description     Blocks a user in chat
// @version         1.0
// @match           *://*.improbableisland.com/*
// @exclude         *://enquirer.improbableisland.com/*
// @icon            http://improbableisland.com/favicon.ico
// @grant           none
// ==/UserScript==
var blockedUserIDs = []; //put users ids here, seperated by commas (eg [100001,47,201])
var showBlankLines = true; //set this to false if you want no indication that a message was blocked
//helper functions to delete html elements
//you'd think that we could just call .parent.remove() on the things we find
// but actually the chat html is hot garbage and nested improperly, so we have to do this
// (don't worry though, this code will still function on proper html, in case CMJ ever decides to fix it)
function delL(element){
 if(element && element.className != "singlecomment"){
function delR(element){
 if(element && (element.className != "singlecomment")){
//the actual function of interest
function removeBlockedMessages(){
	var miceover = document.querySelectorAll(".commentarymouseoverlink")
	for (var m of miceover){
        for (var x of blockedUserIDs){
            if (m.href == "https://www.improbableisland.com/bio.php?char=" + x){
                if(showBlankLines && m.innerHTML){ //there are actually two elements per comment, one empty.
                    //we only want one (else we'd get double spacing) so we pick the nonempty one.
removeBlockedMessages(); //invoke function when page loads
//run removeBlockedMessages whenever an ajax call completes (probably a chat auto-update)
//(This is the part that doesn't work in greasemonkey)
//from https://stackoverflow.com/a/29293383 :
(function(open) {
    window.XMLHttpRequest.prototype.open = function() {
        this.addEventListener("readystatechange", function() {
            if(this.readyState == 4){removeBlockedMessages();}
        }, false);
        open.apply(this, arguments);
//If we're running on a system that supports @grant none, then we're done.
//However, the greasemonkey extension on Firefox does not
//so we must do something special to support it
//Here I use the Content Scope Runner as found in
if ('undefined' == typeof __PAGE_SCOPE_RUN_II_BLOCK_) {
  (function page_scope_runner() {
    // If we're _not_ already running in the page, grab the full source
    // of this script.
    var my_src = "(" + page_scope_runner.caller.toString() + ")();";
    // Create a script node holding this script, plus a marker that lets us
    // know we are running in the page scope (not the Greasemonkey sandbox).
    // Note that we are intentionally *not* scope-wrapping here.
    var script = document.createElement('script');
    script.setAttribute("type", "text/javascript");
    script.textContent = "var __PAGE_SCOPE_RUN_II_BLOCK_ = true;\n" + my_src;
    // Insert the script node into the page, so it will run, and immediately
    // remove it to clean up.  Use setTimeout to force execution "outside" of
    // the user script scope completely.
    setTimeout(function() {
        }, 0);
  // Stop running, because we know Greasemonkey actually runs us in
  // an anonymous wrapper.
Logged in as: Guest (Guest)
greasemonkey/ii-block.txt · Last modified: 2018/11/07 20:51 by Full Metal Lion