···6161 // stop updating the subheader
6262 intervals.forEach((interval) => clearInterval(interval));
63636464- for (const child of oldChildren) {
6565- // remove new children
6666- while (subheader.firstChild) {
6767- subheader.removeChild(subheader.firstChild);
6868- }
6464+ // remove new children
6565+ while (subheader.firstChild) {
6666+ subheader.removeChild(subheader.firstChild);
6767+ }
69687070- // restore old children
6969+ // restore old children
7070+ for (const child of oldChildren) {
7171 subheader.appendChild(child);
7272 }
7373
+10
src/entrypoints/start.content.ts
···4040 const updateUserSnippets: WatchCallback<Settings> = (newValue, oldValue) => {
4141 // if global or userSnippets were changed
4242 if (hasChanged(newValue, oldValue, ["global", "userSnippets"])) {
4343+ // uninject removed snippets
4444+ if (oldValue) {
4545+ for (const id of Object.keys(oldValue.userSnippets)) {
4646+ if (!newValue.userSnippets[id]) {
4747+ uninjectUserSnippet(id);
4848+ }
4949+ }
5050+ }
5151+5252+ // inject/uninject current snippets
4353 for (const [id, userSnippet] of Object.entries(newValue.userSnippets)) {
4454 if (newValue.global && newValue.snippets && userSnippet.toggle) {
4555 injectUserSnippet(id);
+10-11
src/utils/index.ts
···130130 }
131131132132 // check not already injected
133133- const style = document.querySelector(dataAttr(`userSnippet-${id}`));
134134- if (style) {
133133+ if (document.querySelector(dataAttr(`userSnippet-${id}`))) {
135134 logger.info(`user snippet with id ${id} already injected, aborting`);
136135 return;
137136 }
138137139138 // inject user snippet
140140- fetch(`https://gist.githubusercontent.com/${snippet.author}/${id}/raw`)
141141- .then((response) => response.text())
142142- .then((css) => {
143143- const style = document.createElement("style");
144144- style.textContent = css;
145145- setDataAttr(style, `userSnippet-${id}`);
146146- document.head.appendChild(style);
147147- logger.info(`injected user snippet with id ${id}`);
148148- });
139139+ const response = await fetch(`https://gist.githubusercontent.com/${snippet.author}/${id}/raw`);
140140+ const css = await response.text();
141141+ const style = document.createElement("style");
142142+143143+ style.textContent = css;
144144+ setDataAttr(style, `userSnippet-${id}`);
145145+ document.head.appendChild(style);
146146+147147+ logger.info(`injected user snippet with id ${id}`);
149148}
150149151150export function uninjectUserSnippet(id: string) {