公式ブックマークレットを改善する
よくScrapするサイトで、フォーマットが気に入らないものを正す
Scrpabox
プロジェクト内リンクとして表示したい
code:*
他プロジェクトへのリンク表記として表示したい
code:*
YouTube
動画の埋め込み表示にしたい
code:*
https://www.youtube.com/watch?v=XXXXXXXXXXX
Twitter
document.titleにツイート内容が貼っているのが鬱陶しい
code:*
画像を直リンで埋め込む(要検討)
タイトルを任意の文字列にする
設定がされていたら設定した任意の文字列、そうでなければdocument.titleにする、にしよう
タイトルを空にしたいときはnewにする(公式ブックマークレット同様)
キャンセルするときはpromptで値を空にする(公式ブックマークレット同様)
rmaruon.iconはShortkeysのctrl+d、command+dに設定し、ブラウザのブックマークを使わないようにしている issue
vimeoを追加してもいいかも
code:js
javascript: (() => {
const プロジェクト名 = "ry";
const プロンプト初期値 = document.title;
const Scrapbox用の文字列を生成する = () => {
// scrapboxプロジェクト以外のページをふるいにかける
try {
scrapbox;
} catch {
return [${window.location.href} ${document.title}];
}
if (scrapbox.Layout === "list") {
return [/${scrapbox.Project.name}];
}
if (scrapbox.Layout === "page") {
if (scrapbox.Project.name == プロジェクト名) {
return [${scrapbox.Page.title}];
}
return [/${scrapbox.Project.name}/${scrapbox.Page.title}];
}
return [${window.location.href}];
};
const YouTube用の文字列を生成する = (pathname) => {
if (pathname === "/watch" || pathname === "/playlist") {
return [${document.location.href}];
}
return [${window.location.href} ${document.title}];
};
const Twitter用の文字列を生成する = (pathname) => {
if (!pathname.includes("/status")) {
return [${window.location.href} ${document.title}];
}
const username = elem.href.split("/")3; const datetime = elem.firstChild.innerText;
const imgUrls = Array.from(document.querySelectorAll('ahref*="/photo/" img')).map( (img) => >[${img.src.split("&")[0] + "&name=large#.jpg"}]
);
const imgUrlString = imgUrls.length > 0 ? "\n" + imgUrls.join("\n") : "";
return [${window.location.href} @${username}'s tweet ${datetime}] + imgUrlString;
};
const hostname毎に文字列を生成する = () => {
const hostname = window.location.hostname;
const pathname = window.location.pathname;
if (hostname === "scrapbox.io") return Scrapbox用の文字列を生成する(pathname);
if (hostname === "www.youtube.com") return YouTube用の文字列を生成する(pathname);
if (hostname === "twitter.com") return Twitter用の文字列を生成する(pathname);
return [${window.location.href} ${document.title}];
};
const 選択文字列から引用を生成する = () => {
const text = window.getSelection().toString();
if (text.trim() === "") return "";
const lines = text.split(/\n/g).map((line) => {
return ">" + line;
});
return lines.join("\n");
};
const main = () => {
const ページタイトル = window.prompt(
Scrap "Scrapbox" to /${プロジェクト名}.,
プロンプト初期値
);
if (!ページタイトル) return;
ページタイトル.trim()
)}`;
const 本文 = encodeURIComponent(
);
window.open(${ページURL}?body=${本文});
};
main();
})();
code:*
javascript:(()=>{const a="%s",b=document.title,c=()=>{try{scrapbox}catch{return[${window.location.href} ${document.title}]}return"list"===scrapbox.Layout?[/${scrapbox.Project.name}]:"page"===scrapbox.Layout?scrapbox.Project.name==a?[${scrapbox.Page.title}]:[/${scrapbox.Project.name}/${scrapbox.Page.title}]:[${window.location.href}]},d=a=>"/watch"===a||"/playlist"===a?[${document.location.href}]:[${window.location.href} ${document.title}],e=a=>{if(!a.includes("/status"))return[${window.location.href} ${document.title}];const b=document.querySelector("divdir=\"auto\" > arole=\"link\"href*=\"/status/\""),c=b.href.split("/")3,d=b.firstChild.innerText,e=Array.from(document.querySelectorAll("ahref*=\"/photo/\" img")).map(a=>>[${a.src.split("&")[0]+"&name=large#.jpg"}]),f=0<e.length?"\n"+e.join("\n"):"";return[${window.location.href} @${c}'s tweet ${d}]+f},f=()=>{const a=window.location.hostname,b=window.location.pathname;return"scrapbox.io"===a?c(b):"www.youtube.com"===a?d(b):"twitter.com"===a?e(b):[${window.location.href} ${document.title}]},g=()=>{const a=window.getSelection().toString();if(""===a.trim())return"";const b=a.split(/\n/g).map(a=>">"+a);return b.join("\n")};(()=>{const c=window.prompt(Scrap "Scrapbox" to /${a}.,b);if(!c)return;const d=https://scrapbox.io/${a}/${encodeURIComponent(c.trim())},e=encodeURIComponent(f(),g().join("\n")+"\n");window.open(${d}?body=${e})})()})(); 2021-08-08
リファクタリング
引用を箇条書きにしない
YouTube playlist対応
hrefとtitleを入れ替える