Created
March 23, 2018 12:57
Star
You must be signed in to star a gist
TamperMonkey script to add variable access to FeatherTest
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 FeatherTest Variable Support | |
// @namespace http://mysite | |
// @include http*://mysite/* | |
// @description Add support for FeatherTest variable access. Matt Collinge. | |
// @version 1.0 | |
// @grant all | |
// ==/UserScript== | |
function featherTestSupport() { | |
if (typeof(window.addEventListener)!='undefined') window.addEventListener('message',function(event) { | |
// Make sure the request is coming from our own site (or FeatherTest) | |
if (event.origin !== window.origin) return; | |
if (typeof(event.data.action)=='undefined') return; | |
// Instead, I used this from StackOverflow; https://stackoverflow.com/questions/11924731/get-object-by-name-as-string-without-eval | |
if (event.data.action=='variable') { | |
var variableValue = event.data.value.split('.').reduce(function (object, property) { | |
return object[property]; | |
}, unsafeWindow); | |
console.log('%c'+event.data.value+' = '+variableValue, 'color:orange'); | |
} | |
},false); | |
} | |
featherTestSupport(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment