Skip to content

Commit

Permalink
til: module scripts only run once! cool!
Browse files Browse the repository at this point in the history
  • Loading branch information
marcustyphoon committed Jun 10, 2024
1 parent b563976 commit 73424aa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const setNativePalette = async palette => {

const { nonce } = [...document.scripts].find(script => script.getAttributeNames().includes('nonce'));
const script = document.createElement('script');
script.type = 'module';
script.nonce = nonce;
script.src = `${browser.runtime.getURL('/setNativePalette.js')}?palette=${palette}`;
script.dataset.palette = palette;
script.src = browser.runtime.getURL('/setNativePalette.js');
document.documentElement.append(script);
script.remove();
};
Expand Down
2 changes: 1 addition & 1 deletion src/setNativePalette.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
try {
const palette = new URL(import.meta.url).searchParams.get('palette');
const { palette } = document.currentScript.dataset;
const styleElement = document.querySelector('#root > div > style');
const reactKey = Object.keys(styleElement).find((key) => key.startsWith('__reactFiber'));
let fiber = styleElement[reactKey];
Expand Down

0 comments on commit 73424aa

Please # to comment.