Last active
July 5, 2019 17:24
-
-
Save joelacummings/294dfcdff998b7da94ecd41b641db7ad 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
(function(){ | |
var base = "https://data.schemaapp.com/" + __schemaConfig.accountId + "/"; | |
var url = __schemaConfig.strip_query ? btoa(unescape(window.location.href.replace(window.location.search, ""))).replace(/=/g, "") : btoa(unescape(window.location.href)).replace(/=/g, ""); | |
var xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function() { | |
if (xhr.readyState === 4 && xhr.status === 200) { | |
if (xhr.responseText !== "") { | |
var ld = document.createElement('script'); | |
ld.type = "application/ld+json"; | |
ld.innerHTML = xhr.responseText; | |
document.getElementsByTagName('head')[0].appendChild(ld); | |
} | |
} | |
} | |
xhr.open("GET", base + url, true); | |
xhr.setRequestHeader("x-api-key", __schemaConfig.apiKey); | |
xhr.send(); | |
})(); |
Author
joelacummings
commented
Jul 5, 2019
I did something similar to this as a toy app last year. Sent you an invite as a collaborator if you'd like to inspect the code.
https://github.com/JohnM-729/foldout
It's a proof-of-concept that will remote load and invoke a vue app on a page when the user presses alt-shift-f.
Basically a similar approach to what you've got here, create a script node, set the source, and insert it, with the added frills of an event listener and interval to make sure that the vue library from cdn is loaded before invoking the app.
- What you've got above look like it should work fine, however, I would replace the deprecated
unescape
function with decodeURI.
Also, don't forget that you can use eval() if you need to run a string as if it were JS code, if all else fails and you just want to run something and damn the torpedoes...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment