F-i-f / Slashdot Adblock Fixes

// ==UserScript==
// @name        Slashdot Adblock Fixes
// @description To be used in conjunction with AdBlock/uBlock:  hides dynamically fetched ads (aka. sponsored contents) and fixes scrolling issue on the side bar when ad-blocking is on.
// @copyright   2016-2023 Philippe Troin
// @namespace   org.fifi.userscripts.slashdot-hide-sponsored
// @include     https://*slashdot.org/*
// @include     http://*slashdot.org/*
// @version     14
// @grant       none
// @run-at      document-start
// @require     https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @license     BSD-3-Clause
// ==/UserScript==

(function () {
  var oldOpen = XMLHttpRequest.prototype.open;
  XMLHttpRequest.prototype.open = function () {
    if (arguments[1] == '/ajax.pl?op=nel') {
      console.log('Slashdot Adblock Fixes: Prevented sponsored content!');
      Array.prototype.splice.call(arguments, 1, 1, 'http://127.0.0.253/nosuchdoc');
    }
    oldOpen.apply(this, arguments);
  };
  document.addEventListener("DOMContentLoaded", function () {
    setTimeout(function () {
      jQuery('.adwrap-unviewed').removeClass('adwrap-unviewed');
      jQuery('aside#slashboxes').css({
        'position': ''
      });
      console.log('Slashdot Adblock Fixes: Nuked adwrap-unviewed');
    }, 0);
    if (document.documentURI.match(/slashdot\.org\/story\//) !== null) {
      jQuery('.has-rail-right > .main-content, div#comments.a2commentwrap').each(function () {
        jQuery(this).css('margin-right', jQuery(this).css('margin-left'));
        console.log('Slashdot Adblock Fixes: Tweaked right margin.');
      });
      jQuery('#sideb').each(function() {
        jQuery(this).css('flex', '');
        console.log('Slashdot Adblock Fixes: Nuked sidebar flex.');
      });
    }
  });
  console.log('Slashdot Adblock Fixes: loaded.');
})();