Skip to content

Instantly share code, notes, and snippets.

@chadlavi
Last active February 14, 2018 20:01
Show Gist options
  • Save chadlavi/fae974f20b5d7567fbf6a94931a0e2d7 to your computer and use it in GitHub Desktop.
Save chadlavi/fae974f20b5d7567fbf6a94931a0e2d7 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name image hider
// @namespace https://gist.github.com/chadlavi/fae974f20b5d7567fbf6a94931a0e2d7
// @downloadURL https://gist.github.com/chadlavi/fae974f20b5d7567fbf6a94931a0e2d7/raw/image-hider.user.js
// @updateURL https://gist.github.com/chadlavi/fae974f20b5d7567fbf6a94931a0e2d7/raw/image-hider.user.js
// @version 1.26
// @description hide images until you want them
// @include https://6.f*.org/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js
// @copyright 2018, Chad Lavimoniere
// ==/UserScript==
/* jshint -W097 */
'use strict';
function hideImages() {
var imgs=document.getElementsByTagName("img");
var img_count=imgs.length;
for (var i=0; i<img_count; i++) {
var A = document.getElementsByTagName("img")[i];
var h = A.height;
var w = A.width;
var x=imgs[i].getAttribute("src");
var div = document.createElement("div");
A.parentNode.replaceChild(div, A);
var b = document.createElement("div");
var img = document.createElement("img");
div.appendChild(b);
div.appendChild(img);
img.setAttribute("src", x);
img.setAttribute("style", "display: inline-block; width:"+w+"px; height:"+h+"px; position: absolute; opacity: 0;")
b.setAttribute("style", "background-color: none; width:"+w+"px; height:"+h+"px; color: inherit; text-align: center; line-height:"+h+"px; position: absolute;");
b.setAttribute("class", "image-hider");
img.setAttribute("class", "hidden");
div.setAttribute("style", "background-color: none; width:"+w+"px; height:"+h+"px; position: relative;");
b.innerHTML="[image]";
img.setAttribute("onclick", "if (this.getAttribute(\"class\")==\"hidden\") {this.style.opacity=1; this.setAttribute('class', 'shown');} else {this.style.opacity=0; this.setAttribute('class', 'hidden');}");
}
}
$(window).on("load", function() {
setTimeout(function(){
//do what you need here
hideImages();
}, 100);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment