diff options
author | Omar Rizwan <omar@omar.website> | 2021-03-22 08:56:48 -0700 |
---|---|---|
committer | Omar Rizwan <omar@omar.website> | 2021-03-22 08:56:48 -0700 |
commit | 345c7a4af5294c5d548973eb9da3ac560e429cc5 (patch) | |
tree | 876c0b3d4adddf6f51df9490393c2ac3cf65c0d4 /extension/background.js | |
parent | 73f4672a8cf56b7c5fb6afa22e925b81867fcb89 (diff) | |
download | TabFS-345c7a4af5294c5d548973eb9da3ac560e429cc5.tar.gz TabFS-345c7a4af5294c5d548973eb9da3ac560e429cc5.zip |
extension: red highlights for routes.
Diffstat (limited to 'extension/background.js')
-rw-r--r-- | extension/background.js | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/extension/background.js b/extension/background.js index 8d06ebd..237b02d 100644 --- a/extension/background.js +++ b/extension/background.js @@ -538,9 +538,35 @@ Router["/runtime/reload"] = { }; Router["/runtime/background.js.html"] = defineFile(async () => { const js = await window.fetch(chrome.runtime.getURL('background.js')) - .then(r => r.text()); + .then(r => r.text()); + + const classes = [ + [/Router\["[^\]]+"\] = /, 'route'] + ]; + + const classedJs = + js.split('\n') + .map(line => { + const class_ = classes.find(([re, class_]) => re.test(line)); + line = line + .replace(/&/g, "&") + .replace(/</g, "<") + .replace(/>/g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); + if (!class_) { return `<span>${line}</span>`; } + return `<span class="${class_[1]}">${line}</span>`; + }) + .join('\n'); + return ` <html> + <head> + <style> + .route { background-color: red; } + span:not(.route) { height: 0px; } + </style> + </head> <body> <dl> ${Object.entries(Router).map(([a, b]) => ` @@ -548,7 +574,7 @@ Router["/runtime/background.js.html"] = defineFile(async () => { <dd>${b}</dd> `).join('\n')} </dl> - <pre><code>${js}</code></pre> + <pre><code>${classedJs}</code></pre> </body> </html> `; |