Advertisement
Foxscotch

Image Hider

Jan 21st, 2016
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Image Hider
  3. // @namespace    https://foxscotch.us/
  4. // @version      1
  5. // @description  Hides images on the forum
  6. // @author       You
  7. // @match        https://forum.blockland.us/index.php*
  8. // @grant        none
  9. // ==/UserScript==
  10. /* jshint -W097 */
  11. 'use strict';
  12.  
  13. // Change this to true if you want to hide images in signatures too
  14. var includeSignatures = false;
  15.  
  16. var images = [];
  17.  
  18. if (window.location.search.startsWith('?action=pm')) {
  19.     images = images.concat(Array.prototype.slice.call(document.querySelectorAll('.personalmessage img')));
  20.     if (includeSignatures) {
  21.         images = images.concat(Array.prototype.slice.call(document.querySelectorAll('.signature img')));
  22.     }
  23. }
  24. else if (window.location.search.startsWith('?topic=')) {
  25.     images = images.concat(Array.prototype.slice.call(document.querySelectorAll('.post img')));
  26. }
  27.  
  28. function hideImage(img, btn) {
  29.     if (img.hidden) {
  30.         img.hidden = false;
  31.         btn.value = 'Hide';
  32.     }
  33.     else {
  34.         img.hidden = true;
  35.         btn.value = 'Show';
  36.     }
  37. }
  38.  
  39. function addButtons() {
  40.     for (var i = 0; i < images.length; i++) {
  41.         images[i].hidden = true;
  42.        
  43.         var btn = document.createElement('input');
  44.         btn.type = 'button';
  45.         btn.value = 'Show';
  46.         btn.style.display = 'block';
  47.        
  48.         btn.addEventListener('click', hideImage.bind(null, images[i], btn));
  49.        
  50.         images[i].parentElement.insertBefore(btn, images[i]);
  51.     }
  52. }
  53.  
  54. addButtons();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement