-
-
Save Dbof/94ec90c3a5aef25afe4f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ==UserScript== | |
// @name 9GAG NSFW picture peeker | |
// @include http://9gag.com/* | |
// @include https://9gag.com/* | |
// @version 0.1.11 | |
// @description 9GAG NSFW peeker | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.js | |
// @author Dbof, Error418 | |
// @grant GM.xmlHttpRequest | |
// ==/UserScript== | |
/* Change log: | |
Version 0.1.11 | |
- 9gag changed its elements and removed *badge* elements, which actually made the detection on the NSFW page easier. | |
- remove onclick event by removing <a> element. | |
Version 0.1.10 | |
If URL can not be retrieved, try again with window.location.href. | |
Version 0.1.9 | |
Adapt to newest Greasemonkey API: https://wiki.greasespot.net/GM.xmlHttpRequest | |
Version 0.1.8 | |
Remove gifs and add mp4s. | |
Version 0.1.7 | |
9gag added ?sc=nsfw to the url path...so script was adapted. | |
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, videoid) { | |
this.targetContainer = targetContainer; | |
this.imageUrl = imgUrl; | |
this.videoid = 'video' + videoid; | |
} | |
NSFWImage.prototype.imgAppend = function (suffix) { | |
this.imageUrl = this.imageUrl + suffix; | |
}; | |
NSFWImage.prototype.applyImageUrl = function () { | |
this.targetContainer.empty(); | |
if (this.imageUrl.endsWith('.mp4')) { | |
var video = document.createElement('video'); | |
video.id = this.videoid; | |
video.controls = true; | |
video.preload = 'auto'; | |
video.loop = false; | |
video.muted = false; | |
var source = document.createElement('source'); | |
source.src = this.imageUrl; | |
source.type = "video/mp4"; | |
$(video).width("500px"); | |
video.append(source); | |
this.targetContainer.append(video); | |
} else { | |
var img = document.createElement('img'); | |
img.src = this.imageUrl; | |
$(img).width("500px"); | |
this.targetContainer.append(img); | |
} | |
}; | |
var titties = function (index) { | |
var targetElement = $(this); | |
targetElement.removeClass('nsfw-post'); | |
var article = targetElement.parents().eq(3); | |
var id_split = article.attr('id').split('-'); | |
var urlId = id_split[id_split.length - 1]; | |
if (urlId === null || urlId === undefined) { | |
// try to get it from the URL | |
var urlExtract = /[^\/]*\/gag\/([^\?]*)/; | |
urlId = urlExtract.exec(window.location.href)[1]; | |
} | |
var newDiv = $(document.createElement('div')); | |
newDiv.css("display", "block"); | |
newDiv.css("border", "0px"); | |
targetElement.unwrap('a'); | |
targetElement.parent().append(newDiv); | |
targetElement.remove(); | |
var nsfw = new NSFWImage(newDiv, 'https://img-9gag-fun.9cache.com/photo/' + urlId, index); | |
GM.xmlHttpRequest({ | |
binary: true, | |
timeout: 15000, | |
url: nsfw.imageUrl + '_460sv.mp4', | |
method: 'GET', | |
onload: function (response) { | |
if (response.status !== 404) { | |
nsfw.imgAppend('_460sv.mp4'); | |
} | |
else { | |
nsfw.imgAppend('_700b.jpg'); | |
} | |
nsfw.applyImageUrl(); | |
} | |
}); | |
}; | |
$('.nsfw-post').each(titties); | |
$('#list-view-2').bind('DOMSubtreeModified', function () { | |
$('.nsfw-post').each(titties); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment