Firefoxだとscrapboxの選択文字列をwindow.getSelection().toString()で取得できない
以前はどのscrapbox.ioそのものがwindow.getSelection().toString()に対応していないのかと思っていたが、/jyori112/beyondTheLinkにwindow.getSelection().toString()を使っているコードがあったので疑い始めた
以前対応していたという可能性も考えたが、上記のページの更新日時が今年の8月だったので、その線はなさそうだった
確かに、Chrome@PCだとwindow.getSelection().toString()でScrapboxの選択範囲を取得できるようだ
Chrome for Androidも対応していないもよう
/rmaruon/Scrapboxで文字を読み上げる#6103ccb35aca300000d0be7d
無理矢理Reactの中身を取り出せばいけそう
code:js
{
const selections = document.querySelector(".selections");
if(selections){
const reactKey = Object.keys(selections).find(key => key.startsWith("__reactInternalInstance"));
console.log(selectionsreactKey.return.memoizedProps.range)
}
}
memoizedPropsについて
https://postd.cc/react-fiber-architecture/
React Fiberに関わるpropertyらしい
これ使えば、scrapboxのcursorの位置を計算する必要もないじゃん
React Componentの内部変数からScrapboxのカーソル位置と選択範囲を取得する
#2022-01-19 08:34:29
#2021-12-13 09:14:11