ScrapboxのCursorオブジェクトを取得する
吐き出せやオラッするやつ
script.jsexport function getCursor() {
const textarea = document.getElementById("text-input");
// from https://github.com/takker99/scrapbox-userscript-std/blob/58ede69911a63600acb39745dc7fdec3fcf8cf6d/browser/dom/caret.ts#L50
const reactKey = Object.keys(textarea)
.find((key) => key.startsWith("__reactFiber"));
const input = textarea[reactKey].return.return.stateNode;
const cursor = input._stores.find((obj) => obj.constructor.name === "Cursor");
const selection = input._stores.find((obj) =>
obj.constructor.name === "Selection"
);
const mobileSelection = input._stores.find((obj) =>
obj.constructor.name === "MobileSelection"
);
return {
cursor,
selection,
mobileSelection,
};
}