I’ll copy and paste the version as of 2021-07-29 and run it. js

import {insertText} from '../scrapbox-insert-text-2/script.js';

https://scrapbox.io/api/code/nishio/scrapbox-insert-text-2/script.js net::ERR_ABORTED 404 (Not Found) That’s right, fix to absolute paths.

Uncaught (in promise) ReferenceError: getTalkId is not defined I missed that there are two scripts.

Uncaught (in promise) SyntaxError: Unexpected token ')' Merge and extract the code block of the same name in the page of /takker/scrapbox. Corrected by copying and pasting from

Uncaught (in promise) ReferenceError: askKeicho is not defined Put the following UserScript in TamperMonkey.

test keicho.json

{"talk": "Cl72730A3VXGskCtZ6gL"}

/nishio/nisbot.iconWhat kind of ā€œtestā€ is this ā€œtestā€? Whoa, now I can talk to Keicho on Scrapbox! /nishio/nisbot.iconWhat kind of ā€œKeichoā€ is this ā€œKeichoā€?

As already written in [/takker/UserScript to chat with Keicho](https://scrapbox.io/takker/UserScript to chat with Keicho), ā€œI want to send answers without making selections / with one button or one keystroke.ā€

  • I don’t have to make a selection to access the entire page content.
  • How about creating something like [ask_keicho.icon], and using a hotkey to enter the non-empty line before the icon, and inserting the answer before the icon? 1
Test (cursor)[ask_keicho.icon]

2

test
[nisbot.icon]What kind of "test" is this "test"?
(cursor)[ask_keicho.icon]

2

test
[nisbot.icon]What kind of "test" is this "test"?
Next sentence (cursor)[ask_keicho.icon]
  • Would you rather this be ā€œthe line with the cursorā€?

    • Image of hotkey becoming ā€œask me a question line breakā€.
  • Right now Keicho has a chat-like UI that looks human and behaves in a tightly coupled ā€œonly put a quote when asking a question in a sentence other than the one immediately preceding itā€, but you can always include the input text in the response.

    • Then the UserScript side can look at it and decide where to insert it…?
      • I’m still trying to figure out how the asynchronous text in Scrapbox works.
    • Ah, you’re using a textarea inserted at the cursor position, then I can only write at the user’s cursor position.
    • This is going to be difficult because of Scrapbox’s philosophy of not providing an API for programs to write to arbitrary locations, so the user will have to move it themselves.
  • line containing the cursor

    • Wow, Textarea is floating with position: absolute?
    • XPath
      • $x("//span[@class='text' and contains(.,'[ask_keicho.icon]')]").slice(-1)[0].innerText
      • "\t\n Why don't you create something like [ask_keicho.icon] separately from [nisbot.icon], use the hotkey to take the non-empty line before that icon as input, and insert the answer before the icon."
    • https://developer.mozilla.org/en-US/docs/Web/API/Document/evaluate
    • document.evaluate("//span[@class='text' and contains(.,'[ask_keicho.icon]')]", document).iterateNext().innerText It’s an icon, so can’t you get it with this? → False.
  • document.querySelector("span.text img[alt='ask_keicho']").parentElement.parentElement.parentElement.parentElement.innerText

  • Incorrect: When the cursor is in front of the icon, the line is in edit mode, so it is text.

  • Activate by pressing CTRL+Enter

    • image
    • Oops…
    • Keicho’s specification that interprets keywords enclosed in square brackets as explicit keywords.
    • So let’s just call it (keicho) then.

It’s done. - Ctrl+Enter in Scrapbox to have Keicho ask a question.


This page is auto-translated from /nishio/éøęŠžēÆ„å›²ć‚’Keichoに尋ねるPopupMenu using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I’m very happy to spread my thought to non-Japanese readers.