Skip to content

Commit

Permalink
fix: improve menu injection
Browse files Browse the repository at this point in the history
closes #24
  • Loading branch information
pionxzh committed Dec 22, 2022
1 parent c3b7114 commit b822e5b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"node": ">=16.0.0"
},
"commitlint": {
"extends": ["@commitlint/config-conventional"]
"extends": [
"@commitlint/config-conventional"
]
},
"scripts": {
"build": "turbo run build",
Expand All @@ -36,6 +38,11 @@
"turbo": "^1.6.3",
"typescript": "^4.9.4"
},
"pnpm": {
"patchedDependencies": {
"sentinel-js@0.0.5": "patches/sentinel-js@0.0.5.patch"
}
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": "pnpm exec eslint"
}
Expand Down
13 changes: 13 additions & 0 deletions packages/userscript/patches/sentinel-js@0.0.5.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/dist/sentinel.umd.js b/dist/sentinel.umd.js
index 08dcbff40b764a4eabf7990e751c364c4724c885..d5ce9732e2726d9497dc14bcbbcdd155247c3b52 100644
--- a/dist/sentinel.umd.js
+++ b/dist/sentinel.umd.js
@@ -46,7 +46,7 @@ return {

// add stylesheet to document
styleEl = doc.createElement('style');
- head.insertBefore(styleEl, head.firstChild);
+ head.append(styleEl);
styleSheet = styleEl.sheet;
cssRules = styleSheet.cssRules;
}
2 changes: 1 addition & 1 deletion packages/userscript/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function createMenuContainer() {
container.id = 'exporter-menu'
container.className = 'pt-1'

const chatList = document.querySelector('nav > div')
const chatList = document.querySelector('nav > div.overflow-y-auto')
if (chatList) {
chatList.after(container)
sentinel.on('nav > div.overflow-y-auto', (el) => {
Expand Down
13 changes: 13 additions & 0 deletions patches/sentinel-js@0.0.5.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/dist/sentinel.umd.js b/dist/sentinel.umd.js
index 08dcbff40b764a4eabf7990e751c364c4724c885..d5ce9732e2726d9497dc14bcbbcdd155247c3b52 100644
--- a/dist/sentinel.umd.js
+++ b/dist/sentinel.umd.js
@@ -46,7 +46,7 @@ return {

// add stylesheet to document
styleEl = doc.createElement('style');
- head.insertBefore(styleEl, head.firstChild);
+ head.append(styleEl);
styleSheet = styleEl.sheet;
cssRules = styleSheet.cssRules;
}
10 changes: 8 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 comment on commit b822e5b

@pionxzh
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sentinel will try to inject the style element at the start of the head which will be blown away by things like next/head.

Please sign in to comment.