STG Filtering GreaseMonkey script

This is a very early alpha release, but thought I'd see if anyone finds any value in it.
This was written and tested with Firefox / GreaseMonkey. It might also work in other browsers with TamperMonkey or ViolentMonkey.

So, there's a LOT of duplicates on STG. People that post multiple times a day, and lots of scams. Basically, it takes the gallery and groups the photos up by post, making it clear that multiple photos are part of the same post.

To the right of each set is an X. If you click that, it will register all the images in that row, and remove the current row and any other row that includes the same images. At the very bottom of the screen is a reset button to clear your filters, but otherwise they should persist.

To install, add the GreaseMonkey extension to FireFox. Then, left click the monkey face, and click "New User Script", and paste the following:

Code:
// ==UserScript==
// @name     Skip the Crap
// @author    EquateMan
// @version  1.0.0
// @grant       GM.setValue
// @grant       GM.getValue
// @grant                GM.listValues
// @grant                GM.deleteValue
// @match https://*.skipthegames.com/*
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// ==/UserScript==


var input=document.createElement("input");
input.type="button";
input.value="Reset all filters";
input.onclick = showAlert;
document.body.appendChild(input); 

function setKey(key)
{
  GM.setValue(key, true);
}

async function getKey(key)
{ 
  var result = await GM.getValue(key);
  return result;
}

async function showAlert()
{
  let keys = await GM.listValues();
  for (let key of keys) {
    GM.deleteValue(key);
  }
  alert("Filters reset. Refresh your browser.");
}


function filter() 
{  
  var filterId = this.id;
  filterRow(filterId);
}

function filterRow(filterId)
{
  
  $(".day-gallery").find("tr").each(function() { 
    if($(this).attr('id') == filterId) { 
      addRowToFilters($(this));
        filterAll();
    } 
  } );
}

function addRowToFilters(row)
{
  var links = row.children("a");
  for(var i = 0; i < links.length; i++) {
    var link = links.eq(i);
    var imageId = link.children("img").attr('src');
    setKey(imageId);
  }  
}

function filterAll()
{
  $(".day-gallery").each(function() {
    var rows = $(this).children("table").children("tbody").children("tr").each(function() {    
        var row = $(this);
        var images = row.children("a").children("img");
      
      for (var i = 0; i < images.length; i++) {
            var image = images.eq(i);
        getKey(image.attr('src')).then(function(filter) {
          if(filter) {
            $(row).remove();
          }
        });
      }
    });
  });
}

function hashImage(imageUrl)
{    //https://stackoverflow.com/questions/15208640/hashing-an-image-in-javascript
  var xhr = new XMLHttpRequest();
  xhr.open('GET', '/my/image/file.png', true);
  xhr.responseType = 'arraybuffer'; // this will accept the response as an ArrayBuffer
  xhr.onload = function(buffer) {
      var words = new Uint32Array(buffer),
          hex = '';
      for (var i = 0; i < words.length; i++) {
        hex += words.get(i).toString(16);  // this will convert it to a 4byte hex string
      }
      console.log(hex);
  };
  xhr.send();
}

var lastTitle;

//convert
$(".day-gallery").each(function() {
  
  var table = $("<table />");
  $(this).prepend(table);
  var row;
  var filterButton;
  
  var children = $(this).children();
  for (var i = 0; i < children.length; i++) {
    var currentChild = children.eq(i);
    
    var url = currentChild.attr('href');
    var title = currentChild.attr('title');
    var picUrl = currentChild.children("img").attr('src');

    if(title) {    // this filters to just the gallery links        
      if(title != lastTitle) { 
        
        row = $("<tr />");
        row.attr('id', url);
        table.append(row);
        
        filterButton = $("<input />");
        filterButton.attr('type', 'button');
        filterButton.attr('value', 'X');
        filterButton.attr('id', url);
        filterButton.click(filter);
        
        row.append(filterButton);
      }
      
      row.append(currentChild);
      
    }
    lastTitle = title;
  }
  
  filterAll();

});
morbidxrabs's Avatar
Thanks! I can finally hide the obnoxious fake ads.