Skip to content

Instantly share code, notes, and snippets.

@nora-tetsu
Created February 23, 2023 08:40
Show Gist options
  • Save nora-tetsu/8a47788d0740443eb9fdf98cb4c95cb8 to your computer and use it in GitHub Desktop.
Save nora-tetsu/8a47788d0740443eb9fdf98cb4c95cb8 to your computer and use it in GitHub Desktop.
Page Menuから指定したキーワードをタイトルに含むページの一覧を追記するUserScript
(function () {
scrapbox.PageMenu.addMenu({
title: 'タイトル抽出',
image: 'https://i.gyazo.com/7057219f5b20ca8afd122945b72453d3.png', // Scrapboxアイコン
onClick: () => {
const keyword = prompt('ピックアップする文字列を入力してください。');
if (!keyword) return;
// 現在のプロジェクトの全ページについて、指定した文字列をタイトルに含むか判定する
let body = `「${keyword}」を含むページ\n`;
scrapbox.Project.pages.forEach(data => {
if (!data.exists) return; // 空リンクはスキップ
if (!data.title.includes(keyword)) return;
body += `\t[${data.title}]\n`;
})
// 追記内容を現在のページのURLに付与して別ウインドウで開く
const write = window.open(`https://scrapbox.io/${scrapbox.Project.name}/${scrapbox.Page.title}?body=${encodeURIComponent(body)}`);
setTimeout(() => write.close(), 15000); // 15秒後に閉じる(長過ぎるようなら短くする)
},
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment