Imgur retro style

try to take over the world!

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name         Imgur retro style
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://imgur.com/gallery/*
// @match        https://imgur.com/user/*
// @match        https://imgur.com/account/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

// This script should run at "document-start" so we really don't render the images on the first post,
// but it might just work(TM)
function _code_to_inject() {
  var _hide_imgs = true;
  var _autoplay = false;

  // We want to ensure we hook it as soon as possible, so lets use MutationObserver to wait for scripts.
  var config = {
    attributes: false,
    childList: true,
    subtree: false,
    characterData: false
  };
  var observer = new MutationObserver(function (mutationsList) {
    for (var mutation of mutationsList) {
      var addedNodes = mutation.addedNodes;
      if (!addedNodes) continue;
      for (var i = 0; i < addedNodes.length; i++) {
        if (addedNodes[i].tagName !== 'SCRIPT') continue;
        console.log('Added', addedNodes[i], window.Imgur);
        var script = addedNodes[i];
        script.onload = script.onreadystatechange = function () {
          if (window.Imgur && Imgur.Linkifier) {
            _inject();
            observer.disconnect();
          }
        }
      }
    }
  });
  function _inject() {
    console.log('Found Linkifier');
    init();
  }
  function do_observe() {
    if (window.Imgur && Imgur.Linkifier)
    _inject();
     else
    observer.observe(document.body, config);
  }
  // Depending on browser and userscript executor the body migh not exists yet.
  if (!document.body) {
    document.onreadystatechange = function () {
      if (document.body) {
        console.log('DOMContentLoaded');
        do_observe();
        document.onreadystatechange = null; // TODO: do this nicer
      }
    }
  } else {
    do_observe();
  }

  function hookit(parent, name, func) {
    var o = parent[name];
    var f = function () {
      var x = func.apply(this, [
        o,
        arguments
      ]);
      return x
    };
    parent[name] = f;
    f.__o__ = o;
    f.__unhook__ = function () {
      parent[name] = f.__o__;
    }
  };
  function linkifier_grab_hook(o, args) {
    return o.apply(this, [
      args[0]
    ]);
  }
  function linkifier_reactionVideo_hook(o, args) {
    var x = o.apply(this, args);
    delete x.props['autoPlay'];
    return x;
  }
  function init() {
    if (_hide_imgs)
      hookit(Imgur.Linkifier.prototype, 'grab', linkifier_grab_hook);
    if (!_autoplay)
      hookit(Imgur.Linkifier.prototype, 'reactionVideo', linkifier_reactionVideo_hook);
  }
}
var s = document.createElement('script');
s.textContent = '(' + _code_to_inject + ')()';
//console.log("Inject into", document.location, ":", s.textContent);
document.head.appendChild(s);