
ツール・ページ#page#clipboard#links#llm
1hope linkと2hope linkをclipboardにコピーするUserScript
今見ているページとつながっている関連ページの内容を、まとめてクリップボードにコピーできます。1hop(直接つながったページ)と2hop(その先までたどったページ)の2段階を選べるので、関連する情報を一気に集められます。集めたテキストをそのままChatGPTなどのLLMに貼れば、ページの周辺情報込みで相談できて便利です。
使い方:ページメニューの「Copy 1 Hope」または「Copy 2 Hope」を選びます。
デモ

インストール
設定ページの code:script.js に貼る
import "/api/code/cosense-toolbox/1hope linkと2hope linkをclipboardにコピーするUserScript/script.js";
ソースコード全文を見る(JS)
(() => {
createLinkToMenu(1);
createLinkToMenu(2);
function createLinkToMenu(type = 1) {
const TEXT_CONTENT = `📋 Copy ${type} Hope Lins to Clipboard`;
window.cosense.on("layout:changed", handler);
function handler() {
if (window.cosense.Layout !== "page") {
return;
}
if (hasElementInserted()) {
return;
}
let pageMenuLastDvider = document.querySelectorAll(
".page-menu > div.dropdown:nth-of-type(2) ul li.divider",
);
if (!pageMenuLastDvider[2]) return;
pageMenuLastDvider = pageMenuLastDvider[2];
const li = document.createElement("li");
const a = document.createElement("a");
a.textContent = TEXT_CONTENT;
a.onclick = async () => {
window.showToastAsync("取得中...", { position: "bottom-center" });
const res = await fetch(
`/api/smart-context/export-${type}hop-links/${cosense.Project.name}.txt?title=${cosense.Page.title}`,
);
await navigator.clipboard.writeText(await res.text());
window.toastDone("コピーしました!");
};
li.append(a);
pageMenuLastDvider.insertAdjacentElement("beforebegin", li);
}
function hasElementInserted() {
let has = false;
document.querySelectorAll(".page-menu > div.dropdown:nth-of-type(2) ul li").forEach((n) => {
has = n.textContent === TEXT_CONTENT;
});
return has;
}
handler();
}
})();