Created
April 13, 2016 09:54
-
-
Save dafrancis/2b48e09d385c304f6bc9243c410e5d32 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
// ==UserScript== | |
// @name Fuck Aggro Gator | |
// @namespace http://somethingafal.com | |
// @version 0.1 | |
// @description FUCK AGGRO GATOR | |
// @author Afal | |
// @match http://forums.somethingawful.com/* | |
// @grant none | |
// ==/UserScript== | |
/* jshint -W097 */ | |
'use strict'; | |
// Your code here... | |
var shorteners = ["j.mp", "bit.ly", "u.to", "bit.do", "bitly.com", "goo.gl", "tr.im"]; | |
var good_ads = []; | |
function uses_shortener(ad) { | |
var i = 0; | |
for (;i < shorteners.length; i++) { | |
if (ad.href.indexOf(shorteners[i]) !== -1) { | |
return true; | |
} | |
} | |
return false; | |
} | |
function ad_safety(ad) { | |
var safety = "POSSIBLY UNSAFE"; | |
if (ad.href.indexOf("aggro-gator.com") !== -1) { | |
safety = "UNSAFE"; | |
} else if (!uses_shortener(ad)) { | |
safety = "PROBABLY COMPLETELY SAFE"; | |
} | |
return safety; | |
} | |
function get_safe_ads() { | |
$.ajax({ | |
type: "GET", | |
url: "http://forums.somethingawful.com/adlist.php", | |
dataType: 'html', | |
success: function(response) { | |
var adlist = $(response).find("#adlist")[0]; | |
[].forEach.call(adlist.children, function (ad) { | |
if (ad_safety(ad.children[0]) === "PROBABLY COMPLETELY SAFE") { | |
good_ads.push(ad.children[0]); | |
} | |
}); | |
make_ad_safe(); | |
} | |
}); | |
} | |
function make_ad_safe() { | |
var ad = document.getElementById("ad_banner_user"); | |
var good_ad = good_ads[Math.floor(Math.random() * good_ads.length)]; | |
if (ad) { | |
ad = ad.children[0]; | |
} | |
/* | |
if (ad) { | |
ad.onclick = function () { | |
var warning = "Are you sure you want to click on this ad? It might be Aggro Gator.\n\n"; | |
var safety = ad_safety(ad); | |
warning += "The site it redirects to is " + ad.href; | |
warning += "\n\nMaking this site " + safety; | |
return confirm(warning); | |
}; | |
} | |
*/ | |
if (ad) { | |
ad.href = good_ad.href; | |
ad.children[0].src = good_ad.children[0].src; | |
} | |
} | |
function main() { | |
get_safe_ads(); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment