fix url params reading in OBS browser plugin

This commit is contained in:
e7d 2020-11-11 11:02:02 +01:00
parent 54de87514d
commit d0c08a8b0f
2 changed files with 27 additions and 21 deletions

View File

@ -5,17 +5,6 @@ body {
overflow: hidden; overflow: hidden;
} }
#debug {
color: red;
display: none;
font-size: 60px;
line-height: 80px;
position: absolute;
text-align: center;
top: 0;
width: 100vw;
}
.instructions { .instructions {
height: 100vh; height: 100vh;
line-height: 2em; line-height: 2em;

View File

@ -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}<br>${error.stack}`;
$console.appendChild(p);
};
/** /**
* The main Gamepad class * The main Gamepad class
* *
@ -547,7 +554,8 @@ class Gamepad {
const activeGamepad = this.getActive(); const activeGamepad = this.getActive();
// check for actual gamepad update // check for actual gamepad update
if (!activeGamepad || activeGamepad.timestamp === this.lastTimestamp) return; if (!activeGamepad || activeGamepad.timestamp === this.lastTimestamp)
return;
this.lastTimestamp = activeGamepad.timestamp; this.lastTimestamp = activeGamepad.timestamp;
// actually update the active gamepad graphically // 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 * Update url hash with new settings
*
* @param {*} newSettings * @param {*} newSettings
*/ */
updateSettings(newSettings) { updateSettings(newSettings) {
const settings = Object.assign( const settings = Object.assign(this.getUrlSettings(), newSettings);
Object.fromEntries(
window.location.search
.replace("?", "")
.split("&")
.map((param) => param.split("="))
),
newSettings
);
const query = Object.entries(settings) const query = Object.entries(settings)
.filter(([, value]) => value !== undefined) .filter(([, value]) => value !== undefined)
.map(([key, value]) => `${key}=${value}`) .map(([key, value]) => `${key}=${value}`)