From 4c6be038659c3286bcd472913fc4a3e6c4364ebf Mon Sep 17 00:00:00 2001 From: Kasen IO Date: Fri, 28 Feb 2020 01:20:21 -0500 Subject: [PATCH] Adds decentralizedGoTo as a default script, adds beta channel as well. --- scripts/communityScripts/decentralizedGoTo.js | 133 ++++++++++++++++++ scripts/defaultScripts.js | 2 + 2 files changed, 135 insertions(+) create mode 100644 scripts/communityScripts/decentralizedGoTo.js diff --git a/scripts/communityScripts/decentralizedGoTo.js b/scripts/communityScripts/decentralizedGoTo.js new file mode 100644 index 0000000000..a526d85866 --- /dev/null +++ b/scripts/communityScripts/decentralizedGoTo.js @@ -0,0 +1,133 @@ +(function () { + var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + Menu.menuItemEvent.connect(onMenuItemEvent); + var AppUi = Script.require('appUi'); + var goToAddresses; + var permission; + Menu.addMenu("GoTo"); + Menu.addMenuItem("GoTo", "Subscribe to new GoTo provider"); + Menu.addMenu("GoTo > Unsubscribe from GoTo provider"); + var goToAddress = Settings.getValue("goToDecentral", ""); + for (var i = 0; i < goToAddress.length; i++) { + Menu.addMenuItem("GoTo > Unsubscribe from GoTo provider", goToAddress[i]); + } + var ui; + function startup() { + goToAddress = Settings.getValue("goToDecentral", ""); + if (goToAddress == "") { + var initialGoToList = Script.resolvePath("goto.json"); + Menu.addMenuItem("GoTo > Unsubscribe from GoTo provider", initialGoToList); + goToAddressNow = [ + initialGoToList + ]; + Settings.setValue("goToDecentral", goToAddressNow); + } + ui = new AppUi({ + buttonName: "Find", + home: Script.resolvePath("decentralizedGoTo.html"), + icon: Script.resolvePath("goto-a.svg"), + activeIcon: Script.resolvePath("goto-a-msg.svg") + }); + } + + function onWebEventReceived(event) { + messageData = JSON.parse(event); + if (messageData.action == "requestAddressList") { + goToAddresses = Settings.getValue("goToDecentral", ""); + for (var i = 0; i < goToAddresses.length; i++) { + + try { + Script.require(goToAddresses[i] + "?" + Date.now()); + } + catch (e) { + goToAddresses.remove(goToAddresses[i]); + } + } + var children = goToAddresses + .map(function (url) { return Script.require(url + '?' + Date.now()); }) + .reduce(function (result, someChildren) { return result.concat(someChildren); }, []); + + for (var z = 0; z < children.length; z++) { + delete children[z].age; + delete children[z].id; + children[z]["Domain Name"] = children[z]["Domain Name"].replace(//g, '<'); + children[z].Owner = children[z].Owner.replace(//g, '<'); + } + + permission = Entities.canRez() + + var readyEvent = { + "action": "addressList", + "myAddress": children, + "permission": permission + }; + + tablet.emitScriptEvent(JSON.stringify(readyEvent)); + + } else if (messageData.action == "goToUrl") { + Window.location = messageData.visit; + } else if (messageData.action == "addLocation") { + + var messageDataDomainInformation = { + owner: messageData.owner, + domainName: messageData.domainName, + port: messageData.Port + }; + + locationboxID = Entities.addEntity({ + position: Vec3.sum(MyAvatar.position, Quat.getFront(MyAvatar.orientation)), + userData: JSON.stringify(messageDataDomainInformation), + serverScripts: messageData.script, + color: { red: 255, green: 0, blue: 0 }, + type: "Box" + }); + } else if (messageData.action == "retrievePortInformation") { + var readyEvent = { + "action": "retrievePortInformationResponse", + "goToAddresses": goToAddresses + }; + + tablet.emitScriptEvent(JSON.stringify(readyEvent)); + + } + } + + function onMenuItemEvent(menuItem) { + if (menuItem == "Subscribe to new GoTo provider") { + goToAddress = Settings.getValue("goToDecentral", ""); + var arrayLength = goToAddress.length; + var prom = Window.prompt("Enter URL to GoTo JSON.", ""); + if (prom) { + goToAddress[arrayLength] = prom; + Settings.setValue("goToDecentral", goToAddress); + Menu.addMenuItem("GoTo > Unsubscribe from GoTo provider", prom); + } + } else { + goToAddresses = Settings.getValue("goToDecentral", ""); + Menu.removeMenuItem("GoTo > Unsubscribe from GoTo provider", menuItem); + goToAddresses.remove(menuItem); + Settings.setValue("goToDecentral", goToAddresses); + } + } + + Array.prototype.remove = function () { + var what, a = arguments, L = a.length, ax; + while (L && this.length) { + what = a[--L]; + while ((ax = this.indexOf(what)) !== -1) { + this.splice(ax, 1); + } + } + return this; + }; + + tablet.webEventReceived.connect(onWebEventReceived); + startup(); + + Script.scriptEnding.connect(function () { + Messages.unsubscribe("goTo"); + Menu.removeMenu("GoTo"); + tablet.webEventReceived.disconnect(onWebEventReceived); + Menu.menuItemEvent.disconnect(onMenuItemEvent); + }); +}()); diff --git a/scripts/defaultScripts.js b/scripts/defaultScripts.js index 7700167d59..a233903a3e 100644 --- a/scripts/defaultScripts.js +++ b/scripts/defaultScripts.js @@ -34,12 +34,14 @@ var DEFAULT_SCRIPTS_COMBINED = [ "system/emote.js", "system/miniTablet.js", "system/audioMuteOverlay.js", + "system/inspect.js", "system/keyboardShortcuts/keyboardShortcuts.js" ]; var DEFAULT_SCRIPTS_SEPARATE = [ "system/controllers/controllerScripts.js", "communityModules/notificationCore/notificationCore.js", "simplifiedUI/ui/simplifiedNametag/simplifiedNametag.js", + {"stable": "communityScripts/decentralizedGoTo/decentralizedGoTo.js", "beta": "https://metaverse.projectathena.io/interim/d-goto/app/decentralizedGoTo.js"}, {"stable": "communityModules/chat/FloofChat.js", "beta": "https://content.fluffy.ws/scripts/chat/FloofChat.js"} //"system/chat.js" ];