Last active
June 25, 2021 08:06
-
-
Save nfreear/6dc7a3c35baab24238ba81b5e035fe89 to your computer and use it in GitHub Desktop.
Javascript to inject a Bot in an <iframe> into the nQuire mission builder | https://nquire.org.uk/
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
| /** | |
| Javascript to inject a Bot in an <iframe> into the nQuire mission builder. | |
| @author NDF, 24-June-2021 | |
| @see https://nquire.org.uk/mission-builder/ | |
| @see https://tinymce.github.io/tinymce-demos/email/webmail-rich-text-editor.html | |
| javascript:(() => { | |
| //. | |
| })(); | |
| */ | |
| (() => { | |
| const SELECTOR = '#bot-iframe-1'; | |
| const BOT_URL = 'https://nfreear.github.io/demo-bot/?embed=true&userID=[RESPONSE_ID]'; | |
| const PARENT_URL_REGEX = /https:\/\/(\w\.)?nquire.org.uk\/mission-builder\/\w+/; | |
| const $ELEM = document.querySelector(SELECTOR); | |
| const HTML = `<iframe | |
| aria-label="Try the Chat Bot." | |
| src="${BOT_URL}&zz" | |
| style="border:1px solid #ddd; height:20rem; width:100%; min-width:32rem;" | |
| ><iframe>`; | |
| if (!PARENT_URL_REGEX.test(window.location.href)) { | |
| console.warn('Caution! Not the mission-builder editor?'); | |
| } | |
| console.debug('Injecting Chat-Bot ...:', BOT_URL, $ELEM); | |
| $ELEM.innerHTML = HTML; | |
| })(); | |
| /* | |
| document.querySelector('#bot-iframe-1').innerHTML = | |
| `<iframe | |
| aria-label="Demo-Bot" | |
| src="https://nfreear.github.io/demo-bot/?embed=true&userID=abc-123&" | |
| style="border:1px solid #ddd; height:20rem; width:100%; min-width:32rem;" | |
| ><iframe>`; | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment