diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 6de5bac7..66190b43 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -1052,7 +1052,7 @@ function goto(dest) { clmod(document.documentElement, 'op_open', dest); - if (window['treectl']) + if (treectl) treectl.onscroll(); } @@ -1508,7 +1508,7 @@ var widget = (function () { clmod(document.documentElement, 'np_open', is_open); clmod(widget, 'open', is_open); bcfg_set('au_open', r.is_open = is_open); - if (window.vbar) { + if (vbar) { pbar.onresize(); vbar.onresize(); } @@ -2421,7 +2421,7 @@ function play(tid, is_ev, seek) { clmod(ebi(oid), 'act', 1); clmod(ebi(oid).closest('tr'), 'play', 1); clmod(ebi('wtoggle'), 'np', mpl.clip); - if (window.thegrid) + if (thegrid) thegrid.loadsel(); try { @@ -3392,7 +3392,7 @@ var showfile = (function () { } r.setstyle = function () { - if (window['no_prism']) + if (window.no_prism) return; qsr('#prism_css'); @@ -3521,7 +3521,7 @@ var showfile = (function () { else { el.textContent = txt; el.innerHTML = '' + el.innerHTML + ''; - if (!window['no_prism']) { + if (!window.no_prism) { el.className = 'prism linkable-line-numbers line-numbers language-' + lang; if (!defer) fun(el.firstChild); @@ -3747,7 +3747,7 @@ var thegrid = (function () { ebi('bdoc').style.display = 'none'; clmod(ebi('wrap'), 'doc'); qsr('#docname'); - if (window['treectl']) + if (treectl) treectl.textmode(false); aligngriditems(); @@ -4610,7 +4610,7 @@ document.onkeydown = function (e) { })(); function aligngriditems() { - if (!window.treectl) + if (!treectl) return; var em2px = parseFloat(getComputedStyle(ebi('ggrid')).fontSize); @@ -5496,7 +5496,7 @@ function apply_perms(newperms) { 'table-cell' : 'none'; } - if (window['up2k']) + if (up2k) up2k.set_fsearch(); ebi('widget').style.display = have_read ? '' : 'none'; @@ -5629,7 +5629,7 @@ var filecols = (function () { for (var b = 0, bb = tds.length; b < bb; b++) tds[b].className = cls; } - if (window['tt']) { + if (tt) { tt.att(ebi('hcols')); tt.att(QS('#files>thead')); } @@ -6215,7 +6215,7 @@ function show_md(md, name, div, url, depth) { if (url != now) return; - if (!window['marked']) { + if (!marked) { if (depth) return toast.warn(10, errmsg + 'failed to load marked.js') @@ -6579,7 +6579,7 @@ function reload_browser() { for (var a = 0; a < ns.length; a++) clmod(ebi(ns[a]), 'hidden', ebi('unsearch')); - if (window['up2k']) + if (up2k) up2k.set_fsearch(); thegrid.setdirty(); diff --git a/copyparty/web/md.js b/copyparty/web/md.js index 52adfb43..c0385d5e 100644 --- a/copyparty/web/md.js +++ b/copyparty/web/md.js @@ -498,5 +498,5 @@ dom_navtgl.onclick = function () { if (sread('hidenav') == 1) dom_navtgl.onclick(); -if (window['tt']) +if (window.tt && tt.init) tt.init(); diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index e1c528f0..ac4370cb 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -928,7 +928,7 @@ function up2k_init(subtle) { r.st = st; r.uc = uc; - if (!window.File || !File.prototype.slice || !window.FileReader || !window.FileList) + if (!window.File || !window.FileReader || !window.FileList || !File.prototype || !File.prototype.slice) return un2k(L.u_ever); var flag = false; diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 4d6e6f64..906ffeeb 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -1,12 +1,13 @@ "use strict"; -if (!window['console']) - window['console'] = { +if (!window.console || !console.log) + window.console = { "log": function (msg) { } }; var wah = '', + L, tt, treectl, thegrid, up2k, asmCrypto, hashwasm, vbar, marked, CB = '?_=' + Date.now(), HALFMAX = 8192 * 8192 * 8192 * 8192, HTTPS = (window.location + '').indexOf('https:') === 0, @@ -17,6 +18,15 @@ var wah = '', IPHONE = TOUCH && /iPhone|iPad|iPod/i.test(navigator.userAgent), WINDOWS = navigator.platform ? navigator.platform == 'Win32' : /Windows/.test(navigator.userAgent); +if (!window.WebAssembly || !WebAssembly.Memory) + window.WebAssembly = false; + +if (!window.Notification || !Notification.permission) + window.Notification = false; + +if (!window.FormData) + window.FormData = false; + try { CB = '?' + document.currentScript.src.split('?').pop(); @@ -381,13 +391,14 @@ function clgot(el, cls) { var ANIM = true; -if (window.matchMedia) { +try { var mq = window.matchMedia('(prefers-reduced-motion: reduce)'); mq.onchange = function () { ANIM = !mq.matches; }; ANIM = !mq.matches; } +catch (ex) { } function yscroll() { @@ -747,7 +758,7 @@ function lhumantime(v) { var t = shumantime(v, 1), tp = t.replace(/([a-z])/g, " $1 ").split(/ /g).slice(0, -1); - if (!window.L || tp.length < 2 || tp[1].indexOf('$') + 1) + if (!L || tp.length < 2 || tp[1].indexOf('$') + 1) return t; var ret = ''; @@ -1251,8 +1262,8 @@ var modal = (function () { tok, tng, prim, sec, ok_cancel; r.load = function () { - tok = (window.L && L.m_ok) || 'OK'; - tng = (window.L && L.m_ng) || 'Cancel'; + tok = (L && L.m_ok) || 'OK'; + tng = (L && L.m_ng) || 'Cancel'; prim = '' + tok + ''; sec = '' + tng + ''; ok_cancel = WINDOWS ? prim + sec : sec + prim; @@ -1612,7 +1623,7 @@ function xhrchk(xhr, prefix, e404, lvl, tag) { return true; if (xhr.status == 403) - return toast.err(0, prefix + (window.L && L.xhr403 || "403: access denied\n\ntry pressing F5, maybe you got logged out"), tag); + return toast.err(0, prefix + (L && L.xhr403 || "403: access denied\n\ntry pressing F5, maybe you got logged out"), tag); if (xhr.status == 404) return toast.err(0, prefix + e404, tag);