From f041f2265a222def88fc3e4a08d632df41b4384a Mon Sep 17 00:00:00 2001 From: tophf Date: Wed, 19 Jan 2022 22:19:50 +0300 Subject: [PATCH] fix $ for detached nodes --- edit/settings.js | 2 +- install-usercss/install-usercss.js | 2 +- js/dom.js | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/edit/settings.js b/edit/settings.js index 6e6d0b9a..e1264f11 100644 --- a/edit/settings.js +++ b/edit/settings.js @@ -13,7 +13,7 @@ async function StyleSettings() { await t.fetchTemplate('/edit/settings.html', SS_ID); const {style} = editor; const ui = t.template[SS_ID].cloneNode(true); - const elAuto = $('[id="config.autosave"]', ui); + const elAuto = $('#config\\.autosave', ui); const elSave = $('#ss-save', ui); const pendingSetters = new Map(); const updaters = [ diff --git a/install-usercss/install-usercss.js b/install-usercss/install-usercss.js index 793bf07e..a121b681 100644 --- a/install-usercss/install-usercss.js +++ b/install-usercss/install-usercss.js @@ -67,7 +67,7 @@ setTimeout(() => !cm && showSpinner($('#header')), 200); ({tabId, initialUrl} = preinit); liveReload = initLiveReload(); - preinit.tpl.then(el => $('#ss-scheme').append(...$('[id=ss-scheme]', el).children)); + preinit.tpl.then(el => $('#ss-scheme').append(...$('#ss-scheme', el).children)); const [ {dup, style, error, sourceCode}, diff --git a/js/dom.js b/js/dom.js index a650a387..9d7671b5 100644 --- a/js/dom.js +++ b/js/dom.js @@ -64,11 +64,11 @@ window.messageBoxProxy = new Proxy({}, { }, }); -function $(selector, base = document) { +function $(selector, base) { // we have ids with . like #manage.onlyEnabled which looks like #id.class // so since getElementById is superfast we'll try it anyway - const byId = selector.startsWith('#') && document.getElementById(selector.slice(1)); - return byId || base.querySelector(selector); + const byId = !base && selector.startsWith('#') && document.getElementById(selector.slice(1)); + return byId || (base || document).querySelector(selector); } function $$(selector, base = document) {