Skip to content

Instantly share code, notes, and snippets.

@yashihei
Created December 12, 2023 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yashihei/2d197d6393cecc2fe82dde73b466b9cf to your computer and use it in GitHub Desktop.
Save yashihei/2d197d6393cecc2fe82dde73b466b9cf to your computer and use it in GitHub Desktop.
スクマ(日付+OGP付き)
javascript: (function() {
var title = window.prompt(`Scrap "${document.title}" to yashihei-bookmark.`, document.title);
if (!title) return;
var ogImage = document.querySelector('meta[property="og:image"]') ? document.querySelector('meta[property="og:image"]').getAttribute('content') : '';
var ogDescription = document.querySelector('meta[property="og:description"]') ? document.querySelector('meta[property="og:description"]').getAttribute('content') : '';
var lines = ['[' + window.location.href + ' ' + document.title + ']'];
var today = new Date();
var formattedDate = today.getFullYear() + '-' + String(today.getMonth() + 1).padStart(2, '0') + '-' + String(today.getDate()).padStart(2, '0');
lines.push('bookmarked: ' + formattedDate);
if (ogImage) lines.push('[' + ogImage + ']');
if (ogDescription) lines.push('> ' + ogDescription);
var quote = window.getSelection().toString();
if (quote.trim()) {
lines = lines.concat(quote.split(/\n/g).map(function(line) {
return ' > ' + line;
}));
}
var body = encodeURIComponent(lines.join('\n'));
window.open('https://scrapbox.io/yashihei-bookmark/' + encodeURIComponent(title.trim()) + '?body=' + body);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment