diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 310db30e..af1be68e 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -311,7 +311,7 @@ def disable_quickedit() -> None: cmode(True, mode | 4) -def run_argparse(argv: list[str], formatter: Any) -> argparse.Namespace: +def run_argparse(argv: list[str], formatter: Any, retry: bool) -> argparse.Namespace: ap = argparse.ArgumentParser( formatter_class=formatter, prog="copyparty", @@ -611,6 +611,7 @@ def run_argparse(argv: list[str], formatter: Any) -> argparse.Namespace: ap2.add_argument("--lang", metavar="LANG", type=u, default="eng", help="language") ap2.add_argument("--theme", metavar="NUM", type=int, default=0, help="default theme to use") ap2.add_argument("--themes", metavar="NUM", type=int, default=8, help="number of themes installed") + ap2.add_argument("--favico", metavar="TXT", type=u, default="c 000 none" if retry else "🎉 000 none", help="favicon text [ foreground [ background ] ], set blank to disable") ap2.add_argument("--js-browser", metavar="L", type=u, help="URL to additional JS to include") ap2.add_argument("--css-browser", metavar="L", type=u, help="URL to additional CSS to include") ap2.add_argument("--html-head", metavar="TXT", type=u, default="", help="text to append to the of all HTML pages") @@ -682,12 +683,14 @@ def main(argv: Optional[list[str]] = None) -> None: except: pass - for fmtr in [RiceFormatter, Dodge11874, BasicDodge11874]: + retry = False + for fmtr in [RiceFormatter, RiceFormatter, Dodge11874, BasicDodge11874]: try: - al = run_argparse(argv, fmtr) + al = run_argparse(argv, fmtr, retry) except SystemExit: raise except: + retry = True lprint("\n[ {} ]:\n{}\n".format(fmtr, min_ex())) assert al diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 19e2cf5e..094c1186 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -184,6 +184,8 @@ class HttpCli(object): def j2s(self, name: str, **ka: Any) -> str: tpl = self.conn.hsrv.j2[name] ka["ts"] = self.conn.hsrv.cachebuster() + ka["lang"] = self.args.lang + ka["favico"] = self.args.favico ka["svcname"] = self.args.doctitle ka["html_head"] = self.html_head return tpl.render(**ka) # type: ignore @@ -1862,6 +1864,8 @@ class HttpCli(object): "edit": "edit" in self.uparam, "title": html_escape(self.vpath, crlf=True), "lastmod": int(ts_md * 1000), + "lang": self.args.lang, + "favico": self.args.favico, "have_emp": self.args.emp, "md_chk_rate": self.args.mcr, "md": boundary, @@ -2406,7 +2410,6 @@ class HttpCli(object): "readme": readme, "title": html_escape(self.vpath, crlf=True), "srv_info": srv_infot, - "lang": self.args.lang, "dtheme": self.args.theme, "themes": self.args.themes, "turbolvl": self.args.turbo, diff --git a/copyparty/web/browser.html b/copyparty/web/browser.html index 0c5655b6..e082a8b2 100644 --- a/copyparty/web/browser.html +++ b/copyparty/web/browser.html @@ -3,7 +3,7 @@ - ⇆🎉 {{ title }} + {{ title }} {{ html_head }} @@ -139,6 +139,7 @@ dtheme = "{{ dtheme }}", srvinf = "{{ srv_info }}", lang = "{{ lang }}", + dfavico = "{{ favico }}", def_hcols = {{ def_hcols|tojson }}, have_up2k_idx = {{ have_up2k_idx|tojson }}, have_tags_idx = {{ have_tags_idx|tojson }}, diff --git a/copyparty/web/md.html b/copyparty/web/md.html index 59268d82..f99641b4 100644 --- a/copyparty/web/md.html +++ b/copyparty/web/md.html @@ -1,6 +1,6 @@ - 📝🎉 {{ title }} + 📝 {{ title }} {{ html_head }} @@ -128,7 +128,8 @@ write markdown (most html is 🙆 too) diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index 71d9ee3e..2fdc1971 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -2139,8 +2139,8 @@ favico.init(); ebi('ico1').onclick = function () { var a = favico.txt == this.textContent; swrite('icot', a ? 'c' : this.textContent); - swrite('icof', a ? null : '000'); - swrite('icob', a ? null : ''); + swrite('icof', a ? 'fc5' : '000'); + swrite('icob', a ? '222' : ''); favico.init(); }; diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 4cf82a8d..9ec0bfd0 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -1427,12 +1427,24 @@ var favico = (function () { var b64; try { b64 = btoa(svg ? svg_decl + svg : gx(r.txt)); + //console.log('f1'); } - catch (ex) { - b64 = encodeURIComponent(r.txt).replace(/%([0-9A-F]{2})/g, - function x(m, v) { return String.fromCharCode('0x' + v); }); - - b64 = btoa(gx(unescape(encodeURIComponent(r.txt)))); + catch (e1) { + try { + b64 = btoa(gx(encodeURIComponent(r.txt).replace(/%([0-9A-F]{2})/g, + function x(m, v) { return String.fromCharCode('0x' + v); }))); + //console.log('f2'); + } + catch (e2) { + try { + b64 = btoa(gx(unescape(encodeURIComponent(r.txt)))); + //console.log('f3'); + } + catch (e3) { + //console.log('fe'); + return; + } + } } if (!r.tag) { @@ -1445,9 +1457,13 @@ var favico = (function () { r.init = function () { clearTimeout(r.to); - scfg_bind(r, 'txt', 'icot', '', r.upd); - scfg_bind(r, 'fg', 'icof', 'fc5', r.upd); - scfg_bind(r, 'bg', 'icob', '222', r.upd); + var dv = (window.dfavico || '').trim().split(/ +/), + fg = dv.length < 2 ? 'fc5' : dv[1].toLowerCase() == 'none' ? '' : dv[1], + bg = dv.length < 3 ? '222' : dv[2].toLowerCase() == 'none' ? '' : dv[2]; + + scfg_bind(r, 'txt', 'icot', dv[0], r.upd); + scfg_bind(r, 'fg', 'icof', fg, r.upd); + scfg_bind(r, 'bg', 'icob', bg, r.upd); r.upd(); };