(function() { // sets unique window for avoiding js conflicts var trueName = ''; for (var i = 0; i < 16; i++) { // generates a unique number trueName += String.fromCharCode(Math.floor(Math.random() * 26) + 97); } window[trueName] = {}; var $ = window[trueName]; // functions $.f = (function() { return { init: function(target) { var theScripts = document.getElementsByTagName('SCRIPT'); for (var i = 0; i < theScripts.length; i++) { if (theScripts[i].src.match(target)) { $.q = theScripts[i].src.replace(/^[^\?]+\??/, ''); $.w = document.createElement('DIV'); $.a = {}; $.f.getJSON('//aspgear.com/aspbadges/aspbadges.json'); // splits value from size $.s = $.q.split('='); if ($.f.checkDomain(resp.domains, window.location.hostname)) { $.w.innerHTML = '
\
\ ' + resp.tooltiptitle + '\
' + resp.tooltiptitle + '
' + resp.tooltiptext + '
\
\
'; theScripts[i].parentNode.insertBefore($.w, theScripts[i]); theScripts[i].parentNode.removeChild(theScripts[i]); } else { console.log('ASP Badge: Domain not allowed'); } break; } } if (!$.f.runFunction) { $.f.runFunction = []; } }, getJSON: function(url) { resp = ''; xmlHttp = new XMLHttpRequest(); if (xmlHttp != null) { xmlHttp.open('GET', url, false); xmlHttp.send(); resp = xmlHttp.responseText; } // makes string an object resp = JSON.parse(resp); return resp; }, checkDomain: function(domains, domain) { for (var i = 0; i < domains.length; i++) { if (domains[i] === domain) { return true; } } return false; } }; })(); var thisScript = /aspbadge/; document.addEventListener('DOMContentLoaded', function() { $.f.init(thisScript); }); })();