Skip to content

Commit 4ce0246

Browse files
committed
fix(userscript): use raw install url on pages
1 parent ceb8df6 commit 4ce0246

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

.github/workflows/deploy-pages.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ jobs:
8686
BASE_PATH: /${{ github.event.repository.name }}
8787
PUBLIC_GITHUB_CLIENT_ID: ${{ secrets.NEOXK_GITHUB_CLIENT_ID }}
8888
PUBLIC_GITHUB_OAUTH_PROXY_URL: ${{ vars.PUBLIC_GITHUB_OAUTH_PROXY_URL }}
89+
VITE_GITHUB_REPO: ${{ github.repository }}
8990

9091
- uses: actions/upload-pages-artifact@v3
9192
with:

app/src/config/userscript.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,23 @@ export interface UserscriptConfig {
55
scriptUrl: string;
66
}
77

8+
function resolveRepoSlug() {
9+
return import.meta.env?.VITE_GITHUB_REPO ?? '129s/NeoSHUSchedulingHelper';
10+
}
11+
812
const DEFAULT_CONFIG: UserscriptConfig = {
913
helpUrl:
1014
import.meta.env?.VITE_USERSCRIPT_HELP_URL ??
11-
`https://github.com/${import.meta.env?.VITE_GITHUB_REPO ?? '129s/NeoSHUSchedulingHelper'}#readme`,
15+
`https://github.com/${resolveRepoSlug()}#readme`,
1216
// Prefer `.user.js` suffix to ensure userscript managers trigger install reliably.
13-
scriptUrl: `${base || ''}/backenduserscript/backend.user.js`
17+
//
18+
// On GitHub Pages, some setups (e.g. service worker, COOP/COEP headers, or routing fallbacks)
19+
// can interfere with userscript managers' install interception. A raw.githubusercontent.com
20+
// URL is the most stable install source.
21+
scriptUrl: import.meta.env?.PROD
22+
? import.meta.env?.VITE_USERSCRIPT_INSTALL_URL ??
23+
`https://raw.githubusercontent.com/${resolveRepoSlug()}/main/app/static/backenduserscript/backend.user.js`
24+
: `${base || ''}/backenduserscript/backend.user.js`
1425
};
1526

1627
export function getUserscriptConfig(overrides?: Partial<UserscriptConfig>): UserscriptConfig {

0 commit comments

Comments
 (0)