Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/* 9gag NSFW loader - Loads 9gag NSFW posts without login
*
* Copyright (c) 2015 Adrian Iain Lam <adrianiainlam@gmail.com>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* A copy of the GNU General Public License can be viewed at
* <https://www.gnu.org/licenses/gpl-3.0.txt>.
*/
// ==UserScript==
// @name 9gag NSFW loader
// @namespace https://github.com/adrianiainlam
// @description Loads 9gag NSFW posts without login
// @include http://9gag.com/*
// @version 1.0.1
// @downloadURL https://gist.githubusercontent.com/adrianiainlam/c382e9f971ed73262d6e/raw/9gag_NSFW_loader.user.js
// @updateURL https://gist.githubusercontent.com/adrianiainlam/c382e9f971ed73262d6e/raw/9gag_NSFW_loader.user.js
// @grant none
// ==/UserScript==
var baseurl = "http://img-9gag-ftw.9cache.com/photo/";
var jpgend = "_700b.jpg";
var gifend = "_460sa.gif";
function getImg(obj, postCode) {
var img = document.createElement("img");
img.onerror = function() {
img.src = baseurl + postCode + jpgend;
};
img.src = baseurl + postCode + gifend;
obj.innerHTML = "";
obj.appendChild(img);
}
var scriptNode = document.createElement("script");
scriptNode.textContent = getImg.toString();
document.head.appendChild(scriptNode);
if(document.URL.indexOf("/gag/") >= 0) {
var url = document.URL.split('/');
var postCode = url[url.length - 1].split('?')[0];
var obj = document.getElementsByClassName("badge-nsfw-entry-cover")[0];
if(obj) {
getImg(obj, postCode);
}
} else {
document.addEventListener("scroll", function() {
var posts = document.getElementsByClassName("badge-evt badge-nsfw-entry-cover");
for(var i=0; i<posts.length; i++) {
var obj = posts[i];
obj.className = "";
var postCode = obj.parentNode.parentNode.getAttribute("data-entry-id");
getImg(obj, postCode);
}
});
}
@LoveIsGrief

This comment has been minimized.

Copy link

LoveIsGrief commented Mar 29, 2015

Don't know if you still maintain this, but the nsfw-class is now called "nsfw-post" and in your final 'if' a obj.className = "" would also be necessary because of the fixed CSS height attribute.

Cheers for the code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.