generated at
開いている Web ページを自分の project に引用する bookmark

作: Summer498
機能
scrapbox ページを開いている状態で起動すると、そのページを全文自分のプロジェクトにコピペする
先頭に from [/Project.name/Page.title] が追加される
scrapbox 以外を開いている状態で起動すると、そのページへの参照ページを自分のプロジェクトに作成する
その際に文字を選択していると、選択部分のみが引用される

使い方
1. minify バージョンをコピーしてブックマークの URL にペースト
2. "Summer498" となっている所を自分のプロジェクト名にする
自分のプロジェクト名は、URL の https://scrapbox.io/ProjectName ProjectName に書いてある文字列のこと
3. ブックマークから起動

今後の課題
scrapbox ページを引用する方でも選択範囲のみの引用をしたい

参照

bookmark.js
javascript:(()=>{let p="Summer498",c='\n',f=window,r=encodeURIComponent,l=f.scrapbox,m=t=>prompt(`Scrap "${t}" to /${p}/.`,t),o,i,a,s;if(l){let t=l.Project.name,e=l.Page,n=e.title,d=t+"/"+n;o=m(n),o&&(i=`from [/${d}]`,s=e.lines.map(_=>_.text).slice(1))}else if(location.href.match("youtube\.com")){let t=document.title;if(o=m(t),o){i=`from ${t}${c}[${location.href}]`;let e=getSelection().toString();s=e.trim()?e.split(c).map(n=>"> "+n):[]}}else{let t=document.title;if(o=m(t),o){i=`from [${location.href} ${t}]`;let e=getSelection().toString();s=e.trim()?e.split(c).map(n=>"> "+n):[]}}if(o){a=[i,""].concat(s);let t=r(a.join(c));open(`https://scrapbox.io/${p}/${r(o.trim())}?body=`+t)}})();

旧バージョン
bookmark.js
javascript:(()=>{let p="Summer498",m='\n',_=window,r=encodeURIComponent,c=_.scrapbox,a=t=>prompt(`Scrap "${t}" to /${p}/.`,t),o,i,l,s;if(c){let t=c.Project.name,e=c.Page,n=e.title,d=t+"/"+n;o=a(n),o&&(i=`from [/${d}]`,s=e.lines.map(f=>f.text).slice(1))}else{let t=document.title;if(o=a(t),o){i=`from [${location.href} ${t}]`;let e=getSelection().toString();s=e.trim()?e.split(m).map(n=>"> "+n):[]}}if(o){l=[i,""].concat(s);let t=r(l.join(m));open(`https://scrapbox.io/${p}/${r(o.trim())}?body=`+t)}})();

readable.js
(()=>{ const my_project = "Summer498"; const LF='\n' const _window = window; const _encodeURIComponent = encodeURIComponent; const _scrapbox=_window.scrapbox; const getTitle = title => prompt(`Scrap "${title}" to /${my_project}/.`, title); let title, first_line, lines, quote; if(_scrapbox){ const project_name = _scrapbox.Project.name; const page = _scrapbox.Page; const page_title = page.title; const page_path = project_name + "/" + page_title; title = getTitle(page_title); if(title){ first_line = `from [/${page_path}]`; quote = page.lines.map(e=>e.text).slice(1); } } else if(location.href.match("youtube\.com")) { const document_title = document.title; title = getTitle(document_title); if(title){ first_line = `from ${document_title}${LF}[${location.href}]`; const selection = getSelection().toString(); quote = selection.trim() ? selection.split(LF).map(e=>'> '+e) : []; } } else { const document_title = document.title; title = getTitle(document_title); if(title){ first_line = `from [${location.href} ${document_title}]`; const selection = getSelection().toString(); quote = selection.trim() ? selection.split(LF).map(e=>'> '+e) : []; } } if(title){ lines = [first_line, ""].concat(quote); const body = _encodeURIComponent(lines.join(LF)); open(`https://scrapbox.io/${my_project}/${_encodeURIComponent(title.trim())}?body=` + body); } })();



thanks for takker
> try{_scrapbox = scrapbox}catch(_){_scrapbox=0} を入れている理由がわからないtakker
scrapbox 以外のページで scrapbox を参照しようとするとエラーが出るので防ぐSummer498
window.scrapbox にすればいいな
diff
- try{_scrapbox = scrapbox}catch(_){_scrapbox=0} + const _scrapbox=_window.scrapbox;

> テンプレート文字列にしたほうが1文字少なくなるtakker
Summer498
diff
- open('https://scrapbox.io/'+my_project+'/'+_encodeURIComponent(title.trim())+'?body='+body); + open(`https://scrapbox.io/${my_project}/${_encodeURIComponent(title.trim())}?body=`+body);