sjehuda / Downloader.exe Remover

// ==UserScript== 
// @name        Downloader.exe Remover 
// @namespace   remover.exe.Downloader 
// @description Remove Downloader.exe from search results. For more information, read about "Torrent Poisoning" 
// @author      Schimon Jehudah, Adv. 
// @copyright   2022, Schimon Jehudah (http://schimon.i2p) 
// @license     MIT; https://opensource.org/licenses/MIT 
// @grant       none 
// @homepageURL https://openuserjs.org/scripts/sjehuda/Downloader.exe_Remover 
// @supportURL  https://openuserjs.org/scripts/sjehuda/Downloader.exe_Remover/issues 
// @match       *://bt4g.org/search/* 
// @match       *://*.bt4g.org/search/* 
// @version     1.0.0 
// @run-at      document-end 
// @icon        data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48dGV4dCB5PSIuOWVtIiBmb250LXNpemU9IjkwIj7wn5eR77iPPC90ZXh0Pjwvc3ZnPgo=
// ==/UserScript==

// NOTE
// We can use 
// count = 'count(' + query + ')'; 
// but I've chose otherwise for my students 
//
// TODO
// Use a shorter query for count and 
// place the query itself inside if 
//

var count, element, query, total;

query = '//div[contains(h5/a/@title, "Downloader.exe") and span/b[@class="cpill blue-pill"]/text() = "782.95KB"]';

count = 'count(//div[contains(h5/a/@title, "Downloader.exe") and span/b[@class="cpill blue-pill"]/text() = "782.95KB"])';

count = document.evaluate(
  count, document, null,
  XPathResult.STRING_TYPE);
count = count.stringValue;

if (count > 0) {
  total = 0;
  for (let i = 0; i < count; i++) {
    element = document.evaluate(
      query, document, null,
      XPathResult.FIRST_ORDERED_NODE_TYPE);
    //element.singleNodeValue.style.display = 'none';
    element = element.singleNodeValue;
    element.remove();
    total = total + 1;
  }
  alert(total + ' torrent poisoning results were removed.');
}