Orion BrowserのProgrammable buttonで遊ぶ
折角ならProgrammable Buttonからscrapboxにページを作成したいな やってみた
microlinkというサーピスを利用
使い過ぎに注意
code:scraplinker.js
(async () => {
const project = "xyzw";
const pageUrl = location.href;
const pageTitle = document.title.trim() || pageUrl;
const selectedText = window.getSelection()?.toString() ?? "";
// 非同期処理後のポップアップブロック対策
const popup = window.open("about:blank", "_blank");
const lines = [[${pageUrl} ${pageTitle}]];
try {
const apiUrl =
https://api.microlink.io/?url=${encodeURIComponent(pageUrl)};
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error(Microlink API: ${response.status});
}
const result = await response.json();
const imageUrl = result?.data?.image?.url;
if (imageUrl) {
lines.push("", [${imageUrl}]);
}
} catch (error) {
console.error("Microlink image fetch failed:", error);
// API失敗時は現在のページ内メタタグへフォールバック
const fallbackImage =
"";
if (fallbackImage) {
try {
const absoluteImageUrl =
new URL(fallbackImage, document.baseURI).href;
lines.push("", [${absoluteImageUrl}]);
} catch {}
}
}
if (selectedText.trim()) {
lines.push(
"",
...selectedText
.split(/\r?\n/)
.map((line) => > ${line})
);
}
lines.push("", "#Webpage");
const scrapboxUrl =
https://scrapbox.io/${encodeURIComponent(project)}/ +
${encodeURIComponent(pageTitle)}?body= +
encodeURIComponent(lines.join("\n"));
if (popup) {
popup.location.replace(scrapboxUrl);
} else {
location.href = scrapboxUrl;
}
})();
public.icon
とりあえず公開しておく