From ee85533bd14c746308a75f141cb16b102b269eda Mon Sep 17 00:00:00 2001 From: Mute Date: Tue, 3 Sep 2024 16:34:24 +0000 Subject: [PATCH 1/5] additional keys for history mode --- ambient.d.ts | 16 +++++++++++++--- mbchc.mjs | 23 ++++++++++++++--------- server.js | 3 ++- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/ambient.d.ts b/ambient.d.ts index c5c7f58..b0545e2 100644 --- a/ambient.d.ts +++ b/ambient.d.ts @@ -349,7 +349,7 @@ interface Utils { complete_do_target(actions: {self: unknown, others: unknown}): Set complete_do(this: Optional): undefined replace_me(_match: string, _offset: number, whole: string): string - //pad_chat(chat: HTMLDivElement): undefined + scroll(): true } interface Complete { @@ -445,15 +445,25 @@ interface InputHistory { */ ids: Set | undefined + /** + * Specific key handlers. + */ + key: Record true> + + /** + * Set or unset the readonly mode on the input. + */ + icro(textarea: HTMLTextAreaElement, readonly: boolean): true + /** * Enter the history mode. */ enter(textarea: HTMLTextAreaElement, input: string, bottom: boolean, ids: Set): true /** - * Exit the history mode and optionally restore original input. + * Exit the history mode and proc the key event. */ - exit(textarea: HTMLTextAreaElement, restore_input: boolean): true + exit(textarea: HTMLTextAreaElement, key: KeyboardEvent['key']): true } // FIXME spread around readonly where appropriate diff --git a/mbchc.mjs b/mbchc.mjs index a87ebe0..2ea0126 100644 --- a/mbchc.mjs +++ b/mbchc.mjs @@ -158,7 +158,7 @@ const/**@type {Utils}*/U = { remove_loader_hook: $, RGB: {Polly: '#81b1e7', Mute return $Ss })}, replace_me: (_, __, whole) => cur(whole.slice(1), t => `${U.ACT}<${U.cid(W.Player)}:>SourceCharacter${t.startsWith('\'') || t.startsWith(' ') ? $S : ' '}`), - //pad_chat: c => loo(100, _ => c.scrollHeight <= c.clientHeight, _ => yes(void c.prepend(U.mkdiv('\u061C')))) && void W.ElementScrollToEnd('TextAreaChatLog') + scroll: () => yes(void W.ElementScrollToEnd('TextAreaChatLog')), } const/**@type {SUBCOMMANDS}*/SUBCOMMANDS_MBCHC = { @@ -178,7 +178,7 @@ const/**@type {Complete}*/C = { S_OPTS: {behavior: 'instant'}, hint: cs => m_t(cs) || yes(_ => { yes(C.e.style.display = 'block') && C.div?.replaceChildren(...[...cs].sort().reverse().map(U.mkdiv)) W.ElementSetDataAttribute(C.e.id, 'colortheme', W.Player.ChatSettings?.ColorTheme ?? 'Light') - cur(W.ElementIsScrolledToEnd('TextAreaChatLog'), r => yes(void W.ChatRoomResize(false)) && r && void W.ElementScrollToEnd('TextAreaChatLog')) + cur(W.ElementIsScrolledToEnd('TextAreaChatLog'), r => yes(void W.ChatRoomResize(false)) && r && U.scroll()) C.div?.lastElementChild?.scrollIntoView(C.S_OPTS) }), get hidden() {return C.e.parentElement === null || C.e.style.display === 'none'}, @@ -203,8 +203,13 @@ const/**@type {Complete}*/C = { S_OPTS: {behavior: 'instant'}, } const/**@type {InputHistory}*/H = { input: undefined, ids: undefined, bottom: undefined, // FIXME ids don't need to be a set, but I'm too tired right now - enter: (ic, i, b, is) => yes(H.input = i, H.bottom = b, H.ids = is, ic.readOnly = true, val(ic.parentElement?.parentElement?.dataset, d => d['mbchcMode'] = 'h'), b && void W.ElementScrollToEnd('TextAreaChatLog')), - exit: (ic, r) => yes(ic.readOnly = false, val(ic.parentElement?.parentElement?.dataset, d => del(d, 'mbchcMode')), r && val(H.input, i => ic.value = i), val(H.bottom, b => b && void W.ElementScrollToEnd('TextAreaChatLog')), W.ChatRoomLastMessageIndex = W.ChatRoomLastMessage.length) + key: { + Escape: ic => yes(val(H.input, i => ic.value = i)), + ArrowLeft: ic => yes(void ic.setSelectionRange(0, 0)), + }, + icro: (ic, ro) => yes(ic.readOnly = ro, val(ic.parentElement?.parentElement?.dataset, d => ro ? d['mbchcMode'] = 'h' : del(d, 'mbchcMode'))), + enter: (ic, i, b, is) => yes(H.input = i, H.bottom = b, H.ids = is, H.icro(ic, true), b && U.scroll()), + exit: (ic, k) => yes(H.icro(ic, false), H.key[k]?.(ic), val(H.bottom, b => b && U.scroll()), W.ChatRoomLastMessageIndex = W.ChatRoomLastMessage.length) } ass('MBCHC found, aborting loading', W.MBCHC === $) @@ -475,7 +480,7 @@ const/**@type {SDK.Hook}*/after = (name, f) => mod.hookFunction(name, 0, (na, n) // W.ElementSetDataAttribute(this.COMP_HINT.id, 'colortheme', (W.Player.ChatSettings?.ColorTheme || 'Light')) // const rescroll = W.ElementIsScrolledToEnd('TextAreaChatLog') // W.ChatRoomResize(false) - // if (rescroll) W.ElementScrollToEnd('TextAreaChatLog') + // if (rescroll) U.scroll() // this.COMP_HINT.firstChild?.lastChild?.scrollIntoView({behaviour: 'instant'}) //}, @@ -585,7 +590,7 @@ const/**@type {SDK.Hook}*/after = (name, f) => mod.hookFunction(name, 0, (na, n) #${C.e.id}[data-colortheme^="dark"] > div { background-color: ${U.RGB.Mute}; color: white; } #${C.e.id} > div div { margin: 0.25ex 0; } #chat-room-div #TextAreaChatLog::before { content: ''; display: block; height: 100%; } - #chat-room-div[data-mbchc-mode="h"] #TextAreaChatLog::after { content: 'π—΅π—Άπ˜€π˜π—Όπ—Ώπ˜† βŸ¨π˜—π˜¨π˜œπ˜±/π˜‹π˜―βŸ© π—Œπ–Όπ—‹π—ˆπ—…π—… β‡… ⟨𝘌𝘯𝘡𝘦𝘳⟩ π—Œπ–Ύπ—‡π–½ ↡ βŸ¨π˜›π˜’π˜£βŸ© 𝖾𝖽𝗂𝗍 ⌨ ⟨𝘌𝘴𝘀⟩ π–Ίπ–»π—ˆπ—‹π— ⟲'; display: block; position: sticky; bottom: 0; background: black; color: orange; padding: 0 0.2ex; animation: 0.2s cubic-bezier(0.19, 1, 0.22, 1) mbchc_hist_hint_show; } + #chat-room-div[data-mbchc-mode="h"] #TextAreaChatLog::after { content: 'π—΅π—Άπ˜€π˜π—Όπ—Ώπ˜† βŸ¨π˜—π˜¨π˜œπ˜±/π˜‹π˜―/β†•βŸ© π—Œπ–Όπ—‹π—ˆπ—…π—… β‡… ⟨𝘌𝘯𝘡𝘦𝘳⟩ π—Œπ–Ύπ—‡π–½ ↡ βŸ¨π˜›π˜’π˜£/β†”βŸ© 𝖾𝖽𝗂𝗍 ⌨ ⟨𝘌𝘴𝘀⟩ π–Ίπ–»π—ˆπ—‹π— ⟲'; display: block; position: sticky; bottom: 0; background: black; color: orange; padding: 0 0.2ex; animation: 0.2s cubic-bezier(0.19, 1, 0.22, 1) mbchc_hist_hint_show; } #InputChat:read-only { background: black; color: orange; } @keyframes mbchc_hist_hint_show { from {transform: translateX(-100%);} to {transform: translateX(0);} } `) @@ -630,11 +635,11 @@ const/**@type {SDK.Hook}*/after = (name, f) => mod.hookFunction(name, 0, (na, n) C.hide() const ic = this // eslint-disable-line unicorn/no-this-assignment,@typescript-eslint/no-this-alias if (ic.readOnly) switch (e.key) { - case 'Tab': case 'Escape': + case 'ArrowUp': case 'ArrowDown': W.ChatRoomScrollHistory(e.key === 'ArrowUp'); break + case 'Escape': case 'Tab': case 'ArrowRight': case 'ArrowLeft': e.stopImmediatePropagation() e.preventDefault() // falls through - case 'Enter': - H.exit(ic, e.key === 'Escape') // no default + case 'Enter': H.exit(ic, e.key) // no default } } after('ChatRoomCreateElement', () => { // This thing runs on every frame actually. diff --git a/server.js b/server.js index 803dffb..6df9882 100644 --- a/server.js +++ b/server.js @@ -24,7 +24,8 @@ const h_all = { } const server = createServer((rq, rx) => { - rq.method !== undefined && resp[rq.method] !== undefined && (new URL(`http://${config.host}:${config.port}${rq.url}`)).pathname === '/' ? resp[rq.method](rx) : rx.writeHead(400) + const handler = resp[rq.method ?? ''] + handler !== undefined && (new URL(`http://${config.host}:${config.port}${rq.url}`)).pathname === '/' ? handler(rx) : rx.writeHead(400) rx.end(() => void console.log('%s %d %s %s', (new Date()).toISOString(), rx.statusCode, rq.method, rq.url)) }) server.listen(config.port, config.host, () => void console.log(`Server started at http://${config.host}:${config.port} for ${config.filename}`)) From fb700c91cfb9b26ad5ed7c8235629c37f3e31efd Mon Sep 17 00:00:00 2001 From: Mute Date: Wed, 4 Sep 2024 15:30:03 +0000 Subject: [PATCH 2/5] better history hint --- mbchc.mjs | 8 ++++++-- package.json | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/mbchc.mjs b/mbchc.mjs index 2ea0126..0595c6a 100644 --- a/mbchc.mjs +++ b/mbchc.mjs @@ -590,9 +590,12 @@ const/**@type {SDK.Hook}*/after = (name, f) => mod.hookFunction(name, 0, (na, n) #${C.e.id}[data-colortheme^="dark"] > div { background-color: ${U.RGB.Mute}; color: white; } #${C.e.id} > div div { margin: 0.25ex 0; } #chat-room-div #TextAreaChatLog::before { content: ''; display: block; height: 100%; } - #chat-room-div[data-mbchc-mode="h"] #TextAreaChatLog::after { content: 'π—΅π—Άπ˜€π˜π—Όπ—Ώπ˜† βŸ¨π˜—π˜¨π˜œπ˜±/π˜‹π˜―/β†•βŸ© π—Œπ–Όπ—‹π—ˆπ—…π—… β‡… ⟨𝘌𝘯𝘡𝘦𝘳⟩ π—Œπ–Ύπ—‡π–½ ↡ βŸ¨π˜›π˜’π˜£/β†”βŸ© 𝖾𝖽𝗂𝗍 ⌨ ⟨𝘌𝘴𝘀⟩ π–Ίπ–»π—ˆπ—‹π— ⟲'; display: block; position: sticky; bottom: 0; background: black; color: orange; padding: 0 0.2ex; animation: 0.2s cubic-bezier(0.19, 1, 0.22, 1) mbchc_hist_hint_show; } + #chat-room-div[data-mbchc-mode="h"] #TextAreaChatLog::after { + content: 'π—΅π—Άπ˜€π˜π—Όπ—Ώπ˜† βŸ¨π˜—π˜¨π˜œπ˜±/π˜‹π˜―/β†•βŸ© π—Œπ–Όπ—‹π—ˆπ—…π—… β‡… ⟨𝘌𝘯𝘡𝘦𝘳⟩ π—Œπ–Ύπ—‡π–½ ↡ βŸ¨π˜›π˜’π˜£/β†”βŸ© 𝖾𝖽𝗂𝗍 ⌨ ⟨𝘌𝘴𝘀⟩ π–Ίπ–»π—ˆπ—‹π— ⟲\\A' attr(data-mbchc-h-h); whitespace: pre; + display: block; position: sticky; z-index: 1; bottom: 0; background: black; color: orange; padding: 0 0.2ex; animation: 0.2s cubic-bezier(0.19, 1, 0.22, 1) mbchc_hh_show; + } #InputChat:read-only { background: black; color: orange; } - @keyframes mbchc_hist_hint_show { from {transform: translateX(-100%);} to {transform: translateX(0);} } + @keyframes mbchc_hh_show { from {transform: translateX(-100%);} to {transform: translateX(0);} } `) // Actions @@ -672,6 +675,7 @@ const/**@type {SDK.Hook}*/after = (name, f) => mod.hookFunction(name, 0, (na, n) const/**@type {Map}*/map = new Map() const/**@type {(l: string, i: number, I: string) => boolean}*/ cond = m_t(input) ? (_, i, __) => i > 0 : (l, _, i) => l !== i && l.startsWith(i) if (m_t(history.reduce((ax, l, i) => cond(l, i, input) ? ax.set(l, i) : ax, map))) return U.bell() + val(asa(HTMLDivElement, D.querySelector('#TextAreaChatLog')), t => t.dataset['mbchcHH'] = m_t(input) ? 'All history' : `Prefix: ${input}`) H.enter(ic, input, W.ElementIsScrolledToEnd('TextAreaChatLog'), new Set(map.values())) } if (ic.readOnly) { // this can't be an else, because we mutate state above. To be honest, this will always be true, but I want to make sure. diff --git a/package.json b/package.json index 1074145..6b6577c 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "brace-style": "off", "camelcase": "off", "capitalized-comments": "off", + "complexity": "off", "curly": "off", "generator-star-spacing": "off", "max-nested-callbacks": "off", From b9b1226e60ed6971bec0008e618c66f8e0a6eaf3 Mon Sep 17 00:00:00 2001 From: Mute Date: Fri, 6 Sep 2024 21:34:29 +0000 Subject: [PATCH 3/5] history improvements: backspace passthrough, hint rearranged --- ambient.d.ts | 6 ++++-- mbchc.mjs | 26 ++++++++++++++------------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/ambient.d.ts b/ambient.d.ts index b0545e2..da320fa 100644 --- a/ambient.d.ts +++ b/ambient.d.ts @@ -350,6 +350,8 @@ interface Utils { complete_do(this: Optional): undefined replace_me(_match: string, _offset: number, whole: string): string scroll(): true + get scrolled(): boolean + rescroll(func: (_: undefined) => unknown): true } interface Complete { @@ -448,7 +450,7 @@ interface InputHistory { /** * Specific key handlers. */ - key: Record true> + key: Record true> /** * Set or unset the readonly mode on the input. @@ -463,7 +465,7 @@ interface InputHistory { /** * Exit the history mode and proc the key event. */ - exit(textarea: HTMLTextAreaElement, key: KeyboardEvent['key']): true + exit(textarea: HTMLTextAreaElement, e: KeyboardEvent): true } // FIXME spread around readonly where appropriate diff --git a/mbchc.mjs b/mbchc.mjs index 0595c6a..4747ec2 100644 --- a/mbchc.mjs +++ b/mbchc.mjs @@ -159,6 +159,8 @@ const/**@type {Utils}*/U = { remove_loader_hook: $, RGB: {Polly: '#81b1e7', Mute })}, replace_me: (_, __, whole) => cur(whole.slice(1), t => `${U.ACT}<${U.cid(W.Player)}:>SourceCharacter${t.startsWith('\'') || t.startsWith(' ') ? $S : ' '}`), scroll: () => yes(void W.ElementScrollToEnd('TextAreaChatLog')), + get scrolled() {return W.ElementIsScrolledToEnd('TextAreaChatLog')}, + rescroll: f => cur(U.scrolled, s => yes(f, s && U.scroll())), } const/**@type {SUBCOMMANDS}*/SUBCOMMANDS_MBCHC = { @@ -178,7 +180,7 @@ const/**@type {Complete}*/C = { S_OPTS: {behavior: 'instant'}, hint: cs => m_t(cs) || yes(_ => { yes(C.e.style.display = 'block') && C.div?.replaceChildren(...[...cs].sort().reverse().map(U.mkdiv)) W.ElementSetDataAttribute(C.e.id, 'colortheme', W.Player.ChatSettings?.ColorTheme ?? 'Light') - cur(W.ElementIsScrolledToEnd('TextAreaChatLog'), r => yes(void W.ChatRoomResize(false)) && r && U.scroll()) + U.rescroll(_ => void W.ChatRoomResize(false)) C.div?.lastElementChild?.scrollIntoView(C.S_OPTS) }), get hidden() {return C.e.parentElement === null || C.e.style.display === 'none'}, @@ -204,12 +206,12 @@ const/**@type {Complete}*/C = { S_OPTS: {behavior: 'instant'}, const/**@type {InputHistory}*/H = { input: undefined, ids: undefined, bottom: undefined, // FIXME ids don't need to be a set, but I'm too tired right now key: { - Escape: ic => yes(val(H.input, i => ic.value = i)), - ArrowLeft: ic => yes(void ic.setSelectionRange(0, 0)), + Escape: (_, ic) => yes(val(H.input, i => ic.value = i)), + ArrowLeft: (_, ic) => yes(void ic.setSelectionRange(0, 0)), }, icro: (ic, ro) => yes(ic.readOnly = ro, val(ic.parentElement?.parentElement?.dataset, d => ro ? d['mbchcMode'] = 'h' : del(d, 'mbchcMode'))), enter: (ic, i, b, is) => yes(H.input = i, H.bottom = b, H.ids = is, H.icro(ic, true), b && U.scroll()), - exit: (ic, k) => yes(H.icro(ic, false), H.key[k]?.(ic), val(H.bottom, b => b && U.scroll()), W.ChatRoomLastMessageIndex = W.ChatRoomLastMessage.length) + exit: (ic, e) => yes(H.icro(ic, false), H.key[e.key]?.(e, ic), val(H.bottom, b => b && U.scroll()), W.ChatRoomLastMessageIndex = W.ChatRoomLastMessage.length) } ass('MBCHC found, aborting loading', W.MBCHC === $) @@ -478,7 +480,7 @@ const/**@type {SDK.Hook}*/after = (name, f) => mod.hookFunction(name, 0, (na, n) // this.COMP_HINT.innerHTML = '
' + options.sort().reverse().map(s => `
${s}
`).join($S) + '
' // this.COMP_HINT.style.display = 'block' // W.ElementSetDataAttribute(this.COMP_HINT.id, 'colortheme', (W.Player.ChatSettings?.ColorTheme || 'Light')) - // const rescroll = W.ElementIsScrolledToEnd('TextAreaChatLog') + // const rescroll = U.scrolled // W.ChatRoomResize(false) // if (rescroll) U.scroll() // this.COMP_HINT.firstChild?.lastChild?.scrollIntoView({behaviour: 'instant'}) @@ -582,7 +584,7 @@ const/**@type {SDK.Hook}*/after = (name, f) => mod.hookFunction(name, 0, (na, n) {Tag: 'activity', Description: '[Message]: Send a custom activity (or "@@Message", or "@Message" as yourself)', Action: this.command_activity}, {Tag: 'do', Description: ': Do an activity, as if clicked on its button ("/do" for help)', Action: this.command_do, AutoComplete: U.complete_do}, ] - mut(D.createElement('style'), c => void D.head.append(c), c => c.textContent = ` + U.rescroll(_ => mut(D.createElement('style'), c => void D.head.append(c), c => c.textContent = ` #TextAreaChatLog .mbchc { background-color: ${U.RGB.Polly}; margin-left: -0.4em; padding-left: 0.4em; } #TextAreaChatLog[data-colortheme^="dark"] .mbchc { background-color: ${U.RGB.Mute}; } #${C.e.id} { display: none; text-align: right; } @@ -591,12 +593,12 @@ const/**@type {SDK.Hook}*/after = (name, f) => mod.hookFunction(name, 0, (na, n) #${C.e.id} > div div { margin: 0.25ex 0; } #chat-room-div #TextAreaChatLog::before { content: ''; display: block; height: 100%; } #chat-room-div[data-mbchc-mode="h"] #TextAreaChatLog::after { - content: 'π—΅π—Άπ˜€π˜π—Όπ—Ώπ˜† βŸ¨π˜—π˜¨π˜œπ˜±/π˜‹π˜―/β†•βŸ© π—Œπ–Όπ—‹π—ˆπ—…π—… β‡… ⟨𝘌𝘯𝘡𝘦𝘳⟩ π—Œπ–Ύπ—‡π–½ ↡ βŸ¨π˜›π˜’π˜£/β†”βŸ© 𝖾𝖽𝗂𝗍 ⌨ ⟨𝘌𝘴𝘀⟩ π–Ίπ–»π—ˆπ—‹π— ⟲\\A' attr(data-mbchc-h-h); whitespace: pre; + content: 'βŸ¨π˜—π˜¨π˜œπ˜±/π˜‹π˜―/β†•βŸ© π—Œπ–Όπ—‹π—ˆπ—…π—… β‡… ⟨𝘌𝘯𝘡𝘦𝘳⟩ π—Œπ–Ύπ—‡π–½ ↡ βŸ¨π˜›π˜’π˜£/↔/⌫⟩ 𝖾𝖽𝗂𝗍 ⌨ ⟨𝘌𝘴𝘀⟩ π–Ίπ–»π—ˆπ—‹π— ⟲\\A' attr(data-mbchc-h-h); whitespace: pre; display: block; position: sticky; z-index: 1; bottom: 0; background: black; color: orange; padding: 0 0.2ex; animation: 0.2s cubic-bezier(0.19, 1, 0.22, 1) mbchc_hh_show; } #InputChat:read-only { background: black; color: orange; } @keyframes mbchc_hh_show { from {transform: translateX(-100%);} to {transform: translateX(0);} } - `) + `)) // Actions this.calculate_maps() @@ -637,12 +639,12 @@ const/**@type {SDK.Hook}*/after = (name, f) => mod.hookFunction(name, 0, (na, n) const/**@type {(this: HTMLTextAreaElement, e: KeyboardEvent) => void}*/ickd = function(e) { C.hide() const ic = this // eslint-disable-line unicorn/no-this-assignment,@typescript-eslint/no-this-alias - if (ic.readOnly) switch (e.key) { + if (ic.readOnly && !e.repeat) switch (e.key) { // FIXME maybe deal with modifiers case 'ArrowUp': case 'ArrowDown': W.ChatRoomScrollHistory(e.key === 'ArrowUp'); break case 'Escape': case 'Tab': case 'ArrowRight': case 'ArrowLeft': e.stopImmediatePropagation() e.preventDefault() // falls through - case 'Enter': H.exit(ic, e.key) // no default + case 'Enter': case 'Backspace': H.exit(ic, e) // no default } } after('ChatRoomCreateElement', () => { // This thing runs on every frame actually. @@ -675,8 +677,8 @@ const/**@type {SDK.Hook}*/after = (name, f) => mod.hookFunction(name, 0, (na, n) const/**@type {Map}*/map = new Map() const/**@type {(l: string, i: number, I: string) => boolean}*/ cond = m_t(input) ? (_, i, __) => i > 0 : (l, _, i) => l !== i && l.startsWith(i) if (m_t(history.reduce((ax, l, i) => cond(l, i, input) ? ax.set(l, i) : ax, map))) return U.bell() - val(asa(HTMLDivElement, D.querySelector('#TextAreaChatLog')), t => t.dataset['mbchcHH'] = m_t(input) ? 'All history' : `Prefix: ${input}`) - H.enter(ic, input, W.ElementIsScrolledToEnd('TextAreaChatLog'), new Set(map.values())) + val(asa(HTMLDivElement, D.querySelector('#TextAreaChatLog')), t => t.dataset['mbchcHH'] = `π—΅π—Άπ˜€π˜π—Όπ—Ώπ˜†: ${m_t(input) ? 'Everything' : `Prefix: ${input}`}`) + H.enter(ic, input, U.scrolled, new Set(map.values())) } if (ic.readOnly) { // this can't be an else, because we mutate state above. To be honest, this will always be true, but I want to make sure. if (H.ids === $) return U.bell() // shouldn't happen? From 9a646716bf72ebef91a4d0409eb40003fc4b17ae Mon Sep 17 00:00:00 2001 From: Mute Date: Sun, 8 Sep 2024 15:31:33 +0000 Subject: [PATCH 4/5] 107.13.1 scroll on css (works now), also made spacer visible --- ambient.d.ts | 3 - mbchc.mjs | 154 ++-------------------------------------------- package-lock.json | 4 +- package.json | 3 +- 4 files changed, 9 insertions(+), 155 deletions(-) diff --git a/ambient.d.ts b/ambient.d.ts index da320fa..b06ca56 100644 --- a/ambient.d.ts +++ b/ambient.d.ts @@ -66,9 +66,6 @@ interface Window { VERSION: string Settings: Settings.Methods TZ: TZ_Cache - SUBCOMMANDS_MBCHC: SUBCOMMANDS - H: InputHistory - U: Utils AUTOHACK_ENABLED: boolean RE_PREF_ACTIVITY_ME: RegExp RE_PREF_ACTIVITY: RegExp diff --git a/mbchc.mjs b/mbchc.mjs index 4747ec2..09134d9 100644 --- a/mbchc.mjs +++ b/mbchc.mjs @@ -1,5 +1,5 @@ // Take a look at the .d.ts for comments. -export const version = '107.13.0' +export const version = '107.13.1' const W = window, D = W.document, /**fuck money*/$ = undefined, /**@type {''}*/$S = '', /**@type {{}}*/$O = {}, /**@type {Set}*/$Ss = new Set() // /**@type {readonly []}*/$A = [], const/**@type {TextDictionaryEntry}*/MISSING_PLAYER_DIALOG = {Tag: 'MISSING TEXT IN "Interface.csv": ', Text: '\u200C'} // Zero-width non-joiner, used to break up ligatures, does nothing here, but an empty string is a falsey value @@ -229,21 +229,17 @@ const/**@type {SDK.Hook}*/after = (name, f) => mod.hookFunction(name, 0, (na, n) version, /** Just in case someone used it for anything @deprecated*/VERSION: version, Settings, TZ, - SUBCOMMANDS_MBCHC, H, U, // debug, will go away - NEXT_MESSAGE: 1, LOG_MESSAGES: false, LOADED: false, AUTOHACK_ENABLED: false, /**@type {number | undefined}*/LAST_HACKED: $, - //HISTORY_MODE: false, RE_PREF_ACTIVITY_ME: /^@/, RE_PREF_ACTIVITY: /^@@/, RE_ACT_CIDS: /^<(\d+)?:(\d+)?>/, RE_LAST_WORD: /(^|\s)(\S*)$/, RE_LAST_LETTER: /\w$/, RE_ACTIVITY: new RegExp(`^${CommandsKey}activity `), - //PREF_ACTIVITY: `${CommandsKey}activity `, UTC_OFFSET: new Date().getTimezoneOffset() * 60 * 1000, MAP_ACTIONS: { // ActivityFemale3DCG // Action @@ -452,127 +448,6 @@ const/**@type {SDK.Hook}*/after = (name, f) => mod.hookFunction(name, 0, (na, n) mbchc.run_activity(char, /**@type {AssetGroupItemName}*/(ag), /**@type {ActivityName}*/(action)) } catch (x) { U.report(x) } }, - //complete(options, space = true) { - // if (m_t(options)) return void U.bell() - // if (options.length > 1) { - // const width = Math.max(...options.map(o => o.length)) - // let pref = null - // for (let i = width; i > 0; i -= 1) { - // const test = options[0].slice(0, i) - // if (options.every(o => o.startsWith(test))) { - // pref = test - // break - // } - // } - - // if (pref) this.complete([pref], false) - // this.comp_hint(options) - // } else W.ElementValue('InputChat', W.ElementValue('InputChat').replace(this.RE_LAST_WORD, `$1${options[0]}${space ? ' ' : $S}`)) - //}, - - ///** - // * Displays strings as completion hint - // * @param {string[]} options List of words to display. The order will be modified without copy. - // * @returns {undefined} - // */ - //comp_hint(options) { - // if (m_t(options)) return - // this.COMP_HINT.innerHTML = '
' + options.sort().reverse().map(s => `
${s}
`).join($S) + '
' - // this.COMP_HINT.style.display = 'block' - // W.ElementSetDataAttribute(this.COMP_HINT.id, 'colortheme', (W.Player.ChatSettings?.ColorTheme || 'Light')) - // const rescroll = U.scrolled - // W.ChatRoomResize(false) - // if (rescroll) U.scroll() - // this.COMP_HINT.firstChild?.lastChild?.scrollIntoView({behaviour: 'instant'}) - //}, - - ///** - // * Returns true if the completion box is attached to body and its display isn't none - // * @returns {boolean} - // */ - //comp_hint_visible() { - // return this.COMP_HINT.parentElement && this.COMP_HINT.style.display !== 'none' - //}, - //comp_hint_hide() { - // if (!this.comp_hint_visible()) return - // this.COMP_HINT.style.display = 'none' - // W.ChatRoomResize(false) - //}, - //char2targets(/**@type {Character}*/char) { - // const/**@type {Set}*/result = new Set() - // val(U.cid(char)?.toString(), id => result.add(id).add(`=${id}`)) - // for (const t of U.split(char.Name)) { - // result.add(t) - // result.add(`@${t}`) - // } - - // if (char.Nickname !== $) for (const t of U.split(char.Nickname)) { - // result.add(t) - // result.add(`@${t}`) - // } - - // return result - //}, - //complete_target(/**@type {string}*/token, me2 = true, check_perms = false) { - // const [locase, found] = [token.toLocaleLowerCase(), new Set()] - // for (const c of U.crc) { - // if ((c.IsPlayer() && !me2) || (check_perms && !W.ServerChatRoomGetAllowItem(W.Player, c))) continue - // for (const s of this.char2targets(c)) { - // if (s.toLocaleLowerCase().startsWith(locase)) found.add(s) - // } - // } - - // //this.complete(Array.from(found)) - //}, - //complete_common() { // w.ElementValue('InputChat') will strip the trailing whitespace - // const E = D.querySelector('#InputChat') - // ass('somehow #InputChat is broken', E instanceof HTMLTextAreaElement) - // return [this, E.value, U.split(E.value)] - //}, - //complete_mbchc(_args, _locase, _cmdline) { - // const [mbchc, _input, tokens] = W.MBCHC.complete_common(); // `this` is command object - // if (m_t(tokens)) return - // if (tokens.length < 2) return //mbchc.complete([`${CommandsKey}${this.Tag}`]) - // const subname = tokens[1].toLocaleLowerCase() - // if (tokens.length < 3) return //mbchc.complete(Object.keys(SUBCOMMANDS_MBCHC).filter(c => c.startsWith(subname))) // Complete subcommand name - // const sub = SUBCOMMANDS_MBCHC[subname] - // if (sub && sub.args) { - // const argname = Object.keys(sub.args)[tokens.length - 3] - // if (argname === 'TARGET') return mbchc.complete_target(tokens.at(-1), false) - // if (argname === '[TARGET]') return mbchc.complete_target(tokens.at(-1)) - // } - //}, - //complete_fbc_anim(_args, _locase, _cmdline) { - // const [mbchc, _input, tokens] = W.MBCHC.complete_common(); // `this` is command object - // if (m_t(tokens)) return - // if (tokens.length < 2) return mbchc.complete([`${CommandsKey}${this.Tag}`]) - // if (tokens.length > 2) return void U.bell() - // const anim = tokens[1].toLocaleLowerCase() - // return mbchc.complete(Object.keys(W.bce_EventExpressions).filter(a => a.toLocaleLowerCase().startsWith(anim))) - //}, - //complete_fbc_pose(_args, _locase, _cmdline) { - // const [mbchc, _input, tokens] = W.MBCHC.complete_common(); // `this` is command object - // if (m_t(tokens)) return - // if (tokens.length < 2) return mbchc.complete([`${CommandsKey}${this.Tag}`]) - // const pose = tokens.at(-1).toLocaleLowerCase() - // return mbchc.complete(W.PoseFemale3DCG.map(p => p.Name).filter(p => p.toLocaleLowerCase().startsWith(pose))) - //}, - //focus_chat_checks() { // we only want to catch chat log and canvas (no map though) keypresses - // if (D.activeElement === D.body) return true - // if (D.activeElement?.id !== 'MainCanvas') return false - // return !W.ChatRoomMapViewIsActive() - //}, - //focus_chat_whitelist(/**@type {KeyboardEvent}*/event) { - // if (event.ctrlKey && event.key === 'v') return true // Ctrl+V should paste - // return false - //}, - //focus_chat(/**@type {KeyboardEvent}*/event) { - // if (event.repeat) return // Only unique presses please - // if (!this.focus_chat_checks()) return - // if ([event.altKey, event.ctrlKey, event.metaKey].some(Boolean) && !this.focus_chat_whitelist(event)) return // Alt, ctrl and meta should all be false - // if (U.style('#InputChat', s => s.display) !== 'inline') return // Input chat missing - // W.ElementFocus('InputChat') - //}, loader() { U.remove_loader_hook === $ || yes(void U.remove_loader_hook(), U.remove_loader_hook = $) if (this.LOADED) return @@ -584,21 +459,22 @@ const/**@type {SDK.Hook}*/after = (name, f) => mod.hookFunction(name, 0, (na, n) {Tag: 'activity', Description: '[Message]: Send a custom activity (or "@@Message", or "@Message" as yourself)', Action: this.command_activity}, {Tag: 'do', Description: ': Do an activity, as if clicked on its button ("/do" for help)', Action: this.command_do, AutoComplete: U.complete_do}, ] - U.rescroll(_ => mut(D.createElement('style'), c => void D.head.append(c), c => c.textContent = ` + const/**@type (e: Event) => void*/css_hook = e => void cur(/**@type {HTMLStyleElement}*/(e.target), css => U.scroll() && void css.removeEventListener('load', css_hook)) + mut(D.createElement('style'), c => void D.head.append(c), c => void c.addEventListener('load', css_hook), c => c.textContent = ` #TextAreaChatLog .mbchc { background-color: ${U.RGB.Polly}; margin-left: -0.4em; padding-left: 0.4em; } #TextAreaChatLog[data-colortheme^="dark"] .mbchc { background-color: ${U.RGB.Mute}; } #${C.e.id} { display: none; text-align: right; } #${C.e.id} > div { overflow: auto; position: absolute; bottom: 0; right: 0; max-height: 100%; padding: 0 0.5ex; background-color: ${U.RGB.Polly}; color: black; } #${C.e.id}[data-colortheme^="dark"] > div { background-color: ${U.RGB.Mute}; color: white; } #${C.e.id} > div div { margin: 0.25ex 0; } - #chat-room-div #TextAreaChatLog::before { content: ''; display: block; height: 100%; } + #chat-room-div #TextAreaChatLog::before { content: ''; display: block; height: 100%; background: repeating-linear-gradient(135deg, transparent 0 20px, #333 2px 22px); } #chat-room-div[data-mbchc-mode="h"] #TextAreaChatLog::after { content: 'βŸ¨π˜—π˜¨π˜œπ˜±/π˜‹π˜―/β†•βŸ© π—Œπ–Όπ—‹π—ˆπ—…π—… β‡… ⟨𝘌𝘯𝘡𝘦𝘳⟩ π—Œπ–Ύπ—‡π–½ ↡ βŸ¨π˜›π˜’π˜£/↔/⌫⟩ 𝖾𝖽𝗂𝗍 ⌨ ⟨𝘌𝘴𝘀⟩ π–Ίπ–»π—ˆπ—‹π— ⟲\\A' attr(data-mbchc-h-h); whitespace: pre; display: block; position: sticky; z-index: 1; bottom: 0; background: black; color: orange; padding: 0 0.2ex; animation: 0.2s cubic-bezier(0.19, 1, 0.22, 1) mbchc_hh_show; } #InputChat:read-only { background: black; color: orange; } @keyframes mbchc_hh_show { from {transform: translateX(-100%);} to {transform: translateX(0);} } - `)) + `) // will always scroll the chat on CSS load, I can't be fucked to make it conditional // Actions this.calculate_maps() @@ -613,14 +489,6 @@ const/**@type {SDK.Hook}*/after = (name, f) => mod.hookFunction(name, 0, (na, n) } }) prior('ChatRoomSendChat', () => val(U.ic, ic => !ic.value.startsWith('@@@') && ic.value.startsWith('@') && (ic.value = ic.value.replace(U.RE['@'][1], U.ACT).replace(U.RE['@'][0], U.replace_me)))) - //{ - // let input = W.ElementValue('InputChat') - // if (!input.startsWith('@@@') && input.startsWith('@')) { - // input = input.replace(this.RE_PREF_ACTIVITY, this.PREF_ACTIVITY) - // input = input.replace(this.RE_PREF_ACTIVITY_ME, this.replace_me) - // W.ElementValue('InputChat', input) - // } - //}) after('ChatRoomSendChat', () => { // FIXME actually make history a ring buffer of a given size. clear the array and push every string into it, compacting sequential equal strings into one. const history = W.ChatRoomLastMessage if ((history.length > 1) && (history.at(-1) === history.at(-2))) { @@ -650,27 +518,15 @@ const/**@type {SDK.Hook}*/after = (name, f) => mod.hookFunction(name, 0, (na, n) after('ChatRoomCreateElement', () => { // This thing runs on every frame actually. C.e.parentElement ?? D.body.append(C.e) val(U.ic, ic => ic.dataset['mbchc'] ?? void ic.addEventListener('keydown', ickd) ?? (ic.dataset['mbchc'] = 'yes')) - //val(asa(HTMLDivElement, D.querySelector('#TextAreaChatLog')), c => c.scrollHeight > c.clientHeight || void U.pad_chat(c)) }) prior('ChatRoomClearAllElements', () => C.hide() && void C.e.remove()) D.addEventListener('click', _ => C.hide()) // downstream handlers can capture clicks, but I can't be fucked to be honest - //after('ChatRoomResize', () => { - // if (W.CharacterGetCurrent() === null && W.CurrentScreen === 'ChatRoom' && D.querySelector('#InputChat') && D.querySelector('#TextAreaChatLog') && this.comp_hint_visible()) { // Upstream - // const fontsize = ChatRoomFontSize - // //w.ElementPositionFix('TextAreaChatLog', fontsize, 1005, 66, 988, 630) - // //w.ElementPositionFix(this.COMP_HINT.id, fontsize, 1005, 701, 988, 200) - // W.ElementPositionFix(this.COMP_HINT.id, fontsize, 800, 65, 200, 835) - // //this.COMP_HINT.style.display = 'flex' - // } - //}) after('ChatRoomResize', () => { if (W.CharacterGetCurrent() === null && W.CurrentScreen === 'ChatRoom' && U.ic !== $ && D.querySelector('#TextAreaChatLog') !== null && !C.hidden) { // Upstream W.ElementPositionFix(C.e.id, ChatRoomFontSize, 800, 65, 200, 835) } }) - //D.addEventListener('keydown', event => void this.focus_chat(event)) // Looks like the club got better at this - mod.hookFunction('ChatRoomScrollHistory', 0, ([up]) => void val(U.ic, ic => { const input = ic.value, history = W.ChatRoomLastMessage // FIXME we'll make it better when the history is a proper ring buffer if (!ic.readOnly) { diff --git a/package-lock.json b/package-lock.json index 0613efd..c9bcd03 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mbchc", - "version": "107.13.0", + "version": "107.13.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "mbchc", - "version": "107.13.0", + "version": "107.13.1", "license": "SEE LICENSE IN LICENSE", "devDependencies": { "bc-stubs": "^107.0.0", diff --git a/package.json b/package.json index 6b6577c..08886a0 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "name": "mbchc", - "version": "107.13.0", + "version": "107.13.1", "description": "Mute's Bondage Club Hacks Collection", "author": "Mute", + "private": true, "type": "module", "devDependencies": { "bc-stubs": "^107.0.0", From 78e2d6ebda04da743c811cd3c160ec511de9748f Mon Sep 17 00:00:00 2001 From: Mute Date: Thu, 19 Sep 2024 14:11:26 +0000 Subject: [PATCH 5/5] R108 --- README.md | 5 ++++- mbchc.mjs | 2 +- package-lock.json | 12 ++++++------ package.json | 4 ++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8aea441..95297cc 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,7 @@ This document is updated with stable releases, for additional documentation plea * Unstable doc: https://code.fleshless.org/mute/MBCHC/wiki/unstable ## PSA -The only supported version is unstable, don't use any other. \ No newline at end of file +The only supported version is unstable, don't use any other. + +## Feedback +We are available at the club in a private room named `MBCHC`. If Mute isn't there, leave a message. diff --git a/mbchc.mjs b/mbchc.mjs index 09134d9..834853e 100644 --- a/mbchc.mjs +++ b/mbchc.mjs @@ -1,5 +1,5 @@ // Take a look at the .d.ts for comments. -export const version = '107.13.1' +export const version = '108.13.1' const W = window, D = W.document, /**fuck money*/$ = undefined, /**@type {''}*/$S = '', /**@type {{}}*/$O = {}, /**@type {Set}*/$Ss = new Set() // /**@type {readonly []}*/$A = [], const/**@type {TextDictionaryEntry}*/MISSING_PLAYER_DIALOG = {Tag: 'MISSING TEXT IN "Interface.csv": ', Text: '\u200C'} // Zero-width non-joiner, used to break up ligatures, does nothing here, but an empty string is a falsey value diff --git a/package-lock.json b/package-lock.json index c9bcd03..ab449f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "mbchc", - "version": "107.13.1", + "version": "108.13.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "mbchc", - "version": "107.13.1", + "version": "108.13.1", "license": "SEE LICENSE IN LICENSE", "devDependencies": { - "bc-stubs": "^107.0.0", + "bc-stubs": "^108.0.0", "bondage-club-mod-sdk": "^1.2.0", "typescript": "^5.5.2", "xo": "^0.56.0" @@ -1074,9 +1074,9 @@ "dev": true }, "node_modules/bc-stubs": { - "version": "107.0.0", - "resolved": "https://registry.npmjs.org/bc-stubs/-/bc-stubs-107.0.0.tgz", - "integrity": "sha512-PUEvMGe7dDm+lKy6YJIWv1xWCOBVt/WAn4xrG8mBUoGobZVBqOrg+x5lOV0HvG9fcBB8K5NEaXMciE5TOTWkBA==", + "version": "108.0.0", + "resolved": "https://registry.npmjs.org/bc-stubs/-/bc-stubs-108.0.0.tgz", + "integrity": "sha512-b3ko8zl9zn5umYKC7uMQjEtOQxcbAdalUvJ7DoOPyJX4WcsdJFq+R76Rr8bhTtcRq7aW3tk7DtDjTy9awd7CRw==", "dev": true, "dependencies": { "socket.io-client": "4.6.1" diff --git a/package.json b/package.json index 08886a0..3039a8a 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "mbchc", - "version": "107.13.1", + "version": "108.13.1", "description": "Mute's Bondage Club Hacks Collection", "author": "Mute", "private": true, "type": "module", "devDependencies": { - "bc-stubs": "^107.0.0", + "bc-stubs": "^108.0.0", "bondage-club-mod-sdk": "^1.2.0", "typescript": "^5.5.2", "xo": "^0.56.0"