dsh-better-sidebar-left 0.2.4 → 0.3.0
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.
- package/cordis.patch.yml +8 -3
- package/package.json +12 -5
- package/src/client.js +1055 -45
- package/src/components.js +19 -1
- package/src/vendor/host/dsh-delete-session.js +1 -1
- package/src/vendor/host/dsh-settings-launcher.js +9 -0
- package/src/vendor/versions.json +3 -2
package/src/client.js
CHANGED
|
@@ -62,7 +62,7 @@ window.__ModuleLoader__.load({
|
|
|
62
62
|
dropHint: '拖到这里删除',
|
|
63
63
|
dropRelease: '松手删除「{name}」',
|
|
64
64
|
dropFallback: '这个对话',
|
|
65
|
-
starAsk: '
|
|
65
|
+
starAsk: '顺手留颗 Star,作者能高兴一整天',
|
|
66
66
|
starCta: '行,给你一颗 Star',
|
|
67
67
|
pageSyncChildrenOn: '删除对话时,把它派生的子代理会话一起删掉。',
|
|
68
68
|
pageSyncChildrenOff: '不勾选时,删除前会列出子会话,由你勾选要删哪些。',
|
|
@@ -180,7 +180,7 @@ window.__ModuleLoader__.load({
|
|
|
180
180
|
dropHint: 'Drop here to delete',
|
|
181
181
|
dropRelease: 'Release to delete \'{name}\'',
|
|
182
182
|
dropFallback: 'this conversation',
|
|
183
|
-
starAsk: '
|
|
183
|
+
starAsk: 'A star would make the author\'s day',
|
|
184
184
|
starCta: 'Fine — have one',
|
|
185
185
|
pageSyncChildrenOn: 'A delete also removes the subagent sessions it spawned.',
|
|
186
186
|
pageSyncChildrenOff: 'When off, the dialog lists the child sessions and you tick the ones to delete.',
|
|
@@ -295,7 +295,7 @@ window.__ModuleLoader__.load({
|
|
|
295
295
|
dropHint: 'Перетащите сюда, чтобы удалить',
|
|
296
296
|
dropRelease: 'Отпустите, чтобы удалить «{name}»',
|
|
297
297
|
dropFallback: 'этот диалог',
|
|
298
|
-
starAsk: '
|
|
298
|
+
starAsk: 'Звёздочка на GitHub сделает автору день',
|
|
299
299
|
starCta: 'Ладно, держи звезду',
|
|
300
300
|
pageSyncChildrenOn: 'Удаление сессии удаляет и порождённые ею сессии субагентов.',
|
|
301
301
|
pageSyncChildrenOff: 'Если выключено, перед удалением появится список дочерних сессий и вы отметите, какие удалить.',
|
|
@@ -1119,6 +1119,16 @@ window.__ModuleLoader__.load({
|
|
|
1119
1119
|
'.dsdel-field:hover{background:var(--dsdel-bg-hover)}',
|
|
1120
1120
|
'.dsdel-field:focus-within{outline:2px solid var(--dsdel-ring);outline-offset:1px}',
|
|
1121
1121
|
'.dsdel-page-hint{margin:0;color:var(--dsdel-label-faint);font-size:12.5px;line-height:19px;letter-spacing:.01em}',
|
|
1122
|
+
'.dsdel-setting{display:flex;align-items:flex-start;gap:12px;padding:2px 0}',
|
|
1123
|
+
'.dsdel-setting-text{display:flex;flex-direction:column;gap:2px;min-width:0}',
|
|
1124
|
+
'.dsdel-setting-title{font-size:13px;line-height:20px;color:var(--dsdel-label)}',
|
|
1125
|
+
'.dsdel-setting-desc{font-size:12px;line-height:18px;color:var(--dsdel-label-faint)}',
|
|
1126
|
+
'.dsdel-switch{position:relative;flex:none;width:38px;height:22px;margin-left:auto;border:0;border-radius:11px;padding:0;cursor:pointer;background:rgba(127,127,127,.4);transition:background .12s ease}',
|
|
1127
|
+
'.dsdel-switch[aria-checked="true"]{background:#4c8dff}',
|
|
1128
|
+
'.dsdel-switch::after{content:"";position:absolute;top:2px;left:2px;width:18px;height:18px;border-radius:50%;background:#fff;transition:left .15s ease}',
|
|
1129
|
+
'.dsdel-switch[aria-checked="true"]::after{left:18px}',
|
|
1130
|
+
'.dsdel-switch:focus-visible{outline:2px solid var(--dsdel-ring);outline-offset:2px}',
|
|
1131
|
+
'@media (prefers-reduced-motion:reduce){.dsdel-switch,.dsdel-switch::after{transition:none}}',
|
|
1122
1132
|
// One produced file per row: tick on the left, path in the middle, a folder
|
|
1123
1133
|
// button on the right. The button sits outside the label so a click opens
|
|
1124
1134
|
// the folder instead of toggling the tick.
|
|
@@ -1130,8 +1140,11 @@ window.__ModuleLoader__.load({
|
|
|
1130
1140
|
'.dsdel-file-open:hover{background:var(--dsdel-bg);border-color:var(--dsdel-border);color:var(--dsdel-label)}',
|
|
1131
1141
|
'.dsdel-file-open:focus-visible{outline:2px solid var(--dsdel-ring);outline-offset:1px}',
|
|
1132
1142
|
'.dsdel-file-remove:hover{background:color-mix(in srgb,var(--dsdel-danger) 12%,transparent);border-color:color-mix(in srgb,var(--dsdel-danger) 40%,transparent);color:var(--dsdel-danger)}',
|
|
1133
|
-
'.dsdel-star{display:flex;align-items:center;
|
|
1134
|
-
'.dsdel-star
|
|
1143
|
+
'.dsdel-star{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-top:6px;padding:8px 10px;border-radius:8px;border:1px solid rgba(0,0,0,.08);background:rgba(255,196,0,.06);color:inherit;text-decoration:none;font-size:12px;line-height:1.4}',
|
|
1144
|
+
'.dsdel-star:hover{background:rgba(255,196,0,.14)}',
|
|
1145
|
+
'.dsdel-star-icon{font-size:14px;line-height:1}',
|
|
1146
|
+
'.dsdel-star-cta{margin-left:auto;color:#8a6d00;font-weight:600}',
|
|
1147
|
+
'@media (prefers-color-scheme: dark){.dsdel-star{border-color:rgba(255,255,255,.12);background:rgba(255,196,0,.08)}.dsdel-star-cta{color:#e8c15a}}',
|
|
1135
1148
|
'.dsdel-root-input{flex:1 1 220px;min-width:160px;min-height:30px;padding:0 10px;border:1px solid var(--dsw-alias-border-secondary,#d0d0d0);border-radius:6px;background:transparent;color:inherit;font:inherit;font-size:13px}',
|
|
1136
1149
|
'.dsdel-picker-path{margin:0 0 8px;font-size:12px;line-height:1.6;color:var(--dsw-alias-label-secondary,#666);word-break:break-all}',
|
|
1137
1150
|
// A wider confirmation dialog: the class reaches it when `Modal` forwards
|
|
@@ -2917,6 +2930,31 @@ window.__ModuleLoader__.load({
|
|
|
2917
2930
|
// configure arrow once the bundle registers its own row.config entry (key
|
|
2918
2931
|
// `<bundle package>#<row id>`). The card carries the one setting the dialog
|
|
2919
2932
|
// also exposes: whether a session delete asks first.
|
|
2933
|
+
/**
|
|
2934
|
+
* One setting the way relocate's page draws it: the title and its explanation on
|
|
2935
|
+
* the left, the control on the right. A checkbox row reads as a form; a switch
|
|
2936
|
+
* with two lines of copy reads as a setting, which is what these are.
|
|
2937
|
+
*
|
|
2938
|
+
* @param options - { key, title, desc, descKey, checked, onChange }.
|
|
2939
|
+
*/
|
|
2940
|
+
function settingRow(options) {
|
|
2941
|
+
const checked = options.checked === true
|
|
2942
|
+
return h('div', { key: 'row:' + options.key, className: 'dsdel-setting' },
|
|
2943
|
+
h('div', { key: 'text', className: 'dsdel-setting-text' },
|
|
2944
|
+
h('div', { key: 'title', className: 'dsdel-setting-title' }, options.title),
|
|
2945
|
+
h('div', { key: options.descKey === undefined ? 'desc' : options.descKey, className: 'dsdel-setting-desc' }, options.desc)),
|
|
2946
|
+
h('button', {
|
|
2947
|
+
key: options.key,
|
|
2948
|
+
type: 'button',
|
|
2949
|
+
role: 'switch',
|
|
2950
|
+
className: 'dsdel-switch',
|
|
2951
|
+
'aria-checked': checked ? 'true' : 'false',
|
|
2952
|
+
'aria-label': options.title,
|
|
2953
|
+
onChange: options.onChange,
|
|
2954
|
+
onClick: () => options.onChange(!checked),
|
|
2955
|
+
}))
|
|
2956
|
+
}
|
|
2957
|
+
|
|
2920
2958
|
function AskBeforeDeleteOption({ view, t: injected }) {
|
|
2921
2959
|
// Unlike the menu rows and the dialog, this entry is registered without a
|
|
2922
2960
|
// `locale`, so the host injects no `t` here. Falling back to the
|
|
@@ -2953,66 +2991,68 @@ window.__ModuleLoader__.load({
|
|
|
2953
2991
|
}
|
|
2954
2992
|
|
|
2955
2993
|
const children = [
|
|
2956
|
-
|
|
2994
|
+
settingRow({
|
|
2957
2995
|
key: 'ask',
|
|
2996
|
+
title: translate('pageAsk'),
|
|
2997
|
+
descKey: 'askHint',
|
|
2998
|
+
desc:
|
|
2999
|
+
// Ask mode needs the dialog for its file list, so "delete straight away"
|
|
3000
|
+
// would be a promise this combination does not keep.
|
|
3001
|
+
translate(ask ? 'pageHintAsk' : (!off && !auto ? 'pageHintAutoWithArtifacts' : 'pageHintAuto')),
|
|
2958
3002
|
checked: ask,
|
|
2959
|
-
label: translate('pageAsk'),
|
|
2960
3003
|
onChange: (checked) => {
|
|
2961
3004
|
setAsk(checked === true)
|
|
2962
3005
|
setSkipConfirm(checked !== true)
|
|
2963
3006
|
},
|
|
2964
3007
|
}),
|
|
2965
|
-
h('p', { key: 'askHint', className: 'dsdel-page-hint' },
|
|
2966
|
-
// Ask mode needs the dialog for its file list, so "delete straight away"
|
|
2967
|
-
// would be a promise this combination does not keep.
|
|
2968
|
-
translate(ask ? 'pageHintAsk' : (!off && !auto ? 'pageHintAutoWithArtifacts' : 'pageHintAuto'))),
|
|
2969
3008
|
|
|
2970
|
-
|
|
3009
|
+
settingRow({
|
|
2971
3010
|
key: 'recycle',
|
|
3011
|
+
title: translate('pageRecycle'),
|
|
3012
|
+
descKey: 'recycleHint',
|
|
3013
|
+
desc: translate(recycle ? 'pageRecycleOn' : 'pageRecycleOff'),
|
|
2972
3014
|
checked: recycle,
|
|
2973
|
-
label: translate('pageRecycle'),
|
|
2974
3015
|
onChange: (checked) => {
|
|
2975
3016
|
setRecycle(checked === true)
|
|
2976
3017
|
setRecycleSession(checked === true)
|
|
2977
3018
|
},
|
|
2978
3019
|
}),
|
|
2979
|
-
h('p', { key: 'recycleHint', className: 'dsdel-page-hint' },
|
|
2980
|
-
translate(recycle ? 'pageRecycleOn' : 'pageRecycleOff')),
|
|
2981
3020
|
|
|
2982
|
-
|
|
3021
|
+
settingRow({
|
|
2983
3022
|
key: 'syncChildren',
|
|
3023
|
+
title: translate('pageSyncChildren'),
|
|
3024
|
+
descKey: 'syncChildrenHint',
|
|
3025
|
+
desc: translate(syncChildrenState ? 'pageSyncChildrenOn' : 'pageSyncChildrenOff'),
|
|
2984
3026
|
checked: syncChildrenState,
|
|
2985
|
-
label: translate('pageSyncChildren'),
|
|
2986
3027
|
onChange: (checked) => {
|
|
2987
3028
|
setSyncChildrenState(checked === true)
|
|
2988
3029
|
setSyncChildren(checked === true)
|
|
2989
3030
|
},
|
|
2990
3031
|
}),
|
|
2991
|
-
h('p', { key: 'syncChildrenHint', className: 'dsdel-page-hint' },
|
|
2992
|
-
translate(syncChildrenState ? 'pageSyncChildrenOn' : 'pageSyncChildrenOff')),
|
|
2993
3032
|
|
|
2994
|
-
|
|
3033
|
+
settingRow({
|
|
2995
3034
|
key: 'replaceCurrent',
|
|
3035
|
+
title: translate('pageReplaceCurrent'),
|
|
3036
|
+
descKey: 'replaceCurrentHint',
|
|
3037
|
+
desc: translate(replaceState ? 'pageReplaceCurrentOn' : 'pageReplaceCurrentOff'),
|
|
2996
3038
|
checked: replaceState,
|
|
2997
|
-
label: translate('pageReplaceCurrent'),
|
|
2998
3039
|
onChange: (checked) => {
|
|
2999
3040
|
setReplaceState(checked === true)
|
|
3000
3041
|
setReplaceCurrent(checked === true)
|
|
3001
3042
|
},
|
|
3002
3043
|
}),
|
|
3003
|
-
h('p', { key: 'replaceCurrentHint', className: 'dsdel-page-hint' },
|
|
3004
|
-
translate(replaceState ? 'pageReplaceCurrentOn' : 'pageReplaceCurrentOff')),
|
|
3005
3044
|
|
|
3006
|
-
|
|
3045
|
+
settingRow({
|
|
3007
3046
|
key: 'off',
|
|
3047
|
+
title: translate('pageArtifactsOff'),
|
|
3048
|
+
descKey: 'offHint',
|
|
3049
|
+
desc: translate(off ? 'pageHintArtifactsOff' : 'pageHintArtifactsOn'),
|
|
3008
3050
|
checked: off,
|
|
3009
|
-
label: translate('pageArtifactsOff'),
|
|
3010
3051
|
onChange: (checked) => {
|
|
3011
3052
|
setOff(checked === true)
|
|
3012
3053
|
setArtifactsOff(checked === true)
|
|
3013
3054
|
},
|
|
3014
3055
|
}),
|
|
3015
|
-
h('p', { key: 'offHint', className: 'dsdel-page-hint' }, translate(off ? 'pageHintArtifactsOff' : 'pageHintArtifactsOn')),
|
|
3016
3056
|
]
|
|
3017
3057
|
|
|
3018
3058
|
// Everything below the master switch only matters while the feature is on;
|
|
@@ -3033,16 +3073,17 @@ window.__ModuleLoader__.load({
|
|
|
3033
3073
|
borderLeft: '2px solid rgba(127,127,127,0.35)',
|
|
3034
3074
|
},
|
|
3035
3075
|
},
|
|
3036
|
-
|
|
3076
|
+
settingRow({
|
|
3037
3077
|
key: 'auto',
|
|
3078
|
+
title: translate('pageArtifactsAuto'),
|
|
3079
|
+
descKey: 'autoHint',
|
|
3080
|
+
desc: translate(auto ? 'pageHintArtifactsAuto' : 'pageHintArtifactsAsk'),
|
|
3038
3081
|
checked: auto,
|
|
3039
|
-
label: translate('pageArtifactsAuto'),
|
|
3040
3082
|
onChange: (checked) => {
|
|
3041
3083
|
setAuto(checked === true)
|
|
3042
3084
|
setArtifactsAuto(checked === true)
|
|
3043
3085
|
},
|
|
3044
3086
|
}),
|
|
3045
|
-
h('p', { key: 'autoHint', className: 'dsdel-page-hint' }, translate(auto ? 'pageHintArtifactsAuto' : 'pageHintArtifactsAsk')),
|
|
3046
3087
|
h('div', {
|
|
3047
3088
|
key: 'scope',
|
|
3048
3089
|
style: {
|
|
@@ -3076,17 +3117,17 @@ window.__ModuleLoader__.load({
|
|
|
3076
3117
|
}),
|
|
3077
3118
|
),
|
|
3078
3119
|
h('p', { key: 'scopeHint', className: 'dsdel-page-hint' }, translate(scope === 'all' ? 'pageScopeAllHint' : 'pageScopeCreatedHint')),
|
|
3079
|
-
|
|
3120
|
+
settingRow({
|
|
3080
3121
|
key: 'skipGit',
|
|
3122
|
+
title: translate('pageSkipGit'),
|
|
3123
|
+
descKey: 'skipGitHint',
|
|
3124
|
+
desc: translate(skipGit ? 'pageSkipGitOn' : 'pageSkipGitOff'),
|
|
3081
3125
|
checked: skipGit,
|
|
3082
|
-
label: translate('pageSkipGit'),
|
|
3083
3126
|
onChange: (checked) => {
|
|
3084
3127
|
setSkipGit(checked === true)
|
|
3085
3128
|
setSkipGitRepos(checked === true)
|
|
3086
3129
|
},
|
|
3087
3130
|
}),
|
|
3088
|
-
h('p', { key: 'skipGitHint', className: 'dsdel-page-hint' },
|
|
3089
|
-
translate(skipGit ? 'pageSkipGitOn' : 'pageSkipGitOff')),
|
|
3090
3131
|
h('div', { key: 'root', style: { display: 'flex', flexDirection: 'column', gap: '6px', marginTop: '2px' } },
|
|
3091
3132
|
h('p', { key: 'rootLabel', className: 'dsdel-page-hint' }, translate('pageRootLabel')),
|
|
3092
3133
|
h('div', { key: 'rootRow', style: { display: 'flex', gap: '8px', alignItems: 'center', flexWrap: 'wrap' } },
|
|
@@ -3133,15 +3174,16 @@ window.__ModuleLoader__.load({
|
|
|
3133
3174
|
// A quiet link to the repository, last in the card. It is a nudge, not a
|
|
3134
3175
|
// setting, so it never competes with the controls above it — and it is a
|
|
3135
3176
|
// plain anchor, so clicking it opens the page instead of switching tabs here.
|
|
3136
|
-
children.push(h('
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3177
|
+
children.push(h('a', {
|
|
3178
|
+
key: 'star',
|
|
3179
|
+
className: 'dsdel-star',
|
|
3180
|
+
href: 'https://github.com/DDDMUC/dsh-delete-session',
|
|
3181
|
+
target: '_blank',
|
|
3182
|
+
rel: 'noreferrer',
|
|
3183
|
+
},
|
|
3184
|
+
h('span', { key: 'icon', className: 'dsdel-star-icon', 'aria-hidden': 'true' }, '⭐'),
|
|
3185
|
+
h('span', { key: 'ask' }, translate('starAsk')),
|
|
3186
|
+
h('span', { key: 'cta', className: 'dsdel-star-cta' }, translate('starCta'))))
|
|
3145
3187
|
|
|
3146
3188
|
// Each control owns the nodes that explain it. Grouping them here keeps the
|
|
3147
3189
|
// markup above flat (a switch and its hint are still two pushes) while the
|
|
@@ -9505,8 +9547,895 @@ window.__ModuleLoader__.load({
|
|
|
9505
9547
|
return module.exports
|
|
9506
9548
|
}
|
|
9507
9549
|
|
|
9550
|
+
// ===== vendored dsh-settings-launcher =====
|
|
9551
|
+
const factory_dsh_settings_launcher = (require) => {
|
|
9552
|
+
const React = require('react')
|
|
9553
|
+
const h = React.createElement
|
|
9554
|
+
|
|
9555
|
+
/** Effect labels; Cordis names the fiber after these. */
|
|
9556
|
+
const NS = 'dsh-settings-launcher'
|
|
9557
|
+
/** The questionnaire the shipped account menu opens (its only feedback target). */
|
|
9558
|
+
const FEEDBACK_URL =
|
|
9559
|
+
'https://trtgsjkv6r.feishu.cn/share/base/form/shrcnlCoGElW7MQznGy9r3YYXcg?hide_uid=1&hide_device_info=1&hide_harness_version=1'
|
|
9560
|
+
|
|
9561
|
+
/**
|
|
9562
|
+
* Both switches live in localStorage rather than the Loader Config: the
|
|
9563
|
+
* client half switches at runtime, and a Config edit restarts the row
|
|
9564
|
+
* instead of reaching the browser. One store, read by the switch card and
|
|
9565
|
+
* the installer, so a change lands everywhere at once.
|
|
9566
|
+
*/
|
|
9567
|
+
const STORE_KEY = 'dsh-settings-launcher:flags'
|
|
9568
|
+
/**
|
|
9569
|
+
* Keys written under the package's previous name. Read once, then removed
|
|
9570
|
+
* after the first successful write, so a rename does not silently reset
|
|
9571
|
+
* the switches a user already chose.
|
|
9572
|
+
*/
|
|
9573
|
+
const LEGACY_STORE_KEYS = ['dsh-settings-direct:flags']
|
|
9574
|
+
/** The single-string key written by the version before `:flags`. */
|
|
9575
|
+
const LEGACY_STORE_KEY = 'dsh-settings-direct:mode'
|
|
9576
|
+
const FLAG_HOVER = 'hover'
|
|
9577
|
+
const FLAG_DIRECT = 'direct'
|
|
9578
|
+
const DEFAULT_FLAGS = { hover: true, direct: false }
|
|
9579
|
+
/** Row-config key: `<bundle package>#<row id from the bundle patch>`. */
|
|
9580
|
+
const ROW_CONFIG_KEY = 'dsh-settings-launcher#settings-launcher'
|
|
9581
|
+
|
|
9582
|
+
/**
|
|
9583
|
+
* Two different attribute names on purpose. The stylesheet tag and the
|
|
9584
|
+
* injected card block used to share one, and the card cleanup sweeps every
|
|
9585
|
+
* node carrying that attribute — so reinstalling deleted the stylesheet
|
|
9586
|
+
* together with the cards, leaving the plugin page's form unstyled.
|
|
9587
|
+
*/
|
|
9588
|
+
const STYLE_ATTR = 'data-dsd-style'
|
|
9589
|
+
const INJECT_ATTR = 'data-dsd-cards'
|
|
9590
|
+
|
|
9591
|
+
/**
|
|
9592
|
+
* The shipped account trigger is the only button in the sidebar carrying
|
|
9593
|
+
* `data-signed-out` (`AccountMenu` sets it from the sign-in state). Its
|
|
9594
|
+
* class prefix is a CSS-module hash that changes every build, and its
|
|
9595
|
+
* `aria-haspopup` is rewritten below when the click opens a dialog — so the
|
|
9596
|
+
* selector anchors on that flag alone.
|
|
9597
|
+
*/
|
|
9598
|
+
const TRIGGER_SELECTOR = 'button[data-signed-out]'
|
|
9599
|
+
/** Any open menu list; the shipped menu is portal-rendered under the body. */
|
|
9600
|
+
const MENU_SELECTOR = '[role="menu"]'
|
|
9601
|
+
const OPEN_DELAY = 160
|
|
9602
|
+
const CLOSE_DELAY = 260
|
|
9603
|
+
/** Shipped shortcut command that opens the Settings panel. */
|
|
9604
|
+
const SETTINGS_COMMAND = 'settings.open'
|
|
9605
|
+
|
|
9606
|
+
const flagSubscribers = new Set()
|
|
9607
|
+
|
|
9608
|
+
/** Parse one `{hover,direct}` document; `null` when it is not one. */
|
|
9609
|
+
function parseFlags(raw) {
|
|
9610
|
+
if (raw === null) return null
|
|
9611
|
+
try {
|
|
9612
|
+
const parsed = JSON.parse(raw)
|
|
9613
|
+
if (parsed === null || typeof parsed !== 'object') return null
|
|
9614
|
+
return { hover: parsed.hover === true, direct: parsed.direct === true }
|
|
9615
|
+
} catch {
|
|
9616
|
+
return null
|
|
9617
|
+
}
|
|
9618
|
+
}
|
|
9619
|
+
|
|
9620
|
+
function readFlags() {
|
|
9621
|
+
try {
|
|
9622
|
+
const own = parseFlags(localStorage.getItem(STORE_KEY))
|
|
9623
|
+
if (own !== null) return own
|
|
9624
|
+
// Keys written under the package's previous name keep the user's
|
|
9625
|
+
// choice across the rename.
|
|
9626
|
+
for (const key of LEGACY_STORE_KEYS) {
|
|
9627
|
+
const previous = parseFlags(localStorage.getItem(key))
|
|
9628
|
+
if (previous !== null) return previous
|
|
9629
|
+
}
|
|
9630
|
+
// The single-string value from before `:flags`: 'direct' meant "click
|
|
9631
|
+
// opens Settings instead of the menu", 'hover' meant "menu opens on
|
|
9632
|
+
// hover".
|
|
9633
|
+
const legacy = localStorage.getItem(LEGACY_STORE_KEY)
|
|
9634
|
+
if (legacy === 'direct') return { hover: false, direct: true }
|
|
9635
|
+
if (legacy === 'hover') return { hover: true, direct: false }
|
|
9636
|
+
} catch {
|
|
9637
|
+
// Storage may be unavailable; the defaults still apply.
|
|
9638
|
+
}
|
|
9639
|
+
return { ...DEFAULT_FLAGS }
|
|
9640
|
+
}
|
|
9641
|
+
|
|
9642
|
+
function writeFlags(next) {
|
|
9643
|
+
const value = { hover: next.hover === true, direct: next.direct === true }
|
|
9644
|
+
try {
|
|
9645
|
+
localStorage.setItem(STORE_KEY, JSON.stringify(value))
|
|
9646
|
+
localStorage.removeItem(LEGACY_STORE_KEY)
|
|
9647
|
+
// Drop the previous-name copies only after the new key is written.
|
|
9648
|
+
for (const key of LEGACY_STORE_KEYS) localStorage.removeItem(key)
|
|
9649
|
+
} catch {
|
|
9650
|
+
// A failed write leaves the previous flags in effect; report nothing.
|
|
9651
|
+
}
|
|
9652
|
+
for (const fn of flagSubscribers) {
|
|
9653
|
+
try {
|
|
9654
|
+
fn(value)
|
|
9655
|
+
} catch {
|
|
9656
|
+
// A broken subscriber must not stop the others.
|
|
9657
|
+
}
|
|
9658
|
+
}
|
|
9659
|
+
}
|
|
9660
|
+
|
|
9661
|
+
function subscribeFlags(fn) {
|
|
9662
|
+
flagSubscribers.add(fn)
|
|
9663
|
+
return () => {
|
|
9664
|
+
flagSubscribers.delete(fn)
|
|
9665
|
+
}
|
|
9666
|
+
}
|
|
9667
|
+
|
|
9668
|
+
/** One line for the plugin row and for any log message. */
|
|
9669
|
+
function flagsSummary(flags) {
|
|
9670
|
+
if (flags.hover && flags.direct) return '当前:悬浮展开菜单 + 点击进设置'
|
|
9671
|
+
if (flags.hover) return '当前:悬浮展开菜单'
|
|
9672
|
+
if (flags.direct) return '当前:点击进设置'
|
|
9673
|
+
return '当前:官方原样(点一下弹菜单)'
|
|
9674
|
+
}
|
|
9675
|
+
|
|
9676
|
+
const CSS = [
|
|
9677
|
+
'.dsd-inject{display:flex;flex-direction:column;gap:12px;margin-top:12px}',
|
|
9678
|
+
'.dsd-card{border:1px solid var(--dsw-alias-border-secondary,rgba(128,128,128,.18));',
|
|
9679
|
+
'border-radius:16px;padding:16px 20px;display:flex;flex-direction:column;gap:4px;',
|
|
9680
|
+
'background:var(--dsw-alias-bg-primary,transparent);box-sizing:border-box}',
|
|
9681
|
+
'.dsd-title{font-size:14px;color:var(--dsw-alias-label-primary)}',
|
|
9682
|
+
'.dsd-sub{font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}',
|
|
9683
|
+
'.dsd-actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:6px}',
|
|
9684
|
+
'.dsd-btn{font:inherit;font-size:13px;line-height:20px;padding:6px 14px;cursor:pointer;',
|
|
9685
|
+
'border-radius:var(--dsw-radius-md,8px);border:1px solid var(--dsw-alias-border-secondary,rgba(128,128,128,.3));',
|
|
9686
|
+
'background:transparent;color:var(--dsw-alias-label-primary)}',
|
|
9687
|
+
'.dsd-btn:hover{background:var(--dsw-alias-interactive-bg-hover)}',
|
|
9688
|
+
'.dsd-btn:disabled{opacity:.5;cursor:default}',
|
|
9689
|
+
'.dsd-btn[data-tone=danger]{color:var(--dsw-alias-state-error-primary,#e5484d);',
|
|
9690
|
+
'border-color:var(--dsw-alias-state-error-primary,#e5484d)}',
|
|
9691
|
+
'.dsd-note{font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}',
|
|
9692
|
+
// The plugin page's form: two independent rows, each its own checkbox.
|
|
9693
|
+
'.dsd-form{display:flex;flex-direction:column;gap:8px}',
|
|
9694
|
+
'.dsd-choice{display:flex;flex-direction:column;gap:10px}',
|
|
9695
|
+
'.dsd-option{display:flex;align-items:flex-start;gap:10px;cursor:pointer;',
|
|
9696
|
+
'border:1px solid var(--dsw-alias-border-secondary,rgba(128,128,128,.18));',
|
|
9697
|
+
'border-radius:var(--dsw-radius-md,8px);padding:10px 12px;background:transparent}',
|
|
9698
|
+
'.dsd-option[data-selected=true]{border-color:var(--dsw-alias-state-business-primary,#4a6cf7);',
|
|
9699
|
+
'background:var(--dsw-alias-interactive-bg-hover)}',
|
|
9700
|
+
'.dsd-option input{margin:2px 0 0;flex:none}',
|
|
9701
|
+
'.dsd-optionText{display:flex;flex-direction:column;gap:2px;min-width:0}',
|
|
9702
|
+
'.dsd-optionTitle{font-size:13px;color:var(--dsw-alias-label-primary)}',
|
|
9703
|
+
'.dsd-optionHint{font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}',
|
|
9704
|
+
].join('')
|
|
9705
|
+
|
|
9706
|
+
function ensureStyle() {
|
|
9707
|
+
if (typeof document === 'undefined') return null
|
|
9708
|
+
const existing = document.querySelector('style[' + STYLE_ATTR + ']')
|
|
9709
|
+
if (existing !== null) {
|
|
9710
|
+
if (existing.textContent !== CSS) existing.textContent = CSS
|
|
9711
|
+
return existing
|
|
9712
|
+
}
|
|
9713
|
+
const tag = document.createElement('style')
|
|
9714
|
+
tag.setAttribute(STYLE_ATTR, '1')
|
|
9715
|
+
tag.textContent = CSS
|
|
9716
|
+
document.head.appendChild(tag)
|
|
9717
|
+
return tag
|
|
9718
|
+
}
|
|
9719
|
+
|
|
9720
|
+
/**
|
|
9721
|
+
* The switch on the plugin page. The host hands a keyed
|
|
9722
|
+
* `plugins.row.config` occupant either `view: 'summary'` (the one-liner
|
|
9723
|
+
* under the row) or `view: 'page'` (this form). There is no save button: a
|
|
9724
|
+
* checkbox change is the whole edit, so the choice lands immediately and
|
|
9725
|
+
* the installer below re-runs.
|
|
9726
|
+
*/
|
|
9727
|
+
function SwitchCard(props) {
|
|
9728
|
+
const [, forceRender] = React.useReducer((count) => count + 1, 0)
|
|
9729
|
+
const [flags, setFlags] = React.useState(readFlags)
|
|
9730
|
+
React.useEffect(() => subscribeFlags((next) => { setFlags(next); forceRender() }), [])
|
|
9731
|
+
|
|
9732
|
+
if (props?.view === 'summary') {
|
|
9733
|
+
return h('span', { className: 'dsd-note' }, flagsSummary(flags))
|
|
9734
|
+
}
|
|
9735
|
+
|
|
9736
|
+
const row = (key, title, hint) =>
|
|
9737
|
+
h(
|
|
9738
|
+
'label',
|
|
9739
|
+
{ key, className: 'dsd-option', 'data-selected': flags[key] === true ? 'true' : undefined },
|
|
9740
|
+
h('input', {
|
|
9741
|
+
type: 'checkbox',
|
|
9742
|
+
checked: flags[key] === true,
|
|
9743
|
+
onChange: (event) => writeFlags({ ...flags, [key]: event.target.checked === true }),
|
|
9744
|
+
}),
|
|
9745
|
+
h(
|
|
9746
|
+
'span',
|
|
9747
|
+
{ className: 'dsd-optionText' },
|
|
9748
|
+
h('span', { className: 'dsd-optionTitle' }, title),
|
|
9749
|
+
h('span', { className: 'dsd-optionHint' }, hint),
|
|
9750
|
+
),
|
|
9751
|
+
)
|
|
9752
|
+
|
|
9753
|
+
return h(
|
|
9754
|
+
'div',
|
|
9755
|
+
{ className: 'dsd-form' },
|
|
9756
|
+
h(
|
|
9757
|
+
'fieldset',
|
|
9758
|
+
{ className: 'dsd-choice', 'aria-label': '侧栏账号入口的交互' },
|
|
9759
|
+
row(
|
|
9760
|
+
FLAG_HOVER,
|
|
9761
|
+
'悬浮展开菜单',
|
|
9762
|
+
'指针移入即展开原版菜单(设置 / 意见反馈 / 退出登录),移出收起;点击可固定。',
|
|
9763
|
+
),
|
|
9764
|
+
row(
|
|
9765
|
+
FLAG_DIRECT,
|
|
9766
|
+
'点击进设置',
|
|
9767
|
+
'点击直达设置面板;「账号与余额」页同时追加意见反馈与登录/退出登录两张卡片(与菜单内容重复,属预期)。',
|
|
9768
|
+
),
|
|
9769
|
+
h('span', { className: 'dsd-note' }, flagsSummary(flags)),
|
|
9770
|
+
),
|
|
9771
|
+
)
|
|
9772
|
+
}
|
|
9773
|
+
|
|
9774
|
+
/**
|
|
9775
|
+
* Resolve the account Remote surface. `remote.account` is the same service
|
|
9776
|
+
* path the account plugin injects; the nested form is the fallback for a
|
|
9777
|
+
* deployment that only publishes the namespace root.
|
|
9778
|
+
*/
|
|
9779
|
+
function accountService(ctx) {
|
|
9780
|
+
for (const key of ['remote.account', 'remote']) {
|
|
9781
|
+
try {
|
|
9782
|
+
const service = ctx?.get(key)
|
|
9783
|
+
if (key === 'remote') {
|
|
9784
|
+
if (service?.account !== undefined) return service.account
|
|
9785
|
+
} else if (service !== undefined && service !== null) {
|
|
9786
|
+
return service
|
|
9787
|
+
}
|
|
9788
|
+
} catch {
|
|
9789
|
+
// A missing service is a fallback, not a failure.
|
|
9790
|
+
}
|
|
9791
|
+
}
|
|
9792
|
+
return null
|
|
9793
|
+
}
|
|
9794
|
+
|
|
9795
|
+
/** Metadata the account Remote methods carry. */
|
|
9796
|
+
function clientMeta(ctx) {
|
|
9797
|
+
const locale = (() => {
|
|
9798
|
+
try {
|
|
9799
|
+
return ctx.get('locale')?.getSnapshot()?.active ?? 'zh'
|
|
9800
|
+
} catch {
|
|
9801
|
+
return 'zh'
|
|
9802
|
+
}
|
|
9803
|
+
})()
|
|
9804
|
+
return {
|
|
9805
|
+
version: '0.3.0',
|
|
9806
|
+
locale,
|
|
9807
|
+
timezoneOffsetSeconds: -new Date().getTimezoneOffset() * 60,
|
|
9808
|
+
}
|
|
9809
|
+
}
|
|
9810
|
+
|
|
9811
|
+
/**
|
|
9812
|
+
* The actions the menu holds, appended to the shipped "账号与余额" page for
|
|
9813
|
+
* the click-only combination.
|
|
9814
|
+
*
|
|
9815
|
+
* That page is owned by ui-settings-account and declares no extension slot,
|
|
9816
|
+
* so the only way in is the DOM: when the settings dialog is open and the
|
|
9817
|
+
* account row is the active section, a card block is appended to the section
|
|
9818
|
+
* column and removed again on any other section. Everything here is written
|
|
9819
|
+
* in plain DOM — React never owns these nodes, so the observer re-adds them
|
|
9820
|
+
* whenever the shell re-renders the column.
|
|
9821
|
+
*/
|
|
9822
|
+
/** Active-section text that means "the account page". */
|
|
9823
|
+
const ACCOUNT_LABELS = ['账号与余额', 'Account & balance', 'Account']
|
|
9824
|
+
|
|
9825
|
+
function buildInjectedCards(ctx) {
|
|
9826
|
+
const root = document.createElement('div')
|
|
9827
|
+
root.setAttribute(INJECT_ATTR, '1')
|
|
9828
|
+
root.className = 'dsd-inject'
|
|
9829
|
+
|
|
9830
|
+
const accountCard = document.createElement('section')
|
|
9831
|
+
accountCard.className = 'dsd-card'
|
|
9832
|
+
const accountTitle = document.createElement('div')
|
|
9833
|
+
accountTitle.className = 'dsd-title'
|
|
9834
|
+
accountTitle.textContent = '账号'
|
|
9835
|
+
const accountSub = document.createElement('div')
|
|
9836
|
+
accountSub.className = 'dsd-sub'
|
|
9837
|
+
accountSub.textContent = '正在读取账号状态…'
|
|
9838
|
+
const accountActions = document.createElement('div')
|
|
9839
|
+
accountActions.className = 'dsd-actions'
|
|
9840
|
+
accountCard.append(accountTitle, accountSub, accountActions)
|
|
9841
|
+
|
|
9842
|
+
const feedbackCard = document.createElement('section')
|
|
9843
|
+
feedbackCard.className = 'dsd-card'
|
|
9844
|
+
const feedbackTitle = document.createElement('div')
|
|
9845
|
+
feedbackTitle.className = 'dsd-title'
|
|
9846
|
+
feedbackTitle.textContent = '意见反馈'
|
|
9847
|
+
const feedbackSub = document.createElement('div')
|
|
9848
|
+
feedbackSub.className = 'dsd-sub'
|
|
9849
|
+
feedbackSub.textContent = '在浏览器中打开问卷,提交问题或建议。'
|
|
9850
|
+
const feedbackActions = document.createElement('div')
|
|
9851
|
+
feedbackActions.className = 'dsd-actions'
|
|
9852
|
+
const feedbackButton = document.createElement('button')
|
|
9853
|
+
feedbackButton.type = 'button'
|
|
9854
|
+
feedbackButton.className = 'dsd-btn'
|
|
9855
|
+
feedbackButton.textContent = '打开问卷'
|
|
9856
|
+
feedbackButton.addEventListener('click', () => {
|
|
9857
|
+
window.open(FEEDBACK_URL, '_blank', 'noopener')
|
|
9858
|
+
})
|
|
9859
|
+
feedbackActions.append(feedbackButton)
|
|
9860
|
+
feedbackCard.append(feedbackTitle, feedbackSub, feedbackActions)
|
|
9861
|
+
|
|
9862
|
+
root.append(accountCard, feedbackCard)
|
|
9863
|
+
|
|
9864
|
+
const service = accountService(ctx)
|
|
9865
|
+
|
|
9866
|
+
/**
|
|
9867
|
+
* One action button whose listeners are rebuilt whenever the account state
|
|
9868
|
+
* changes. Replacing the node keeps the old listeners from stacking up;
|
|
9869
|
+
* `actionButton` always points at the node currently in the DOM.
|
|
9870
|
+
*/
|
|
9871
|
+
let actionButton = null
|
|
9872
|
+
let busy = false
|
|
9873
|
+
|
|
9874
|
+
const setBusy = (value, text) => {
|
|
9875
|
+
busy = value
|
|
9876
|
+
if (actionButton === null) return
|
|
9877
|
+
actionButton.disabled = value
|
|
9878
|
+
if (value) actionButton.textContent = text
|
|
9879
|
+
}
|
|
9880
|
+
|
|
9881
|
+
async function onSignOut() {
|
|
9882
|
+
if (service === null || busy || actionButton === null) return
|
|
9883
|
+
const node = actionButton
|
|
9884
|
+
if (node.dataset.confirm !== '1') {
|
|
9885
|
+
node.dataset.confirm = '1'
|
|
9886
|
+
node.textContent = '确认退出'
|
|
9887
|
+
accountSub.textContent = '再点一次「确认退出」完成退出。'
|
|
9888
|
+
setTimeout(() => {
|
|
9889
|
+
if (node.dataset.confirm === '1') {
|
|
9890
|
+
node.dataset.confirm = ''
|
|
9891
|
+
paint('signed-in')
|
|
9892
|
+
}
|
|
9893
|
+
}, 5000)
|
|
9894
|
+
return
|
|
9895
|
+
}
|
|
9896
|
+
node.dataset.confirm = ''
|
|
9897
|
+
setBusy(true, '正在退出…')
|
|
9898
|
+
try {
|
|
9899
|
+
const result = await service.signOut(clientMeta(ctx))
|
|
9900
|
+
if (!result?.ok) throw new Error('sign out failed')
|
|
9901
|
+
paint('signed-out')
|
|
9902
|
+
} catch {
|
|
9903
|
+
accountSub.textContent = '退出登录失败,请稍后再试。'
|
|
9904
|
+
paint('signed-in')
|
|
9905
|
+
}
|
|
9906
|
+
}
|
|
9907
|
+
|
|
9908
|
+
async function onSignIn() {
|
|
9909
|
+
if (service === null || busy || actionButton === null) return
|
|
9910
|
+
setBusy(true, '正在登录…')
|
|
9911
|
+
try {
|
|
9912
|
+
const result = await service.startSignIn(clientMeta(ctx))
|
|
9913
|
+
if (!result?.ok) throw new Error('sign in failed')
|
|
9914
|
+
const url = result.value?.attempt?.authorizeUrl
|
|
9915
|
+
if (typeof url === 'string' && url !== '') window.open(url, '_blank', 'noopener')
|
|
9916
|
+
accountSub.textContent = '已在浏览器中打开登录页,完成后回到这里即可。'
|
|
9917
|
+
paint('signed-out')
|
|
9918
|
+
} catch {
|
|
9919
|
+
accountSub.textContent = '无法开始登录,请稍后再试。'
|
|
9920
|
+
paint('signed-out')
|
|
9921
|
+
}
|
|
9922
|
+
}
|
|
9923
|
+
|
|
9924
|
+
/** `status` is 'signed-in', 'signed-out', 'unavailable' or 'unknown'. */
|
|
9925
|
+
const paint = (status) => {
|
|
9926
|
+
busy = false
|
|
9927
|
+
if (status === 'signed-in') accountSub.textContent = '退出后不影响任何本地数据,可随时重新登录。'
|
|
9928
|
+
else if (status === 'signed-out') accountSub.textContent = '未登录。'
|
|
9929
|
+
else accountSub.textContent = '当前环境无法读取账号服务。'
|
|
9930
|
+
|
|
9931
|
+
const replacement = document.createElement('button')
|
|
9932
|
+
replacement.type = 'button'
|
|
9933
|
+
replacement.className = 'dsd-btn'
|
|
9934
|
+
if (status === 'signed-in') {
|
|
9935
|
+
replacement.textContent = '退出登录'
|
|
9936
|
+
replacement.addEventListener('click', () => { void onSignOut() })
|
|
9937
|
+
} else {
|
|
9938
|
+
replacement.textContent = '登录'
|
|
9939
|
+
if (status === 'signed-out') {
|
|
9940
|
+
replacement.addEventListener('click', () => { void onSignIn() })
|
|
9941
|
+
} else {
|
|
9942
|
+
replacement.disabled = true
|
|
9943
|
+
}
|
|
9944
|
+
}
|
|
9945
|
+
if (actionButton === null) {
|
|
9946
|
+
actionButton = replacement
|
|
9947
|
+
accountActions.append(actionButton)
|
|
9948
|
+
return
|
|
9949
|
+
}
|
|
9950
|
+
actionButton.replaceWith(replacement)
|
|
9951
|
+
actionButton = replacement
|
|
9952
|
+
}
|
|
9953
|
+
|
|
9954
|
+
paint('unknown')
|
|
9955
|
+
if (service !== null) {
|
|
9956
|
+
Promise.resolve()
|
|
9957
|
+
.then(() => service.getState())
|
|
9958
|
+
.then((result) => {
|
|
9959
|
+
if (!result?.ok) return paint('unknown')
|
|
9960
|
+
paint(result.value?.status === 'credential-stored' ? 'signed-in' : 'signed-out')
|
|
9961
|
+
})
|
|
9962
|
+
.catch(() => paint('unknown'))
|
|
9963
|
+
} else {
|
|
9964
|
+
paint('unavailable')
|
|
9965
|
+
}
|
|
9966
|
+
|
|
9967
|
+
return root
|
|
9968
|
+
}
|
|
9969
|
+
|
|
9970
|
+
/**
|
|
9971
|
+
* Keep the injected block in step with the open dialog: the shell swaps the
|
|
9972
|
+
* section column on every navigation, so the block is re-added on the account
|
|
9973
|
+
* row and dropped everywhere else.
|
|
9974
|
+
*/
|
|
9975
|
+
function installAccountCardInjector(ctx) {
|
|
9976
|
+
if (typeof document === 'undefined') return () => {}
|
|
9977
|
+
let dialog = null
|
|
9978
|
+
let dialogObserver = null
|
|
9979
|
+
let scheduled = false
|
|
9980
|
+
|
|
9981
|
+
const findDialog = () =>
|
|
9982
|
+
document.querySelector('[role="dialog"][data-shortcut-modal="settings"]')
|
|
9983
|
+
|
|
9984
|
+
/**
|
|
9985
|
+
* The selected row's label. The shell marks it with `aria-current` in some
|
|
9986
|
+
* builds and with a CSS-module `_active` class in others (the local class
|
|
9987
|
+
* suffix is stable across builds; the hashed prefix is not), so both are
|
|
9988
|
+
* accepted rather than assuming one.
|
|
9989
|
+
*/
|
|
9990
|
+
const currentLabel = (node) => {
|
|
9991
|
+
const active =
|
|
9992
|
+
node.querySelector('nav button[aria-current="true"]') ??
|
|
9993
|
+
node.querySelector('nav button[class*="_active"]')
|
|
9994
|
+
return active === null ? null : (active.textContent ?? '').trim()
|
|
9995
|
+
}
|
|
9996
|
+
|
|
9997
|
+
const sync = () => {
|
|
9998
|
+
scheduled = false
|
|
9999
|
+
const next = findDialog()
|
|
10000
|
+
if (next === null) {
|
|
10001
|
+
if (dialogObserver !== null) {
|
|
10002
|
+
dialogObserver.disconnect()
|
|
10003
|
+
dialogObserver = null
|
|
10004
|
+
}
|
|
10005
|
+
dialog = null
|
|
10006
|
+
return
|
|
10007
|
+
}
|
|
10008
|
+
if (next !== dialog) {
|
|
10009
|
+
if (dialogObserver !== null) dialogObserver.disconnect()
|
|
10010
|
+
dialog = next
|
|
10011
|
+
dialogObserver = new MutationObserver(schedule)
|
|
10012
|
+
dialogObserver.observe(next, {
|
|
10013
|
+
childList: true,
|
|
10014
|
+
subtree: true,
|
|
10015
|
+
attributes: true,
|
|
10016
|
+
// The active row is marked by `aria-current` in some builds and by a
|
|
10017
|
+
// class swap in others, so both attribute changes must re-run `sync`.
|
|
10018
|
+
attributeFilter: ['aria-current', 'class'],
|
|
10019
|
+
})
|
|
10020
|
+
}
|
|
10021
|
+
const column = dialog.querySelector('[class*="_options"]')
|
|
10022
|
+
if (column === null) return
|
|
10023
|
+
const label = currentLabel(dialog)
|
|
10024
|
+
const wanted = label !== null && ACCOUNT_LABELS.some((one) => label.includes(one))
|
|
10025
|
+
const existing = column.querySelector('[' + INJECT_ATTR + ']')
|
|
10026
|
+
if (!wanted) {
|
|
10027
|
+
if (existing !== null) existing.remove()
|
|
10028
|
+
return
|
|
10029
|
+
}
|
|
10030
|
+
if (existing !== null) return
|
|
10031
|
+
column.append(buildInjectedCards(ctx))
|
|
10032
|
+
}
|
|
10033
|
+
|
|
10034
|
+
function schedule() {
|
|
10035
|
+
if (scheduled) return
|
|
10036
|
+
scheduled = true
|
|
10037
|
+
if (typeof requestAnimationFrame === 'function') requestAnimationFrame(sync)
|
|
10038
|
+
else setTimeout(sync, 16)
|
|
10039
|
+
}
|
|
10040
|
+
|
|
10041
|
+
const bodyObserver = new MutationObserver((records) => {
|
|
10042
|
+
for (const record of records) {
|
|
10043
|
+
if (record.addedNodes.length > 0 || record.removedNodes.length > 0) {
|
|
10044
|
+
schedule()
|
|
10045
|
+
return
|
|
10046
|
+
}
|
|
10047
|
+
}
|
|
10048
|
+
})
|
|
10049
|
+
bodyObserver.observe(document.body, { childList: true })
|
|
10050
|
+
schedule()
|
|
10051
|
+
|
|
10052
|
+
return () => {
|
|
10053
|
+
bodyObserver.disconnect()
|
|
10054
|
+
if (dialogObserver !== null) dialogObserver.disconnect()
|
|
10055
|
+
for (const node of document.querySelectorAll('[' + INJECT_ATTR + ']')) node.remove()
|
|
10056
|
+
}
|
|
10057
|
+
}
|
|
10058
|
+
|
|
10059
|
+
/**
|
|
10060
|
+
* Build a caller for the shipped `settings.open` command.
|
|
10061
|
+
*
|
|
10062
|
+
* Nothing in the launcher seat hands out `openSettings` to a bystander, so
|
|
10063
|
+
* the panel is opened through the same command its own shortcut uses. The
|
|
10064
|
+
* service exposes `register` / `edit` / `describeBinding` but not a runner;
|
|
10065
|
+
* `registry` is its own plain field and `registry.invoke(id, context)` is
|
|
10066
|
+
* how a menu row runs a command. That shape is checked here rather than
|
|
10067
|
+
* assumed, and a deployment without it leaves the shipped click alone.
|
|
10068
|
+
*/
|
|
10069
|
+
function settingsInvoker(ctx) {
|
|
10070
|
+
let service = null
|
|
10071
|
+
try {
|
|
10072
|
+
service = ctx?.get('shortcuts') ?? null
|
|
10073
|
+
} catch {
|
|
10074
|
+
service = null
|
|
10075
|
+
}
|
|
10076
|
+
if (service === null) return null
|
|
10077
|
+
const registry = service.registry
|
|
10078
|
+
if (registry === null || typeof registry !== 'object') return null
|
|
10079
|
+
if (typeof registry.invoke !== 'function') return null
|
|
10080
|
+
return () => {
|
|
10081
|
+
// `settings.open` is not registered by the package itself: the settings
|
|
10082
|
+
// shell registers it inside `remoteAccess.whenAccess('settings/describe',
|
|
10083
|
+
// ...)`, which resolves asynchronously after activation. Checking
|
|
10084
|
+
// `commands.has()` at install time therefore reports "missing" on a
|
|
10085
|
+
// perfectly good build, so the check belongs here, per click.
|
|
10086
|
+
const commands = registry.commands
|
|
10087
|
+
if (typeof commands?.has === 'function' && commands.has(SETTINGS_COMMAND) === false) {
|
|
10088
|
+
return false
|
|
10089
|
+
}
|
|
10090
|
+
// `modal: null` means "no modal is covering the page"; the command
|
|
10091
|
+
// opens the panel. Passing `settings` there would close it instead.
|
|
10092
|
+
registry.invoke(SETTINGS_COMMAND, { region: 'page', modal: null })
|
|
10093
|
+
return true
|
|
10094
|
+
}
|
|
10095
|
+
}
|
|
10096
|
+
|
|
10097
|
+
/**
|
|
10098
|
+
* Attach the two behaviours to the shipped account trigger.
|
|
10099
|
+
*
|
|
10100
|
+
* Nothing is rendered and no slot is taken, so the menu keeps every bit of
|
|
10101
|
+
* its shipped appearance, keyboard behaviour, toasts, dialogs and its
|
|
10102
|
+
* `settings.launcher.notifications` stack.
|
|
10103
|
+
*
|
|
10104
|
+
* hover pointer enters the row -> click it once, if it is not open yet
|
|
10105
|
+
* pointer leaves the row -> click it again after a delay, unless
|
|
10106
|
+
* the pointer moved into the open menu
|
|
10107
|
+
* a real click -> that menu is pinned
|
|
10108
|
+
* direct a click lowers the menu if hover had raised it, then opens the
|
|
10109
|
+
* Settings panel
|
|
10110
|
+
*/
|
|
10111
|
+
function installInteraction(ctx, flags) {
|
|
10112
|
+
if (typeof document === 'undefined') return () => {}
|
|
10113
|
+
|
|
10114
|
+
const timers = { open: null, close: null }
|
|
10115
|
+
let trigger = null
|
|
10116
|
+
let menu = null
|
|
10117
|
+
/** True while our own synthetic click is running, so it is not "a click". */
|
|
10118
|
+
let synthetic = false
|
|
10119
|
+
/** A menu the user opened by clicking stays open until dismissed. */
|
|
10120
|
+
let pinned = false
|
|
10121
|
+
const openSettings = flags.direct ? settingsInvoker(ctx) : null
|
|
10122
|
+
|
|
10123
|
+
if (flags.direct && openSettings === null) {
|
|
10124
|
+
console.warn(
|
|
10125
|
+
'[dsh-settings-launcher] 拿不到 shortcuts 服务的 registry.invoke,' +
|
|
10126
|
+
'「点击进设置」这次不生效,账号入口保持官方行为。',
|
|
10127
|
+
)
|
|
10128
|
+
}
|
|
10129
|
+
|
|
10130
|
+
const clear = (name) => {
|
|
10131
|
+
if (timers[name] !== null) {
|
|
10132
|
+
clearTimeout(timers[name])
|
|
10133
|
+
timers[name] = null
|
|
10134
|
+
}
|
|
10135
|
+
}
|
|
10136
|
+
|
|
10137
|
+
const isOpen = () => trigger !== null && trigger.getAttribute('aria-expanded') === 'true'
|
|
10138
|
+
|
|
10139
|
+
const openMenu = () => {
|
|
10140
|
+
if (trigger === null || isOpen()) return
|
|
10141
|
+
synthetic = true
|
|
10142
|
+
try {
|
|
10143
|
+
trigger.click()
|
|
10144
|
+
} finally {
|
|
10145
|
+
synthetic = false
|
|
10146
|
+
}
|
|
10147
|
+
}
|
|
10148
|
+
|
|
10149
|
+
const closeMenu = () => {
|
|
10150
|
+
if (trigger === null || !isOpen()) return
|
|
10151
|
+
synthetic = true
|
|
10152
|
+
try {
|
|
10153
|
+
trigger.click()
|
|
10154
|
+
} finally {
|
|
10155
|
+
synthetic = false
|
|
10156
|
+
}
|
|
10157
|
+
}
|
|
10158
|
+
|
|
10159
|
+
/** The portal the trigger raises, so hovering it counts as "inside". */
|
|
10160
|
+
const adoptMenu = (before) => {
|
|
10161
|
+
const candidates = Array.from(document.querySelectorAll(MENU_SELECTOR))
|
|
10162
|
+
const next = candidates.find((node) => !before.has(node)) ?? null
|
|
10163
|
+
if (next === menu) return
|
|
10164
|
+
releaseMenu()
|
|
10165
|
+
menu = next
|
|
10166
|
+
if (menu !== null) {
|
|
10167
|
+
menu.addEventListener('pointerenter', onMenuEnter)
|
|
10168
|
+
menu.addEventListener('pointerleave', onMenuLeave)
|
|
10169
|
+
}
|
|
10170
|
+
}
|
|
10171
|
+
|
|
10172
|
+
function releaseMenu() {
|
|
10173
|
+
if (menu === null) return
|
|
10174
|
+
menu.removeEventListener('pointerenter', onMenuEnter)
|
|
10175
|
+
menu.removeEventListener('pointerleave', onMenuLeave)
|
|
10176
|
+
menu = null
|
|
10177
|
+
}
|
|
10178
|
+
|
|
10179
|
+
const pointerInsideMenu = () => {
|
|
10180
|
+
if (menu === null || !menu.isConnected) return false
|
|
10181
|
+
return menu.matches(':hover') || menu.contains(document.activeElement)
|
|
10182
|
+
}
|
|
10183
|
+
|
|
10184
|
+
const scheduleOpen = () => {
|
|
10185
|
+
clear('close')
|
|
10186
|
+
if (isOpen()) return
|
|
10187
|
+
clear('open')
|
|
10188
|
+
timers.open = setTimeout(() => {
|
|
10189
|
+
timers.open = null
|
|
10190
|
+
if (pinned) return
|
|
10191
|
+
const before = new Set(document.querySelectorAll(MENU_SELECTOR))
|
|
10192
|
+
openMenu()
|
|
10193
|
+
// The menu mounts after the click; adopt it once React has committed.
|
|
10194
|
+
setTimeout(() => adoptMenu(before), 0)
|
|
10195
|
+
}, OPEN_DELAY)
|
|
10196
|
+
}
|
|
10197
|
+
|
|
10198
|
+
const scheduleClose = () => {
|
|
10199
|
+
clear('open')
|
|
10200
|
+
clear('close')
|
|
10201
|
+
if (pinned) return
|
|
10202
|
+
timers.close = setTimeout(() => {
|
|
10203
|
+
timers.close = null
|
|
10204
|
+
if (pointerInsideMenu()) return
|
|
10205
|
+
closeMenu()
|
|
10206
|
+
releaseMenu()
|
|
10207
|
+
}, CLOSE_DELAY)
|
|
10208
|
+
}
|
|
10209
|
+
|
|
10210
|
+
function onMenuEnter() {
|
|
10211
|
+
clear('close')
|
|
10212
|
+
}
|
|
10213
|
+
|
|
10214
|
+
function onMenuLeave() {
|
|
10215
|
+
scheduleClose()
|
|
10216
|
+
}
|
|
10217
|
+
|
|
10218
|
+
function onEnter() {
|
|
10219
|
+
scheduleOpen()
|
|
10220
|
+
}
|
|
10221
|
+
|
|
10222
|
+
function onLeave() {
|
|
10223
|
+
scheduleClose()
|
|
10224
|
+
}
|
|
10225
|
+
|
|
10226
|
+
/**
|
|
10227
|
+
* A real click is the shipped toggle. Pin only when that click *opened*
|
|
10228
|
+
* the menu, and read the result after React has committed the new
|
|
10229
|
+
* `aria-expanded` rather than guessing it here.
|
|
10230
|
+
*/
|
|
10231
|
+
function onClick() {
|
|
10232
|
+
if (synthetic) return
|
|
10233
|
+
clear('open')
|
|
10234
|
+
clear('close')
|
|
10235
|
+
const before = isOpen()
|
|
10236
|
+
setTimeout(() => {
|
|
10237
|
+
if (isOpen() && !before) {
|
|
10238
|
+
pinned = true
|
|
10239
|
+
return
|
|
10240
|
+
}
|
|
10241
|
+
pinned = false
|
|
10242
|
+
releaseMenu()
|
|
10243
|
+
}, 0)
|
|
10244
|
+
}
|
|
10245
|
+
|
|
10246
|
+
/**
|
|
10247
|
+
* `direct`: run the settings command instead of React's menu toggle.
|
|
10248
|
+
*
|
|
10249
|
+
* Capturing on the trigger and stopping propagation keeps React's
|
|
10250
|
+
* delegated onClick (attached at the root, bubble phase) from ever seeing
|
|
10251
|
+
* the event. Our own bubble-phase `onClick` sits on this same node, so it
|
|
10252
|
+
* needs `stopImmediatePropagation` too. Because `hover` raises the menu on
|
|
10253
|
+
* pointer-enter, a click normally arrives with the menu already open; that
|
|
10254
|
+
* click lowers the menu and then opens Settings, so both switches can be
|
|
10255
|
+
* on at once. `pinned` therefore only applies to the hover-only mode.
|
|
10256
|
+
*/
|
|
10257
|
+
function onClickCapture(event) {
|
|
10258
|
+
if (openSettings === null || synthetic) return
|
|
10259
|
+
// The command may not be registered yet; when it is not, leave the
|
|
10260
|
+
// event alone so the shipped toggle still runs instead of swallowing it.
|
|
10261
|
+
if (openSettings() === false) return
|
|
10262
|
+
|
|
10263
|
+
event.preventDefault()
|
|
10264
|
+
event.stopPropagation()
|
|
10265
|
+
// Our own bubble-phase listener sits on this same node and would still
|
|
10266
|
+
// run after stopPropagation, so stop it as well.
|
|
10267
|
+
if (typeof event.stopImmediatePropagation === 'function') event.stopImmediatePropagation()
|
|
10268
|
+
clear('open')
|
|
10269
|
+
clear('close')
|
|
10270
|
+
pinned = false
|
|
10271
|
+
// With `hover` on, the pointer entering the row already raised the menu,
|
|
10272
|
+
// so a click usually arrives while it is open. Lower it first, then open
|
|
10273
|
+
// Settings — otherwise the two switches together would only be able to
|
|
10274
|
+
// close the menu and Settings would stay unreachable by mouse.
|
|
10275
|
+
if (isOpen()) {
|
|
10276
|
+
closeMenu()
|
|
10277
|
+
releaseMenu()
|
|
10278
|
+
}
|
|
10279
|
+
}
|
|
10280
|
+
|
|
10281
|
+
/** Pin release: outside pointerdown, Escape, or the menu closing itself. */
|
|
10282
|
+
function onDocumentPointerDown(event) {
|
|
10283
|
+
if (!pinned) return
|
|
10284
|
+
if (trigger !== null && trigger.contains(event.target)) return
|
|
10285
|
+
if (menu !== null && menu.contains(event.target)) return
|
|
10286
|
+
pinned = false
|
|
10287
|
+
}
|
|
10288
|
+
|
|
10289
|
+
function onDocumentKeyDown(event) {
|
|
10290
|
+
if (event.key === 'Escape' && pinned) pinned = false
|
|
10291
|
+
}
|
|
10292
|
+
|
|
10293
|
+
/**
|
|
10294
|
+
* Announce the real behaviour. With `direct` alone the menu cannot be
|
|
10295
|
+
* opened at all, so keeping `aria-haspopup="menu"` would promise a menu
|
|
10296
|
+
* that never appears; with `hover` on as well the menu is still reachable
|
|
10297
|
+
* and the shipped value stays right.
|
|
10298
|
+
*/
|
|
10299
|
+
const applyAria = (node) => {
|
|
10300
|
+
if (node === null) return
|
|
10301
|
+
if (flags.direct && !flags.hover) node.setAttribute('aria-haspopup', 'dialog')
|
|
10302
|
+
}
|
|
10303
|
+
|
|
10304
|
+
const restoreAria = (node) => {
|
|
10305
|
+
if (node === null) return
|
|
10306
|
+
if (flags.direct && !flags.hover) node.setAttribute('aria-haspopup', 'menu')
|
|
10307
|
+
}
|
|
10308
|
+
|
|
10309
|
+
const bind = () => {
|
|
10310
|
+
const next = document.querySelector(TRIGGER_SELECTOR)
|
|
10311
|
+
if (next === trigger) return
|
|
10312
|
+
if (trigger !== null) {
|
|
10313
|
+
trigger.removeEventListener('pointerenter', onEnter)
|
|
10314
|
+
trigger.removeEventListener('pointerleave', onLeave)
|
|
10315
|
+
trigger.removeEventListener('click', onClick)
|
|
10316
|
+
trigger.removeEventListener('click', onClickCapture, true)
|
|
10317
|
+
restoreAria(trigger)
|
|
10318
|
+
}
|
|
10319
|
+
trigger = next
|
|
10320
|
+
pinned = false
|
|
10321
|
+
releaseMenu()
|
|
10322
|
+
if (trigger === null) return
|
|
10323
|
+
if (flags.hover) {
|
|
10324
|
+
trigger.addEventListener('pointerenter', onEnter)
|
|
10325
|
+
trigger.addEventListener('pointerleave', onLeave)
|
|
10326
|
+
trigger.addEventListener('click', onClick)
|
|
10327
|
+
}
|
|
10328
|
+
if (openSettings !== null) trigger.addEventListener('click', onClickCapture, true)
|
|
10329
|
+
applyAria(trigger)
|
|
10330
|
+
}
|
|
10331
|
+
|
|
10332
|
+
const observer = new MutationObserver(() => {
|
|
10333
|
+
bind()
|
|
10334
|
+
// The menu unmounts on close; drop the reference so a reopen re-adopts.
|
|
10335
|
+
if (menu !== null && !isOpen()) releaseMenu()
|
|
10336
|
+
})
|
|
10337
|
+
observer.observe(document.body, { childList: true, subtree: true })
|
|
10338
|
+
bind()
|
|
10339
|
+
|
|
10340
|
+
document.addEventListener('pointerdown', onDocumentPointerDown, true)
|
|
10341
|
+
document.addEventListener('keydown', onDocumentKeyDown, true)
|
|
10342
|
+
|
|
10343
|
+
return () => {
|
|
10344
|
+
clear('open')
|
|
10345
|
+
clear('close')
|
|
10346
|
+
observer.disconnect()
|
|
10347
|
+
document.removeEventListener('pointerdown', onDocumentPointerDown, true)
|
|
10348
|
+
document.removeEventListener('keydown', onDocumentKeyDown, true)
|
|
10349
|
+
if (trigger !== null) {
|
|
10350
|
+
trigger.removeEventListener('pointerenter', onEnter)
|
|
10351
|
+
trigger.removeEventListener('pointerleave', onLeave)
|
|
10352
|
+
trigger.removeEventListener('click', onClick)
|
|
10353
|
+
trigger.removeEventListener('click', onClickCapture, true)
|
|
10354
|
+
restoreAria(trigger)
|
|
10355
|
+
}
|
|
10356
|
+
releaseMenu()
|
|
10357
|
+
}
|
|
10358
|
+
}
|
|
10359
|
+
|
|
10360
|
+
return {
|
|
10361
|
+
inject: ['slots', 'remote.account'],
|
|
10362
|
+
// The switches are also readable from outside this bundle: the aggregator
|
|
10363
|
+
// that vendors this file renders the same card (never a copy) and injects
|
|
10364
|
+
// the same stylesheet, so the two surfaces cannot drift.
|
|
10365
|
+
__settings: { SwitchCard },
|
|
10366
|
+
__ui: { pluginId: NS, css: () => CSS },
|
|
10367
|
+
apply(ctx) {
|
|
10368
|
+
// ctx.effect 要的是一个 cleanup 函数;ensureStyle() 返回的是 <style>
|
|
10369
|
+
// 元素,直接返回会让 Cordis 在激活时拿到非函数值而把 fiber 判为 failed。
|
|
10370
|
+
ctx.effect(() => {
|
|
10371
|
+
const tag = ensureStyle()
|
|
10372
|
+
return () => {
|
|
10373
|
+
if (tag !== null) tag.remove()
|
|
10374
|
+
}
|
|
10375
|
+
}, NS + ': stylesheet')
|
|
10376
|
+
|
|
10377
|
+
// Both switches are read on every install, so a checkbox change tears
|
|
10378
|
+
// the running behaviour down and builds the next one without a reload.
|
|
10379
|
+
ctx.effect(() => {
|
|
10380
|
+
let dispose = null
|
|
10381
|
+
const install = () => {
|
|
10382
|
+
if (dispose !== null) {
|
|
10383
|
+
try {
|
|
10384
|
+
dispose()
|
|
10385
|
+
} catch {
|
|
10386
|
+
// Rebuilding anyway; a failed teardown is not fatal.
|
|
10387
|
+
}
|
|
10388
|
+
dispose = null
|
|
10389
|
+
}
|
|
10390
|
+
const flags = readFlags()
|
|
10391
|
+
const releases = [installInteraction(ctx, flags)]
|
|
10392
|
+
// With `direct` the card is always injected, including when the
|
|
10393
|
+
// menu is also reachable through hover. That repeats 意见反馈 and
|
|
10394
|
+
// 退出登录 on the account page, which is the intended trade: the
|
|
10395
|
+
// page looks the same however the menu was opened.
|
|
10396
|
+
if (flags.direct) releases.push(installAccountCardInjector(ctx))
|
|
10397
|
+
dispose = () => {
|
|
10398
|
+
for (const release of releases) {
|
|
10399
|
+
try {
|
|
10400
|
+
release()
|
|
10401
|
+
} catch {
|
|
10402
|
+
// One failed cleanup must not skip the others.
|
|
10403
|
+
}
|
|
10404
|
+
}
|
|
10405
|
+
}
|
|
10406
|
+
}
|
|
10407
|
+
install()
|
|
10408
|
+
const off = subscribeFlags(install)
|
|
10409
|
+
return () => {
|
|
10410
|
+
off()
|
|
10411
|
+
if (dispose !== null) {
|
|
10412
|
+
try {
|
|
10413
|
+
dispose()
|
|
10414
|
+
} catch {
|
|
10415
|
+
// Nothing left to report on teardown failure.
|
|
10416
|
+
}
|
|
10417
|
+
dispose = null
|
|
10418
|
+
}
|
|
10419
|
+
}
|
|
10420
|
+
}, NS + ': behaviours')
|
|
10421
|
+
|
|
10422
|
+
// The plugin page's switches; independent of what is running.
|
|
10423
|
+
ctx.effect(() => {
|
|
10424
|
+
try {
|
|
10425
|
+
return ctx.slots.inject('plugins.row.config', () =>
|
|
10426
|
+
ctx.slots.register({ name: 'plugins.row.config', key: ROW_CONFIG_KEY }, SwitchCard),
|
|
10427
|
+
)
|
|
10428
|
+
} catch (error) {
|
|
10429
|
+
console.warn('[dsh-settings-launcher] 无法挂载插件页开关:', error)
|
|
10430
|
+
return undefined
|
|
10431
|
+
}
|
|
10432
|
+
}, NS + ': row config')
|
|
10433
|
+
},
|
|
10434
|
+
}
|
|
10435
|
+
}
|
|
10436
|
+
|
|
9508
10437
|
// --- which factories this plugin mounts ---
|
|
9509
|
-
const VENDORED_TABLE = { "dsh-delete-session": factory_dsh_delete_session, "dsh-session-relocate": factory_dsh_session_relocate, "dsh-session-rename-dblclick": factory_dsh_session_rename_dblclick, "dsh-session-counts": factory_dsh_session_counts, "dsh-declutter": factory_dsh_declutter }
|
|
10438
|
+
const VENDORED_TABLE = { "dsh-delete-session": factory_dsh_delete_session, "dsh-session-relocate": factory_dsh_session_relocate, "dsh-session-rename-dblclick": factory_dsh_session_rename_dblclick, "dsh-session-counts": factory_dsh_session_counts, "dsh-declutter": factory_dsh_declutter, "dsh-settings-launcher": factory_dsh_settings_launcher }
|
|
9510
10439
|
|
|
9511
10440
|
// --- this plugin's own browser half ---
|
|
9512
10441
|
|
|
@@ -9521,7 +10450,7 @@ window.__ModuleLoader__.load({
|
|
|
9521
10450
|
const NS = 'dsh-better-sidebar-left'
|
|
9522
10451
|
|
|
9523
10452
|
/** Keep in sync with package.json and src/components.js. */
|
|
9524
|
-
const PLUGIN_VERSION = '0.
|
|
10453
|
+
const PLUGIN_VERSION = '0.3.0'
|
|
9525
10454
|
|
|
9526
10455
|
/** Presence marker the live verifier reads. */
|
|
9527
10456
|
const DEBUG_KEY = '__DSH_BETTER_SIDEBAR_LEFT__'
|
|
@@ -9536,6 +10465,7 @@ window.__ModuleLoader__.load({
|
|
|
9536
10465
|
'dsh-session-rename-dblclick',
|
|
9537
10466
|
'dsh-session-counts',
|
|
9538
10467
|
'dsh-declutter',
|
|
10468
|
+
'dsh-settings-launcher',
|
|
9539
10469
|
]
|
|
9540
10470
|
|
|
9541
10471
|
/**
|
|
@@ -9738,6 +10668,22 @@ window.__ModuleLoader__.load({
|
|
|
9738
10668
|
"zh": "两半合一:①会话内收纳 —— 失败轮、空轮、编辑产生的合成轮按规则表收起,只加 data-dshdc-* 视图属性,完全可逆,绝不改日志;②侧栏整理 —— 藏品牌行/「新会话」/「更多」/顶部空隙,面板显隐与排序。",
|
|
9739
10669
|
"en": "Two halves in one: (1) in-conversation collapsing - failed, empty and synthesised turns fold away per a rule table, using data-dshdc-* view attributes only, fully reversible, never touching the log; (2) sidebar tidying - hides the brand row, the New session button, the More buttons and the top gap, plus panel visibility and order."
|
|
9740
10670
|
}
|
|
10671
|
+
},
|
|
10672
|
+
{
|
|
10673
|
+
"id": "dsh-settings-launcher",
|
|
10674
|
+
"package": "dsh-settings-launcher",
|
|
10675
|
+
"suffix": "launcher",
|
|
10676
|
+
"feature": "launcher",
|
|
10677
|
+
"kind": "maintenance",
|
|
10678
|
+
"repo": "https://github.com/DDDMUC/dsh-settings-launcher",
|
|
10679
|
+
"title": {
|
|
10680
|
+
"zh": "账号入口",
|
|
10681
|
+
"en": "Account entry"
|
|
10682
|
+
},
|
|
10683
|
+
"pitch": {
|
|
10684
|
+
"zh": "侧栏账号入口的两个独立开关:悬浮自动展开原版菜单、点击直达设置;两个都关就是官方原样。",
|
|
10685
|
+
"en": "Two independent switches for the sidebar account entry: auto-expand the stock menu on hover, and go straight to Settings on click. Both off is the stock behaviour."
|
|
10686
|
+
}
|
|
9741
10687
|
}
|
|
9742
10688
|
]
|
|
9743
10689
|
|
|
@@ -9865,6 +10811,11 @@ window.__ModuleLoader__.load({
|
|
|
9865
10811
|
"component": "dsh-declutter",
|
|
9866
10812
|
"name": "plugins.row.config",
|
|
9867
10813
|
"key": "dsh-declutter#dsh-declutter"
|
|
10814
|
+
},
|
|
10815
|
+
{
|
|
10816
|
+
"component": "dsh-settings-launcher",
|
|
10817
|
+
"name": "plugins.row.config",
|
|
10818
|
+
"key": "dsh-settings-launcher#settings-launcher"
|
|
9868
10819
|
}
|
|
9869
10820
|
],
|
|
9870
10821
|
"settingsCards": [
|
|
@@ -9879,6 +10830,10 @@ window.__ModuleLoader__.load({
|
|
|
9879
10830
|
{
|
|
9880
10831
|
"component": "dsh-session-relocate",
|
|
9881
10832
|
"exportPath": "__settings.ChildrenSetting"
|
|
10833
|
+
},
|
|
10834
|
+
{
|
|
10835
|
+
"component": "dsh-settings-launcher",
|
|
10836
|
+
"exportPath": "__settings.SwitchCard"
|
|
9882
10837
|
}
|
|
9883
10838
|
]
|
|
9884
10839
|
}
|
|
@@ -9928,12 +10883,19 @@ window.__ModuleLoader__.load({
|
|
|
9928
10883
|
if (typeof document === 'undefined' || typeof document.querySelector !== 'function') return
|
|
9929
10884
|
const style = document.querySelector('style[data-dsh-better-sidebar-left]')
|
|
9930
10885
|
if (style !== null && style.parentNode !== null) style.parentNode.removeChild(style)
|
|
10886
|
+
const cards = typeof document.querySelectorAll === 'function'
|
|
10887
|
+
? document.querySelectorAll('style[data-dsh-better-sidebar-left-css]')
|
|
10888
|
+
: []
|
|
10889
|
+
for (let index = 0; index < cards.length; index += 1) {
|
|
10890
|
+
if (cards[index].parentNode !== null) cards[index].parentNode.removeChild(cards[index])
|
|
10891
|
+
}
|
|
10892
|
+
injectedCss.clear()
|
|
9931
10893
|
}
|
|
9932
10894
|
|
|
9933
10895
|
// --- mounting the vendored halves -------------------------------------------
|
|
9934
10896
|
|
|
9935
10897
|
function vendoredFactory(id) {
|
|
9936
|
-
// tools/build.mjs declares VENDORED_TABLE with the
|
|
10898
|
+
// tools/build.mjs declares VENDORED_TABLE with the six stitched factories;
|
|
9937
10899
|
// running this file on its own (its own unit tests) has none, and mounts
|
|
9938
10900
|
// nothing, which is exactly the "nothing vendored" case.
|
|
9939
10901
|
if (typeof VENDORED_TABLE === 'undefined') return null
|
|
@@ -9996,12 +10958,57 @@ window.__ModuleLoader__.load({
|
|
|
9996
10958
|
* returned is the component's own, so its state, storage keys and copy are the
|
|
9997
10959
|
* ones its own page uses.
|
|
9998
10960
|
*/
|
|
10961
|
+
/** Component ids whose stylesheet this page has already injected. */
|
|
10962
|
+
const injectedCss = new Set()
|
|
10963
|
+
|
|
10964
|
+
/**
|
|
10965
|
+
* Inject the stylesheet a vendored component ships for its own settings card.
|
|
10966
|
+
*
|
|
10967
|
+
* A component injects its sheet from its apply(), which only runs when its row is
|
|
10968
|
+
* mounted. This page renders the card of a component whose row may be disabled
|
|
10969
|
+
* (the gate says so, and the card is still the place a reader turns the feature
|
|
10970
|
+
* on), so the sheet has to be asked for here - otherwise the card renders as raw
|
|
10971
|
+
* DOM: an invisible switch, unstyled segmented buttons, a link that runs into
|
|
10972
|
+
* its label. Components that export no css() supply their styling another way
|
|
10973
|
+
* (platform primitives) and are left alone.
|
|
10974
|
+
*/
|
|
10975
|
+
function injectComponentStyles(id, plugin) {
|
|
10976
|
+
if (typeof document === 'undefined' || typeof document.createElement !== 'function') return
|
|
10977
|
+
const ui = plugin === null || plugin === undefined ? undefined : plugin.__ui
|
|
10978
|
+
if (ui === null || ui === undefined || typeof ui.css !== 'function') return
|
|
10979
|
+
const attribute = 'data-dsh-better-sidebar-left-css'
|
|
10980
|
+
if (injectedCss.has(id) === true) return
|
|
10981
|
+
let css
|
|
10982
|
+
try {
|
|
10983
|
+
css = ui.css()
|
|
10984
|
+
} catch (error) {
|
|
10985
|
+
console.error('[' + NS + '] vendored ' + id + ' stylesheet could not be read:', error)
|
|
10986
|
+
return
|
|
10987
|
+
}
|
|
10988
|
+
if (typeof css !== 'string' || css === '') return
|
|
10989
|
+
// The component injects the very same text from its own apply(); adding a
|
|
10990
|
+
// second copy would double every rule, including the ones with transitions.
|
|
10991
|
+
const existing = typeof document.querySelectorAll === 'function' ? document.querySelectorAll('style') : []
|
|
10992
|
+
for (let index = 0; index < existing.length; index += 1) {
|
|
10993
|
+
if (existing[index].textContent === css) {
|
|
10994
|
+
injectedCss.add(id)
|
|
10995
|
+
return
|
|
10996
|
+
}
|
|
10997
|
+
}
|
|
10998
|
+
const style = document.createElement('style')
|
|
10999
|
+
style.setAttribute(attribute, id)
|
|
11000
|
+
style.textContent = css
|
|
11001
|
+
document.head.appendChild(style)
|
|
11002
|
+
injectedCss.add(id)
|
|
11003
|
+
}
|
|
11004
|
+
|
|
9999
11005
|
function vendoredConfigCard(id) {
|
|
10000
11006
|
const entry = CONFIG_CARDS.filter((candidate) => candidate.id === id)[0]
|
|
10001
11007
|
if (entry === undefined) return null
|
|
10002
11008
|
try {
|
|
10003
11009
|
const plugin = appliedModules[id] !== undefined ? appliedModules[id] : vendoredModule(id)
|
|
10004
11010
|
if (plugin === null || plugin === undefined) return null
|
|
11011
|
+
injectComponentStyles(id, plugin)
|
|
10005
11012
|
let value = plugin
|
|
10006
11013
|
for (let index = 0; index < entry.path.length; index += 1) {
|
|
10007
11014
|
value = value === null || value === undefined ? undefined : value[entry.path[index]]
|
|
@@ -10357,6 +11364,9 @@ window.__ModuleLoader__.load({
|
|
|
10357
11364
|
exports.LeftRailPage = LeftRailPage
|
|
10358
11365
|
exports.LeftRailIcon = LeftRailIcon
|
|
10359
11366
|
exports.railLabel = railLabel
|
|
11367
|
+
// Test-only entry: the injection runs from vendoredConfigCard, which no test
|
|
11368
|
+
// reaches without a rendered page.
|
|
11369
|
+
exports.__componentStyles = injectComponentStyles
|
|
10360
11370
|
exports.stateOf = stateOf
|
|
10361
11371
|
exports.shouldMount = shouldMount
|
|
10362
11372
|
exports.mountableComponents = mountableComponents
|