Created
January 26, 2017 05:58
-
-
Save rdnelson/dd1ad0e69121afedb2d8c8400e5b4121 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 Fate Roll Improver | |
// @namespace https://rnelson.ca | |
// @version 0.1 | |
// @description Replace the dresden fate skill text boxes with per skill buttons. | |
// @author Robert Nelson | |
// @match https://app.roll20.net/editor/* | |
// @match http://app.roll20.net/editor/* | |
// @grant none | |
// @run-at document-body | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
console.log(window.d20ext); | |
window.d20ext.environment = "development"; | |
// Your code here... | |
var timer = setInterval(function(e) { | |
console.log("Attempting roller function injection."); | |
if (d20.Campaign === undefined) { | |
console.warn("Campaign not loaded. Delaying injection."); | |
return; | |
} | |
var models = d20.Campaign.characters.models; | |
if (models.length === 0) { | |
console.warn("Characters not loaded. Delaying injection."); | |
return; | |
} | |
clearInterval(timer); | |
for(var i = 0; i < models.length; i++) { | |
console.log("Injecting into character: " + models[i].attributes.name); | |
models[i].view.updateSheetValues = function(e, view, oldFunc) { | |
return function injected_updateSheetValues(e) { | |
console.log("Running standard function."); | |
oldFunc(e); | |
setTimeout(function() { | |
console.log("Removing normal roll buttons."); | |
$('button[name*="roll"]', view.$charsheet).remove(); | |
console.log("Injecting elements."); | |
var skills = $('div[class="repitem"]>input[name^="attr"][name$="skill"]', view.$charsheet); | |
skills.after(function() { | |
var levelRegex = /attr_(.+)-skill/; | |
var match = levelRegex.exec(this.name); | |
if (match === null) { | |
return; | |
} | |
var level = match[1]; | |
return '<button type="roll" name="roll_' + level + '" value="&{template:' + level + '} {{roll=' + this.value + ': [[4df+5+?{Bonus|0}]]}}" class="btn ui-draggable">' + this.value + '</button>'; | |
}); | |
skills.remove(); | |
}, 200); | |
}; | |
}(e, models[i].view, models[i].view.updateSheetValues); | |
} | |
}, 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment