Created
May 21, 2015 06:59
-
-
Save JRobH/818103d83d0b43c7492f 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 Agar.io Expose Cells | |
// @match http://agar.io/ | |
// @run-at document-start | |
// @grant none | |
// ==/UserScript== | |
var observer = new MutationObserver(function(mutations) { | |
for (var i = 0; i < mutations.length; i++) { | |
if (/^http:\/\/agar\.io\/main_out\.js/.test(mutations[i].addedNodes[0].src)) { | |
document.head.removeChild(mutations[i].addedNodes[0]); | |
observer.disconnect(); | |
break; | |
} | |
} | |
}); | |
observer.observe(document.head, {childList: true}); | |
var request = new XMLHttpRequest(); | |
request.onload = function() { | |
handleResponse(this.responseText); | |
}; | |
request.onerror = function() { | |
console.log("Response was null"); | |
}; | |
request.open("get", "http://agar.io/main_out.js", true); | |
request.send(); | |
function handleResponse(response) { | |
var cutStrings = response.match(/(\w+)\.push\(this\);/); | |
var split = response.split(cutStrings[0]); | |
response = split[0] + cutStrings[0] + "window.agarCells=" + cutStrings[1] + ";" + split[1]; | |
var script = document.createElement("script"); | |
script.innerHTML = response; | |
insertScript(script); | |
} | |
function insertScript(script) { | |
if (typeof jQuery === "undefined") { | |
return setTimeout(insertScript, 0, script); | |
} | |
window.agarCells = []; | |
document.head.appendChild(script); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hye