Skip to content

Instantly share code, notes, and snippets.

@yuki2021
Created May 1, 2023 08:43
Show Gist options
  • Save yuki2021/5ca6c1f7470cf63a5b771378b5138e54 to your computer and use it in GitHub Desktop.
Save yuki2021/5ca6c1f7470cf63a5b771378b5138e54 to your computer and use it in GitHub Desktop.
Tampermonkeyにて、Scrapboxの日記ページを開くためのUserScript
// ==UserScript==
// @name scrapbox_open_diary
// @version 1.0
// @description Scrapboxでその日の日付の日記ページを開く
// @author yuki2021
// @match https://scrapbox.io/*
// ==/UserScript==
var optDown = false;
document.addEventListener('keydown', function(event) {
// Option + Oが押された時はその日の日記ページを開く
if (event.altKey && event.code === 'KeyO') {
var d = new Date();
var year = d.getFullYear();
var dt = d.getDate();
var month = d.getMonth() + 1;
var date = [
year,
('00' + month).slice(-2),
('00' + dt).slice(-2)
];
var title = date.join('/');
var scrapboxProject = location.href.match(/scrapbox.io\/([^\/.]*)/)[1];
var scrapboxUrl = 'https://scrapbox.io/' + scrapboxProject + '/' + encodeURIComponent(title);
// 今現在の時刻をbodyに入れる
var now = new Date();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
var body = encodeURIComponent('\t' + date.join('/') + ' ' + hour + ':' + minute + ':' + second);
window.open(scrapboxUrl + '?body=' + body);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment