Skip to content

Instantly share code, notes, and snippets.

@error418
Last active May 23, 2016 20:01
Show Gist options
  • Save error418/e1a348ee86ad67e0088b to your computer and use it in GitHub Desktop.
Save error418/e1a348ee86ad67e0088b to your computer and use it in GitHub Desktop.
A Greasemonkey/Tampermonkey script, which enables the user to view nsfw pictures instead of the annoying NSFW banners on 9gag. No 9gag sign up required anymore!
// ==UserScript==
// @name 9GAG NSFW picture peeker
// @include http://9gag.com/*
// @version 0.1.6
// @description 9GAG NSFW peeker
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.js
// @copyright 2012+, Error418
// ==/UserScript==
/*
____ _________ ______ _ _______ _______ __ __
/ __ \/ ____/ | / ____/ / | / / ___// ____/ | / / ____ ___ ___ / /_____ _____
/ /_/ / / __/ /| |/ / __ / |/ /\__ \/ /_ | | /| / / / __ \/ _ \/ _ \/ //_/ _ \/ ___/
\__, / /_/ / ___ / /_/ / / /| /___/ / __/ | |/ |/ / / /_/ / __/ __/ , \/ __/ /
/____/\____/_/ |_\____/ /_/ |_//____/_/ |__/|__/ / .___/\___/\___/_/|_|\___/_/
/_/
Thanks for using this script. Feel free to spread the word and leave a comment on this gist :)
Version 0.1.6
- must use GET requests for content-checking.. Thanks 9GAG for not obeying standards!
Version 0.1.5
- Got rid of some annoying bugs
Version 0.1.4
- I can now determine between GIF and JPG!
- I am much faster!
- This version history is also new
Have fun!
*/
$(document).ready( function() {
function NSFWImage(targetContainer, imgUrl) {
targetContainer.removeClass("badge-nsfw-entry-cover");
this.targetContainer = targetContainer;
this.imageUrl = imgUrl;
}
NSFWImage.prototype.imgAppend = function(suffix) {
this.imageUrl = this.imageUrl + suffix;
};
NSFWImage.prototype.applyImageUrl = function() {
this.targetContainer.empty();
var img = document.createElement("img");
img.src = this.imageUrl;
this.targetContainer.append(img);
};
var titties = function(index) {
var targetElement = $(this);
var urlExtract = /[^\/]*\/gag\/(.*)/;
urlExtract.exec(targetElement.attr("href"));
var nsfw = new NSFWImage(targetElement, "http://d24w6bsrhbeh9d.cloudfront.net/photo/" + RegExp.$1);
GM_xmlhttpRequest({
url: nsfw.imageUrl + "_460sa.gif",
method: "GET",
onload: function(response) {
if(response.status !== 404) {
nsfw.imgAppend("_460sa.gif");
}
else {
nsfw.imgAppend("_700b.jpg");
}
nsfw.applyImageUrl();
}
});
};
$("a.badge-nsfw-entry-cover").each(titties);
$("div.badge-entry-collection").bind("DOMSubtreeModified", function() {
$("a.badge-nsfw-entry-cover").each(titties);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment