From 6feb7324671572c2608b383a087607a506060311 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Mon, 15 Sep 2014 21:30:19 +0200 Subject: [PATCH] load a javascript from a message when the user agrees --- examples/loadScriptFromMessage.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 examples/loadScriptFromMessage.js diff --git a/examples/loadScriptFromMessage.js b/examples/loadScriptFromMessage.js new file mode 100644 index 0000000000..c9d067cc3b --- /dev/null +++ b/examples/loadScriptFromMessage.js @@ -0,0 +1,27 @@ +// +// loadScriptFromMessage.js +// examples +// +// Created by Thijs Wenker on 9/15/14. +// Copyright 2014 High Fidelity, Inc. +// +// Filters script links out of incomming messages and prompts you to run the script. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +//Javascript link RegEX +const JS_LINK_REGEX = /https?:\/\/[^ ]+\.js/i; + +function onIncomingMessage(user, message) { + var script_link = JS_LINK_REGEX.exec(message); + if (script_link == null) { + return; + } + if (Window.confirm("@" + user + " sent the following script:\n" + script_link + "\nwould you like to run it?")) { + Script.load(script_link); + } +} + +GlobalServices.incomingMessage.connect(onIncomingMessage); \ No newline at end of file