スクマ
便利すぎてheavy useしている…
本Pageに書いているScriptが即座反映されるBookmarklet
残念ながら
Githubはじめとしたthird party製service内のfileを読み込めないsiteでは機能しない
bookmarklet.jsjavascript:(function(d,s){s=d.createElement('script');s.src='https://scrapbox.io/api/code/inteltank/スクマ/script.js';d.body.appendChild(s);})(document)
ただし、本PageのScriptが更新されるたびにBookmarkletの登録をし直す必要がある
bookmarklet_raw.jsjavascript:var global=window;global.COPY_TO_CLIPBOARD=global.COPY_TO_CLIPBOARD||{};function quickQuotes(){var a=document.title,b={":":"\uff1a","\\[":"\uff3b","\\]":"\uff3d","\\|":"\uff5c"},c;for(c in b)a=a.replace(new RegExp(c,"g"),b[c]);a="["+window.location.href+" "+a+"]";b=window.getSelection().toString();""!=b&&(b=b.split(/\n/g).map(function(d){return" > "+d}),a=a+"\n"+b.join("\n"));return a}function quickQuotesAtScrapbox(){var a="[/"+scrapbox.Project.name+"/"+scrapbox.Page.title;if(document.getElementsByClassName("cursor-line")[0]){var b=window.getSelection().toString();""==window.getSelection().toString()?a=a+"#"+document.getElementsByClassName("cursor-line")[0].id.slice(1)+"]":(b=b.split(/\n/g).map(function(c){return" > "+c}),a=a+"#"+document.getElementsByClassName("cursor-line")[0].id.slice(1)+"]\r"+b.join("\n"))}else a+="]";return a}
global.COPY_TO_CLIPBOARD.copyToClipboard=function(){var a=document.createElement("textarea"),b=document.location.href.match(/scrapbox.io/)?quickQuotesAtScrapbox():quickQuotes();a.textContent=b;b=document.getElementsByTagName("body")[0];b.appendChild(a);a.select();var c=document.execCommand("copy");b.removeChild(a);return c};global.COPY_TO_CLIPBOARD.copyToClipboard();
script.jsvar global = window;
global.COPY_TO_CLIPBOARD = global.COPY_TO_CLIPBOARD || {};
function quickQuotes(){
var title = document.title;
var replacedStrings = {
':': ':',
'\\[': '[',
'\\]': ']',
'\\|': '|'
};
for (var key in replacedStrings) {
title = title.replace(new RegExp(key, 'g'), replacedStrings[key]);
}
var project_title= '['+window.location.href+' '+title+']';
var quote=window.getSelection().toString();
if(quote==""){
var url = project_title;
}else{
var lines = quote.split(/\n/g).map(function(line){return ' > '+line});
var url = project_title + "\n" +lines.join('\n');
}
return url;
}
function quickQuotesAtScrapbox(){
var project_title = '[/' + scrapbox.Project.name + '/' + scrapbox.Page.title
if(document.getElementsByClassName("cursor-line")[0]){
var quote=window.getSelection().toString();
if(window.getSelection().toString()==""){
var url = project_title + "#" +
document.getElementsByClassName("cursor-line")[0].id.slice(1) + ']';
}else{
var lines = quote.split(/\n/g).map(function(line){return ' > '+line})
var url = project_title +
"#"+ document.getElementsByClassName("cursor-line")[0].id.slice(1) +
"]" +
"\r" +lines.join('\n');
}
}else{
var url = project_title + ']';
}
return url;
}
global.COPY_TO_CLIPBOARD.copyToClipboard = function() {
var copyFrom = document.createElement("textarea");
if(document.location.href.match(/scrapbox.io/)){
var body = quickQuotesAtScrapbox();
}else{
var body = quickQuotes();
}
copyFrom.textContent = body;
var bodyElm = document.getElementsByTagName("body")[0];
bodyElm.appendChild(copyFrom);
copyFrom.select();
var retVal = document.execCommand('copy');
bodyElm.removeChild(copyFrom);
return retVal;
};
global.COPY_TO_CLIPBOARD.copyToClipboard();