Skip to content

Instantly share code, notes, and snippets.

@JRobH
Created May 21, 2015 06:59
Show Gist options
  • Save JRobH/818103d83d0b43c7492f to your computer and use it in GitHub Desktop.
Save JRobH/818103d83d0b43c7492f to your computer and use it in GitHub Desktop.
// ==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);
}
@pacojr2003
Copy link

Hye

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment