Imgur retro style

try to take over the world!

  1. // ==UserScript==
  2. // @name Imgur retro style
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://imgur.com/gallery/*
  8. // @match https://imgur.com/user/*
  9. // @match https://imgur.com/account/*
  10. // @grant none
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. // This script should run at "document-start" so we really don't render the images on the first post,
  15. // but it might just work(TM)
  16. function _code_to_inject() {
  17. var _hide_imgs = true;
  18. var _autoplay = false;
  19.  
  20. // We want to ensure we hook it as soon as possible, so lets use MutationObserver to wait for scripts.
  21. var config = {
  22. attributes: false,
  23. childList: true,
  24. subtree: false,
  25. characterData: false
  26. };
  27. var observer = new MutationObserver(function (mutationsList) {
  28. for (var mutation of mutationsList) {
  29. var addedNodes = mutation.addedNodes;
  30. if (!addedNodes) continue;
  31. for (var i = 0; i < addedNodes.length; i++) {
  32. if (addedNodes[i].tagName !== 'SCRIPT') continue;
  33. console.log('Added', addedNodes[i], window.Imgur);
  34. var script = addedNodes[i];
  35. script.onload = script.onreadystatechange = function () {
  36. if (window.Imgur && Imgur.Linkifier) {
  37. _inject();
  38. observer.disconnect();
  39. }
  40. }
  41. }
  42. }
  43. });
  44. function _inject() {
  45. console.log('Found Linkifier');
  46. init();
  47. }
  48. function do_observe() {
  49. if (window.Imgur && Imgur.Linkifier)
  50. _inject();
  51. else
  52. observer.observe(document.body, config);
  53. }
  54. // Depending on browser and userscript executor the body migh not exists yet.
  55. if (!document.body) {
  56. document.onreadystatechange = function () {
  57. if (document.body) {
  58. console.log('DOMContentLoaded');
  59. do_observe();
  60. document.onreadystatechange = null; // TODO: do this nicer
  61. }
  62. }
  63. } else {
  64. do_observe();
  65. }
  66.  
  67. function hookit(parent, name, func) {
  68. var o = parent[name];
  69. var f = function () {
  70. var x = func.apply(this, [
  71. o,
  72. arguments
  73. ]);
  74. return x
  75. };
  76. parent[name] = f;
  77. f.__o__ = o;
  78. f.__unhook__ = function () {
  79. parent[name] = f.__o__;
  80. }
  81. };
  82. function linkifier_grab_hook(o, args) {
  83. return o.apply(this, [
  84. args[0]
  85. ]);
  86. }
  87. function linkifier_reactionVideo_hook(o, args) {
  88. var x = o.apply(this, args);
  89. delete x.props['autoPlay'];
  90. return x;
  91. }
  92. function init() {
  93. if (_hide_imgs)
  94. hookit(Imgur.Linkifier.prototype, 'grab', linkifier_grab_hook);
  95. if (!_autoplay)
  96. hookit(Imgur.Linkifier.prototype, 'reactionVideo', linkifier_reactionVideo_hook);
  97. }
  98. }
  99. var s = document.createElement('script');
  100. s.textContent = '(' + _code_to_inject + ')()';
  101. //console.log("Inject into", document.location, ":", s.textContent);
  102. document.head.appendChild(s);