Last active
August 29, 2015 14:12
-
-
Save chrahunt/ddac0ebb237215c21d31 to your computer and use it in GitHub Desktop.
UserScript for jsoneditoronline.org for use when editing the JSON of TagPro maps. The UserScript adds a "Fix Portals" button to the JSON editor that edits the json in the editor so the cooldown of all portals is zero.
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 0 Portal Cooldown for JSON Editor Online | |
// @namespace http://www.reddit.com/user/snaps_ | |
// @version 0.1 | |
// @description Add a button for automatically setting portal cooldowns to 0 in JSON Editor Online. | |
// @author snaps_ | |
// @match https://*.jsoneditoronline.org/ | |
// @match http://*.jsoneditoronline.org/ | |
// @grant none | |
// @run-at document-end | |
// ==/UserScript== | |
/* | |
* We use two JSON editor online global objects below, `app` and `codeEditor`. | |
* codeEditor is of type JSONEditor, which can be inspected on the page, and | |
* app is just an object with various utility methods. | |
*/ | |
// Create and style button to be added to editor. | |
var button = document.createElement("button"); | |
button.title = "Set cooldown to 0 for all portals"; | |
button.textContent = "Fix Portals"; | |
button.style.width = "auto"; | |
button.style.background = "none"; | |
button.style.padding = "0px 5px"; | |
button.style["background-color"] = "rgb(224, 231, 245)"; | |
button.style["font-weight"] = "bold"; | |
// Add button to editor. | |
var codeMenuLink = document.querySelector("#codeEditor .menu a"); | |
var codeMenu = document.querySelector("#codeEditor .menu"); | |
codeMenu.insertBefore(button, codeMenuLink); | |
// Set portal cooldpwns to 0 on button click. | |
button.addEventListener("click", function(e) { | |
try { | |
var json = codeEditor.get(); | |
if (json.portals) { | |
// Set portal cooldowns to 0. | |
for (var loc in json.portals) { | |
json.portals[loc].cooldown = 0; | |
} | |
} | |
codeEditor.set(json); | |
codeEditor.compact(); | |
} catch (e) { | |
// JSON not parsed correctly, pass error through normal notification method. | |
app.notify.showError(app.formatError(e)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment