diff --git a/www/js/data.js b/www/js/data.js index 348a9cb6..73e614d0 100644 --- a/www/js/data.js +++ b/www/js/data.js @@ -168,6 +168,16 @@ var NO_WEBSOCKETS = USEROPTS.altsocket; var NO_VIMEO = Boolean(location.host.match("cytu.be")); var JSPREF = getOpt("channel_js_pref") || {}; +// Dunno why this happens +if (typeof JSPREF !== "object" || JSPREF === null) { + try { + JSPREF = JSON.parse(JSPREF); + } catch (e) { + console.error("JSPREF is bugged: " + e + " (" + JSPREF + ")"); + JSPREF = {}; + setOpt("channel_js_pref", JSPREF); + } +} var Rank = { Guest: 0, diff --git a/www/js/util.js b/www/js/util.js index 8a526ddd..198a4bae 100644 --- a/www/js/util.js +++ b/www/js/util.js @@ -2826,15 +2826,30 @@ function formatScriptAccessPrefs() { var channels = Object.keys(JSPREF).sort(); channels.forEach(function (channel) { - var parts = channel.split("_"); - if (!parts[1].match(/^(external|embedded)$/)) { + var idx = String(channel).lastIndexOf("_"); + if (idx < 0) { + // Invalid + console.error("Channel JS pref: invalid key '" + channel + "', deleting it"); + delete JSPREF[channel]; + setOpt("channel_js_pref", JSPREF); + return; + } + + var channelName = channel.substring(0, idx); + var prefType = channel.substring(idx + 1); + console.log(channelName, prefType); + if (prefType !== "external" && prefType !== "embedded") { + // Invalid + console.error("Channel JS pref: invalid key '" + channel + "', deleting it"); + delete JSPREF[channel]; + setOpt("channel_js_pref", JSPREF); return; } var pref = JSPREF[channel]; var tr = $("").appendTo(tbl); - $("").text(parts[0]).appendTo(tr); - $("").text(parts[1]).appendTo(tr); + $("").text(channelName).appendTo(tr); + $("").text(prefType).appendTo(tr); var pref_td = $("").appendTo(tr); var allow_label = $("