summaryrefslogtreecommitdiff
path: root/extension/background.js
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2021-09-12 21:29:11 -0700
committerOmar Rizwan <omar@omar.website>2021-09-12 21:29:11 -0700
commitb8258aaa019de66081444dedd3c6020f53a5296f (patch)
tree9d500d0c707052a82ef81d4315acfbfba51b21b8 /extension/background.js
parentd07c99e701b370ae0b6a1d3af834168072e2273e (diff)
downloadTabFS-b8258aaa019de66081444dedd3c6020f53a5296f.tar.gz
TabFS-b8258aaa019de66081444dedd3c6020f53a5296f.zip
extension: Load bg.js upfront; fix bracket matching in routes.html.
Diffstat (limited to 'extension/background.js')
-rw-r--r--extension/background.js19
1 files changed, 12 insertions, 7 deletions
diff --git a/extension/background.js b/extension/background.js
index f624f35..2b20fc6 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -641,23 +641,28 @@ Routes["/runtime/reload"] = {
truncate() { return {}; }
};
+window.fetch(chrome.runtime.getURL('background.js'))
+ .then(async r => { window.__backgroundJS = await r.text(); });
+
Routes["/runtime/routes.html"] = makeRouteWithContents(async () => {
+ if (!window.__backgroundJS) throw new UnixError(unix.EIO);
+
// WIP
- if (!window.__backgroundJS) {
- window.__backgroundJS = await window.fetch(chrome.runtime.getURL('background.js'))
- .then(r => r.text());
- }
const jsLines = (window.__backgroundJS).split('\n');
function findRouteLineRange(path) {
for (let i = 0; i < jsLines.length; i++) {
if (jsLines[i].includes(`Routes["${path}"] = `)) {
if (jsLines[i].match(/;/)) { return [i, i]; } // hacky: if it's a one-liner
- const [_, startBracket] = jsLines[i].match(/Routes\[[^\]]*\] = [^\(\{]*([\(\{])/);
+ const result = jsLines[i].match(/Routes\[[^\]]*\] = [^\(\{]*([\(\{])/);
+ const startBracket = result[1];
+ const startBracketIndex = result.index + result[0].length;
const endBracket = ({'(': ')', '{': '}'})[startBracket];
let counter = 1;
- for (let j = i + 1; j < jsLines.length; j++) {
- for (let k = 0; k < jsLines[j].length; k++) {
+ for (let j = i; j < jsLines.length; j++) {
+ for (let k = (j === i) ? startBracketIndex + 1 : 0;
+ k < jsLines[j].length;
+ k++) {
if (jsLines[j][k] === startBracket) { counter++; }
else if (jsLines[j][k] === endBracket) { counter--; }