dsh-cookie-cleaner 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,129 +1,129 @@
1
- /**
2
- * dsh-cookie-cleaner — 浏览器半。
3
- *
4
- * 装载契约(三条都是事故换来的):
5
- * - bundle id 必须 = **npm 包名**(`client/modules/src/index.ts:1040` 用 `graphRow(packageName,…)`),
6
- * 注册 id 与宿主图不一致时 client 半从不加载;
7
- * - 注册必须发生在 apply 顶层:关在任何 inject 回调里的注册两代都会静默失活;
8
- * - 每个面单独 `safe()`:未知槽名在个别宿主线上同步抛错,而 cordis 会吞掉 inject 回调的
9
- * 异常,一个面失败会带走同一回调里的其它面。
10
- *
11
- * `configForms`(0.1.7+)/`settingsScope`(≤0.1.5)是代际互斥服务,绝不写进插件级 inject——
12
- * 那会让整个 client fiber 在另一代上停在 pending。这里只依赖 `slots` + `locale`(三代齐)。
13
- */
14
- import { dictionaries, NS, UI_KEYS } from './locales'
15
- import { PatchCard } from './card'
16
-
17
- /** 宿主 locale 服务的最小面(不引宿主类型包:client bundle 只按运行时形状用)。 */
18
- interface LocaleService {
19
- register(ns: string, dicts: Record<string, Record<string, string>>): unknown
20
- bind?(ns: string): (key: string) => string
21
- on?(event: string, listener: () => void): unknown
22
- }
23
-
24
- interface SlotEntry {
25
- name: string
26
- id?: string
27
- /** keyed 槽必填(`ui-slots/src/index.ts:1222`:缺 key 直接 throw)。 */
28
- key?: string
29
- order?: number
30
- label?: () => string
31
- locale?: string
32
- inject?: () => Record<string, unknown>
33
- }
34
-
35
- interface SlotsService {
36
- inject(name: string, factory: () => Generator<unknown, void, unknown>): unknown
37
- register(entry: SlotEntry, component: unknown): unknown
38
- }
39
-
40
- interface ClientContext {
41
- get?(name: string): unknown
42
- inject(deps: readonly string[], fn: (ctx: ClientContext) => void): unknown
43
- effect(fn: () => unknown, label?: string): unknown
44
- slots?: SlotsService
45
- locale?: LocaleService
46
- }
47
-
48
- /** 插件级 inject 只声明三代都存在的服务。 */
49
- export const inject = ['slots', 'locale'] as const
50
-
51
- /** 当前语言的取词函数(注册后由 locale 服务提供;拿不到 bind 时回落 zh 字典)。 */
52
- let currentT: (key: string) => string = (key) => {
53
- const zh = (dictionaries as Record<string, Record<string, string>>).zh
54
- return zh[key] ?? key
55
- }
56
-
57
- /** 每个面的独立 try/catch:一面抛错不带走其它面。 */
58
- function safe(ctx: ClientContext, tag: string, fn: () => void): void {
59
- try {
60
- fn()
61
- } catch (error) {
62
- // 农场/真机拿不到 console 时也要留痕:失败面写进 window,供探针直接读取。
63
- const surface = ((globalThis as Record<string, unknown>).__dccSurf ??= []) as string[]
64
- surface.push(`${tag}: ${String((error as Error)?.message ?? error)}`)
65
- const logger = typeof ctx.get === 'function' ? ctx.get('logger') as { warn?(msg: string): void } : undefined
66
- if (typeof logger?.warn === 'function') logger.warn(`[dsh-cookie-cleaner] ${tag} failed: ${String((error as Error)?.message ?? error)}`)
67
- }
68
- }
69
-
70
- /**
71
- * 浏览器半入口。
72
- * @param ctx client context。
73
- */
74
- export function apply(ctx: ClientContext): void {
75
- // 字典注册:一次调用带 9 语(map 式注册要求宿主 locale 服务接受任意语言码)。
76
- safe(ctx, 'locale.register', () => {
77
- if (typeof ctx.locale?.register !== 'function') throw new Error('locale service unavailable')
78
- ctx.locale.register(NS, dictionaries)
79
- const bind = ctx.locale.bind?.(NS)
80
- if (typeof bind === 'function') {
81
- // bind 是活的取值器:换语言后重渲染即跟上新值,卡片不自存语言副本。
82
- currentT = (key: string) => bind(key)
83
- }
84
- })
85
-
86
- // 席位 A:设置页顶级独立节(范式 A,不参与家族 tab 选举)。
87
- safe(ctx, 'settings.section', () => {
88
- const slots = ctx.slots
89
- if (slots?.inject === undefined || slots.register === undefined) throw new Error('slots service unavailable')
90
- slots.inject('settings.section', function* () {
91
- yield slots.register({
92
- name: 'settings.section',
93
- id: NS,
94
- order: 45,
95
- label: () => currentT('section.title'),
96
- locale: NS,
97
- inject: () => ({ t: (key: string) => currentT(key) }),
98
- }, PatchCard)
99
- })
100
- })
101
-
102
- // 席位 B:插件页配置卡(0.2.x 上「导出 Config 自动出表单」不成立,必须显式挂)。
103
- // 这个槽是 **keyed** 形态,key = bundle 的包名(真机报错:keyed slot requires options.key)。
104
- safe(ctx, 'plugins.bundle.config', () => {
105
- const slots = ctx.slots
106
- if (slots?.inject === undefined || slots.register === undefined) throw new Error('slots service unavailable')
107
- slots.inject('plugins.bundle.config', function* () {
108
- yield slots.register({
109
- name: 'plugins.bundle.config',
110
- key: NS,
111
- order: 45,
112
- label: () => currentT('section.title'),
113
- locale: NS,
114
- inject: () => ({ t: (key: string) => currentT(key) }),
115
- }, PatchCard)
116
- })
117
- })
118
-
119
- // 装载自检:键集没注册全就是构建坏了,立刻留痕而不是等用户点开空卡。
120
- safe(ctx, 'dictionary sanity', () => {
121
- const langs = Object.keys(dictionaries)
122
- if (langs.length !== 9) throw new Error(`expected 9 languages, got ${String(langs.length)}`)
123
- const missing = langs.filter((lang) => {
124
- const dict = (dictionaries as Record<string, Record<string, string>>)[lang]
125
- return UI_KEYS.some((key) => typeof dict[key] !== 'string' || dict[key] === '')
126
- })
127
- if (missing.length > 0) throw new Error(`empty keys for ${missing.join(', ')}`)
128
- })
129
- }
1
+ /**
2
+ * dsh-cookie-cleaner — 浏览器半。
3
+ *
4
+ * 装载契约(三条都是事故换来的):
5
+ * - bundle id 必须 = **npm 包名**(`client/modules/src/index.ts:1040` 用 `graphRow(packageName,…)`),
6
+ * 注册 id 与宿主图不一致时 client 半从不加载;
7
+ * - 注册必须发生在 apply 顶层:关在任何 inject 回调里的注册两代都会静默失活;
8
+ * - 每个面单独 `safe()`:未知槽名在个别宿主线上同步抛错,而 cordis 会吞掉 inject 回调的
9
+ * 异常,一个面失败会带走同一回调里的其它面。
10
+ *
11
+ * `configForms`(0.1.7+)/`settingsScope`(≤0.1.5)是代际互斥服务,绝不写进插件级 inject——
12
+ * 那会让整个 client fiber 在另一代上停在 pending。这里只依赖 `slots` + `locale`(三代齐)。
13
+ */
14
+ import { dictionaries, NS, UI_KEYS } from './locales'
15
+ import { PatchCard } from './card'
16
+
17
+ /** 宿主 locale 服务的最小面(不引宿主类型包:client bundle 只按运行时形状用)。 */
18
+ interface LocaleService {
19
+ register(ns: string, dicts: Record<string, Record<string, string>>): unknown
20
+ bind?(ns: string): (key: string) => string
21
+ on?(event: string, listener: () => void): unknown
22
+ }
23
+
24
+ interface SlotEntry {
25
+ name: string
26
+ id?: string
27
+ /** keyed 槽必填(`ui-slots/src/index.ts:1222`:缺 key 直接 throw)。 */
28
+ key?: string
29
+ order?: number
30
+ label?: () => string
31
+ locale?: string
32
+ inject?: () => Record<string, unknown>
33
+ }
34
+
35
+ interface SlotsService {
36
+ inject(name: string, factory: () => Generator<unknown, void, unknown>): unknown
37
+ register(entry: SlotEntry, component: unknown): unknown
38
+ }
39
+
40
+ interface ClientContext {
41
+ get?(name: string): unknown
42
+ inject(deps: readonly string[], fn: (ctx: ClientContext) => void): unknown
43
+ effect(fn: () => unknown, label?: string): unknown
44
+ slots?: SlotsService
45
+ locale?: LocaleService
46
+ }
47
+
48
+ /** 插件级 inject 只声明三代都存在的服务。 */
49
+ export const inject = ['slots', 'locale'] as const
50
+
51
+ /** 当前语言的取词函数(注册后由 locale 服务提供;拿不到 bind 时回落 zh 字典)。 */
52
+ let currentT: (key: string) => string = (key) => {
53
+ const zh = (dictionaries as Record<string, Record<string, string>>).zh
54
+ return zh[key] ?? key
55
+ }
56
+
57
+ /** 每个面的独立 try/catch:一面抛错不带走其它面。 */
58
+ function safe(ctx: ClientContext, tag: string, fn: () => void): void {
59
+ try {
60
+ fn()
61
+ } catch (error) {
62
+ // 农场/真机拿不到 console 时也要留痕:失败面写进 window,供探针直接读取。
63
+ const surface = ((globalThis as Record<string, unknown>).__dccSurf ??= []) as string[]
64
+ surface.push(`${tag}: ${String((error as Error)?.message ?? error)}`)
65
+ const logger = typeof ctx.get === 'function' ? ctx.get('logger') as { warn?(msg: string): void } : undefined
66
+ if (typeof logger?.warn === 'function') logger.warn(`[dsh-cookie-cleaner] ${tag} failed: ${String((error as Error)?.message ?? error)}`)
67
+ }
68
+ }
69
+
70
+ /**
71
+ * 浏览器半入口。
72
+ * @param ctx client context。
73
+ */
74
+ export function apply(ctx: ClientContext): void {
75
+ // 字典注册:一次调用带 9 语(map 式注册要求宿主 locale 服务接受任意语言码)。
76
+ safe(ctx, 'locale.register', () => {
77
+ if (typeof ctx.locale?.register !== 'function') throw new Error('locale service unavailable')
78
+ ctx.locale.register(NS, dictionaries)
79
+ const bind = ctx.locale.bind?.(NS)
80
+ if (typeof bind === 'function') {
81
+ // bind 是活的取值器:换语言后重渲染即跟上新值,卡片不自存语言副本。
82
+ currentT = (key: string) => bind(key)
83
+ }
84
+ })
85
+
86
+ // 席位 A:设置页顶级独立节(范式 A,不参与家族 tab 选举)。
87
+ safe(ctx, 'settings.section', () => {
88
+ const slots = ctx.slots
89
+ if (slots?.inject === undefined || slots.register === undefined) throw new Error('slots service unavailable')
90
+ slots.inject('settings.section', function* () {
91
+ yield slots.register({
92
+ name: 'settings.section',
93
+ id: NS,
94
+ order: 45,
95
+ label: () => currentT('section.title'),
96
+ locale: NS,
97
+ inject: () => ({ t: (key: string) => currentT(key) }),
98
+ }, PatchCard)
99
+ })
100
+ })
101
+
102
+ // 席位 B:插件页配置卡(0.2.x 上「导出 Config 自动出表单」不成立,必须显式挂)。
103
+ // 这个槽是 **keyed** 形态,key = bundle 的包名(真机报错:keyed slot requires options.key)。
104
+ safe(ctx, 'plugins.bundle.config', () => {
105
+ const slots = ctx.slots
106
+ if (slots?.inject === undefined || slots.register === undefined) throw new Error('slots service unavailable')
107
+ slots.inject('plugins.bundle.config', function* () {
108
+ yield slots.register({
109
+ name: 'plugins.bundle.config',
110
+ key: NS,
111
+ order: 45,
112
+ label: () => currentT('section.title'),
113
+ locale: NS,
114
+ inject: () => ({ t: (key: string) => currentT(key) }),
115
+ }, PatchCard)
116
+ })
117
+ })
118
+
119
+ // 装载自检:键集没注册全就是构建坏了,立刻留痕而不是等用户点开空卡。
120
+ safe(ctx, 'dictionary sanity', () => {
121
+ const langs = Object.keys(dictionaries)
122
+ if (langs.length !== 9) throw new Error(`expected 9 languages, got ${String(langs.length)}`)
123
+ const missing = langs.filter((lang) => {
124
+ const dict = (dictionaries as Record<string, Record<string, string>>)[lang]
125
+ return UI_KEYS.some((key) => typeof dict[key] !== 'string' || dict[key] === '')
126
+ })
127
+ if (missing.length > 0) throw new Error(`empty keys for ${missing.join(', ')}`)
128
+ })
129
+ }
@@ -0,0 +1,256 @@
1
+ /**
2
+ * star-row 真源(面板 star 快车道行,v1)——纯 DOM 实现,零依赖。
3
+ *
4
+ * 副本约束:生成文件名 star-row-copy.ts,头部须保留 /** 块注释,单行 ≤140
5
+ * 字宽(sidebar-fold 仓 lint 门禁:max-line + file-header)。
6
+ *
7
+ * 契约(对齐 panel-star-row spec):
8
+ * - 渲染一行 <a>:GitHub 单色 SVG + `owner/name`;variant A 追加一句工程话术;
9
+ * - 整行即链接(A/L 档),新标签页打开;不做弹窗、不做按钮交互;
10
+ * - 文案内嵌 10 语,按 `document.documentElement.lang` 前缀自选
11
+ * (同 sidebar-fold `pickDictionary` 口径),不依赖宿主 locale 服务,
12
+ * 避免逐仓动字典文件;
13
+ * - 样式一次性注入 <style data-dsh-star-row>,色随 currentColor,深浅主题自适应;
14
+ * - 副本由 _tools/star-row/sync.mjs 生成到各仓 `src/client/star-row-copy.ts`
15
+ * (文件名含 copy,locale 守卫豁免规则命中),改副本无效,改真源后重跑 sync。
16
+ *
17
+ * 每仓生成时在文件头部烘焙 REPO_URL / STAR_NS / STAR_VARIANT 三个常量。
18
+ */
19
+
20
+ /** 生成段:REPO_URL / STAR_NS / STAR_VARIANT 由 sync 注入。 */
21
+ // STAR-CONSTS:BEGIN — generated by _tools/star-row/sync.mjs; edit the real source instead
22
+ const REPO_URL = "https://github.com/drscrewdriver/dsh-cookie-cleaner";
23
+ const STAR_NS = "cookie-cleaner";
24
+ const STAR_VARIANT = "S" as "S" | "A" | "L";
25
+ // STAR-CONSTS:END
26
+
27
+ /** zh 为键集真理源;10 语与 sidebar-fold/manage-session 同集合。 */
28
+ const STAR_COPY: Record<string, { ask: string }> = {
29
+ zh: { ask: "觉得省事了?一颗 Star 让工具被更多人看见" },
30
+ en: { ask: "Finding it handy? A star helps more people discover this tool" },
31
+ ja: { ask: "便利でしたら⭐で、このツールがもっと届きます" },
32
+ ko: { ask: "유용했다면 ⭐ 하나로 더 많은 사용자에게 닿습니다" },
33
+ fr: { ask: "Utile ? Une étoile aide cet outil à être découvert" },
34
+ de: { ask: "Nützlich? Ein Stern hilft dem Tool, gesehen zu werden" },
35
+ it: { ask: "Ti è utile? Una stella aiuta questo tool a farsi scoprire" },
36
+ ru: { ask: "Пригодилось? Звезда поможет большему числу людей узнать о tool" },
37
+ es: { ask: "¿Te resulta útil? Una estrella ayuda a que más gente lo descubra" },
38
+ pt: { ask: "Achou útil? Uma estrela ajuda mais pessoas a descobrir a ferramenta" },
39
+ };
40
+ const STAR_LANGS = ["zh", "en", "ja", "ko", "fr", "de", "it", "ru", "es", "pt"];
41
+
42
+ /** GitHub mark(Simple Icons / octicon 轮廓,24 视口),fill 随 currentColor。 */
43
+ const GITHUB_MARK_PATH =
44
+ "M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577" +
45
+ " 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7" +
46
+ " 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07" +
47
+ " 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332" +
48
+ " -5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0" +
49
+ " 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552" +
50
+ " 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0" +
51
+ " 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015" +
52
+ " 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12";
53
+
54
+ const STYLE_ID = "dsh-star-row-style";
55
+ const STYLE_CSS = [
56
+ ".dsh-star-row{display:flex;align-items:center;gap:7px;font-size:12px;",
57
+ "line-height:1.5;color:inherit;text-decoration:none;opacity:.72;padding:3px 0;",
58
+ "margin-top:6px;min-width:0;flex-wrap:wrap}",
59
+ ".dsh-star-row:hover{opacity:1;text-decoration:underline}",
60
+ ".dsh-star-row svg{width:14px;height:14px;flex:none;display:block}",
61
+ ".dsh-star-row .dsh-star-ask{opacity:.85;font-weight:400}",
62
+ ].join("");
63
+
64
+ function pickLang(): { ask: string } {
65
+ const tag = (typeof document !== "undefined" && document.documentElement.lang) || "";
66
+ const low = tag.toLowerCase();
67
+ for (const cand of STAR_LANGS) {
68
+ if (low.startsWith(cand)) return STAR_COPY[cand]!;
69
+ }
70
+ return STAR_COPY.en!;
71
+ }
72
+
73
+ // STAR:EXTENDED:BEGIN — S 档专用段(话术 + ★ CTA + 隐藏钮)。sync 对 A/L 副本整段剥除,
74
+ // 所以本段怎么改都不会波及已发布的 A/L 副本。S 档渲染:GitHub SVG + owner/repo 链接 |
75
+ // star.ask | ★ star.cta(打开仓库页)| × star.hide(收话术与两钮)。★ 是「去点星」的
76
+ // 动作,隐藏才是「别打扰我」;两者绝不合流——旧版把点星写成隐藏,用户点 ★ 只落个静默收起,
77
+ // 仓库页一次都没打开过(2.0.25 实测缺陷)。隐藏写 localStorage `dsh.star.<ns>.dismissed=1`,
78
+ // 链接段永留。文案 10 语随 documentElement.lang。
79
+ const STAR_CTA: Record<string, string> = {
80
+ zh: "留颗 Star",
81
+ en: "Star",
82
+ ja: "スター",
83
+ ko: "스타",
84
+ fr: "Star",
85
+ de: "Stern",
86
+ it: "Stella",
87
+ ru: "Звезда",
88
+ es: "Estrella",
89
+ pt: "Estrela",
90
+ };
91
+
92
+ /** 隐藏钮的可读名(★ 之外的独立动作,10 语同集)。 */
93
+ const STAR_HIDE: Record<string, string> = {
94
+ zh: "不再提示",
95
+ en: "Dismiss",
96
+ ja: "今後表示しない",
97
+ ko: "다시 보지 않기",
98
+ fr: "Masquer",
99
+ de: "Ausblenden",
100
+ it: "Nascondi",
101
+ ru: "Скрыть",
102
+ es: "Ocultar",
103
+ pt: "Ocultar",
104
+ };
105
+
106
+ const STAR_S_STYLE_ID = "dsh-star-row-s-style";
107
+ const STAR_S_STYLE = [
108
+ ".dsh-star-row-s{display:flex;align-items:center;gap:8px;flex-wrap:wrap;",
109
+ "font-size:12px;line-height:1.5;color:inherit;opacity:.75;margin-top:10px;",
110
+ "padding-top:8px;border-top:1px solid var(--dsw-alias-border-l2,currentColor)}",
111
+ ".dsh-star-row-s:hover{opacity:1}",
112
+ ".dsh-star-link{display:inline-flex;align-items:center;gap:6px;",
113
+ "color:inherit;text-decoration:none}",
114
+ ".dsh-star-link:hover{text-decoration:underline}",
115
+ ".dsh-star-link svg{width:14px;height:14px;flex:none;display:block}",
116
+ ".dsh-star-row-s .dsh-star-ask{opacity:.85;font-weight:400}",
117
+ ".dsh-star-cta,.dsh-star-hide{font:inherit;font-size:11px;line-height:1;",
118
+ "padding:4px 9px;border-radius:999px;border:1px solid currentColor;",
119
+ "background:transparent;color:inherit;cursor:pointer;flex:none;opacity:.7}",
120
+ ".dsh-star-hide{padding:4px 7px}",
121
+ ".dsh-star-cta:hover,.dsh-star-hide:hover{opacity:1}",
122
+ ].join("");
123
+
124
+ /** 宿主语言标签归一:取 `documentElement.lang` 的前缀,命中 STAR_LANGS 即用。 */
125
+ function starLang(): string {
126
+ const tag = (typeof document !== "undefined" && document.documentElement.lang) || "";
127
+ const low = tag.toLowerCase();
128
+ for (const cand of STAR_LANGS) if (low.startsWith(cand)) return cand;
129
+ return "en";
130
+ }
131
+
132
+ /** 是否已被用户点掉话术(隐私模式下读失败按未关闭处理,只影响本次会话)。 */
133
+ function starDismissed(): boolean {
134
+ try {
135
+ return localStorage.getItem("dsh.star." + STAR_NS + ".dismissed") === "1";
136
+ } catch {
137
+ return false;
138
+ }
139
+ }
140
+
141
+ /** 记住关闭态(隐私模式写失败不报错,话术本次隐藏、刷新复活)。 */
142
+ function starDismiss(): void {
143
+ try {
144
+ localStorage.setItem("dsh.star." + STAR_NS + ".dismissed", "1");
145
+ } catch {
146
+ /* noop */
147
+ }
148
+ }
149
+
150
+ /** 一次性注入 S 档样式。 */
151
+ function injectStarSStyle(d: Document): void {
152
+ if (d.getElementById(STAR_S_STYLE_ID)) return;
153
+ const style = d.createElement("style");
154
+ style.id = STAR_S_STYLE_ID;
155
+ style.textContent = STAR_S_STYLE;
156
+ d.head.appendChild(style);
157
+ }
158
+
159
+ /** 打开仓库页:桌面壳里 window.open 可能被拦,锚点 click 才是两条路径都通的写法。 */
160
+ function openRepo(d: Document): void {
161
+ const a = d.createElement("a");
162
+ a.href = REPO_URL;
163
+ a.target = "_blank";
164
+ a.rel = "noopener noreferrer";
165
+ a.click();
166
+ }
167
+
168
+ /** S 档扩充:把裸链接行升级成「链接 | 话术 | ★ CTA | × 隐藏」,非 S 档返回 null 走原路径。 */
169
+ function extendedStarRow(link: HTMLElement, d: Document): HTMLElement | null {
170
+ if (STAR_VARIANT !== "S") return null;
171
+ if (starDismissed()) return link;
172
+ injectStarSStyle(d);
173
+ link.className = "dsh-star-link";
174
+ const lang = starLang();
175
+ const row = d.createElement("div");
176
+ row.className = "dsh-star-row-s";
177
+ row.appendChild(link);
178
+ const ask = d.createElement("span");
179
+ ask.className = "dsh-star-ask";
180
+ ask.textContent = STAR_COPY[lang]!.ask;
181
+ row.appendChild(ask);
182
+ const cta = d.createElement("button");
183
+ cta.type = "button";
184
+ cta.className = "dsh-star-cta";
185
+ cta.textContent = "★ " + STAR_CTA[lang];
186
+ cta.addEventListener("click", (event: Event) => {
187
+ // 行内的 ★ 是「去点星」:打开仓库页,不隐藏。
188
+ event.preventDefault();
189
+ event.stopPropagation();
190
+ openRepo(d);
191
+ });
192
+ row.appendChild(cta);
193
+ const hide = d.createElement("button");
194
+ hide.type = "button";
195
+ hide.className = "dsh-star-hide";
196
+ hide.textContent = "×";
197
+ hide.title = STAR_HIDE[lang]!;
198
+ hide.setAttribute("aria-label", STAR_HIDE[lang]!);
199
+ hide.addEventListener("click", (event: Event) => {
200
+ // 隐藏才是「别打扰我」:收话术与两钮,链接段永留。
201
+ event.preventDefault();
202
+ event.stopPropagation();
203
+ starDismiss();
204
+ if (row.parentNode) {
205
+ row.parentNode.replaceChild(link, row);
206
+ link.className = "dsh-star-row";
207
+ }
208
+ });
209
+ row.appendChild(hide);
210
+ return row;
211
+ }
212
+ // STAR:EXTENDED:END
213
+ /** 在目标文档上建出快车道行(一次性注入样式)。纯 DOM,React 仓经 ref 回调挂载。 */
214
+ export function mountStarRow(doc?: Document): HTMLElement {
215
+ const d = doc ?? document;
216
+ if (!d.getElementById(STYLE_ID)) {
217
+ const tag = d.createElement("style");
218
+ tag.id = STYLE_ID;
219
+ tag.textContent = STYLE_CSS;
220
+ d.head.appendChild(tag);
221
+ }
222
+ const match = REPO_URL.match(/github\.com\/([^/]+\/[^/#?]+)/);
223
+ const repo = match ? match[1]! : "drscrewdriver";
224
+ const a = d.createElement("a");
225
+ a.className = "dsh-star-row";
226
+ a.href = REPO_URL;
227
+ a.target = "_blank";
228
+ a.rel = "noreferrer";
229
+ a.dataset.starNs = STAR_NS;
230
+
231
+ const svg = d.createElementNS("http://www.w3.org/2000/svg", "svg");
232
+ svg.setAttribute("viewBox", "0 0 24 24");
233
+ svg.setAttribute("aria-hidden", "true");
234
+ const path = d.createElementNS("http://www.w3.org/2000/svg", "path");
235
+ path.setAttribute("fill", "currentColor");
236
+ path.setAttribute("d", GITHUB_MARK_PATH);
237
+ svg.appendChild(path);
238
+ a.appendChild(svg);
239
+
240
+ const label = d.createElement("span");
241
+ label.textContent = repo;
242
+ a.appendChild(label);
243
+ // STAR:EXTENDED:BEGIN — S 档在此接管(A/L 副本由 sync 剥除本段)
244
+ const row = extendedStarRow(a, d);
245
+ if (row) return row;
246
+ // STAR:EXTENDED:END
247
+
248
+ if (STAR_VARIANT === "A") {
249
+ const ask = d.createElement("span");
250
+ ask.className = "dsh-star-ask";
251
+ ask.textContent = pickLang().ask;
252
+ a.appendChild(ask);
253
+ }
254
+ // L 档:仅中性仓库链接,无话术。S 档细条在后续批次扩展。
255
+ return a;
256
+ }