Last active
August 29, 2015 14:14
-
-
Save adrianiainlam/c382e9f971ed73262d6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!