|
1 | | -// ScriptVault v3.4.0 - Background Service Worker |
| 1 | +// ScriptVault v3.5.0 - Background Service Worker |
2 | 2 | // Comprehensive userscript manager with cloud sync and auto-updates |
3 | 3 | // NOTE: This file is built from source modules. Edit the individual files in |
4 | 4 | // shared/, modules/, and lib/, then run `npm run build` to regenerate. |
@@ -10746,6 +10746,7 @@ function parseUserscript(code) { |
10746 | 10746 | incompatible: [], |
10747 | 10747 | webRequest: null, |
10748 | 10748 | priority: 0, |
| 10749 | + weight: 0, |
10749 | 10750 | crontab: '' |
10750 | 10751 | }; |
10751 | 10752 |
|
@@ -10824,6 +10825,15 @@ function parseUserscript(code) { |
10824 | 10825 | case 'priority': |
10825 | 10826 | meta.priority = parseInt(value, 10) || 0; |
10826 | 10827 | break; |
| 10828 | + case 'weight': { |
| 10829 | + // Phase 11.7 — Userscripts (Safari) `@weight 1..999`. Integer |
| 10830 | + // injection priority where higher = earlier within the same |
| 10831 | + // `@run-at`. Clamp to the documented range so an `@weight 99999` |
| 10832 | + // typo can't dominate the sort. |
| 10833 | + const w = parseInt(value, 10); |
| 10834 | + if (Number.isFinite(w)) meta.weight = Math.max(1, Math.min(999, w)); |
| 10835 | + break; |
| 10836 | + } |
10827 | 10837 | case 'webRequest': |
10828 | 10838 | try { meta.webRequest = JSON.parse(value); } catch (e) {} |
10829 | 10839 | break; |
@@ -15531,10 +15541,14 @@ async function registerAllScripts(forceReregister = false) { |
15531 | 15541 |
|
15532 | 15542 | const enabledScripts = scripts.filter(s => s.enabled !== false); |
15533 | 15543 |
|
15534 | | - // Sort by @priority (higher = first), then position |
| 15544 | + // Sort by combined @priority + @weight (higher = first), then position. |
| 15545 | + // @priority is the legacy ScriptVault directive; @weight is the Userscripts |
| 15546 | + // (Safari) standard (1..999). Either bumps a script earlier within the same |
| 15547 | + // @run-at — we take the max so authors who set both don't get surprised by |
| 15548 | + // the lower one winning. |
15535 | 15549 | enabledScripts.sort((a, b) => { |
15536 | | - const pa = a.meta?.priority || 0; |
15537 | | - const pb = b.meta?.priority || 0; |
| 15550 | + const pa = Math.max(a.meta?.priority || 0, a.meta?.weight || 0); |
| 15551 | + const pb = Math.max(b.meta?.priority || 0, b.meta?.weight || 0); |
15538 | 15552 | if (pb !== pa) return pb - pa; |
15539 | 15553 | return (a.position || 0) - (b.position || 0); |
15540 | 15554 | }); |
@@ -16468,7 +16482,10 @@ ${req.code} |
16468 | 16482 | license: meta.license || '', |
16469 | 16483 | updateURL: meta.updateURL || '', |
16470 | 16484 | downloadURL: meta.downloadURL || '', |
16471 | | - supportURL: meta.supportURL || '' |
| 16485 | + supportURL: meta.supportURL || '', |
| 16486 | + // Phase 11.7 — Userscripts (Safari) injection priority. |
| 16487 | + weight: meta.weight || 0, |
| 16488 | + priority: meta.priority || 0 |
16472 | 16489 | }, |
16473 | 16490 | scriptMetaStr: ${JSON.stringify(script.code.match(/\/\/\s*==UserScript==([\s\S]*?)\/\/\s*==\/UserScript==/)?.[0] || '')}, |
16474 | 16491 | scriptHandler: 'ScriptVault', |
|
0 commit comments