From d0c08a8b0f77c3d8a72f9a26ffcdd195f2ab3397 Mon Sep 17 00:00:00 2001 From: e7d Date: Wed, 11 Nov 2020 11:02:02 +0100 Subject: [PATCH] fix url params reading in OBS browser plugin --- css/main.css | 11 ----------- js/gamepad.js | 37 +++++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/css/main.css b/css/main.css index 56f5c10..b2a3284 100644 --- a/css/main.css +++ b/css/main.css @@ -5,17 +5,6 @@ body { overflow: hidden; } -#debug { - color: red; - display: none; - font-size: 60px; - line-height: 80px; - position: absolute; - text-align: center; - top: 0; - width: 100vw; -} - .instructions { height: 100vh; line-height: 2em; diff --git a/js/gamepad.js b/js/gamepad.js index 191008d..855c0e4 100644 --- a/js/gamepad.js +++ b/js/gamepad.js @@ -1,3 +1,10 @@ +$console = document.querySelector("#console"); +window.onerror = function (event, source, lineno, colno, error) { + var p = document.createElement("p"); + p.innerHTML = `${source}:${lineno}:${colno}: ${error.message}
${error.stack}`; + $console.appendChild(p); +}; + /** * The main Gamepad class * @@ -547,7 +554,8 @@ class Gamepad { const activeGamepad = this.getActive(); // check for actual gamepad update - if (!activeGamepad || activeGamepad.timestamp === this.lastTimestamp) return; + if (!activeGamepad || activeGamepad.timestamp === this.lastTimestamp) + return; this.lastTimestamp = activeGamepad.timestamp; // actually update the active gamepad graphically @@ -874,20 +882,29 @@ class Gamepad { }); } + /** + * Read url settings to produce a key/value object + */ + getUrlSettings() { + const settingsArr = window.location.search + .replace("?", "") + .split("&") + .map((param) => param.split("=")); + const settings = {}; + Object.keys(settingsArr).forEach((key) => { + const [k, v] = settingsArr[key]; + settings[k] = v; + }); + return settings; + } + /** * Update url hash with new settings + * * @param {*} newSettings */ updateSettings(newSettings) { - const settings = Object.assign( - Object.fromEntries( - window.location.search - .replace("?", "") - .split("&") - .map((param) => param.split("=")) - ), - newSettings - ); + const settings = Object.assign(this.getUrlSettings(), newSettings); const query = Object.entries(settings) .filter(([, value]) => value !== undefined) .map(([key, value]) => `${key}=${value}`)