大島崇行
https://gyazo.com/081ee5b0a99daaac72920ca8f2e0d0ea
日付書式
code:script.js
scrapbox.TimeStamp.addFormat("]YYYY/MM/DD[ HH:mm:ss")
scrapbox.TimeStamp.addFormat("]YYYY/MM/DD[")
code:script.js
const number_finder = /\d{2,5}-(\d{1,4}-)\d{4}/g const menu_title = 'Call Button'
let count_indent = text => /^(\s*)/.exec(text)0.length scrapbox.PageMenu.addMenu({
title : menu_title,
onClick: () => {
scrapbox.PageMenu(menu_title).removeAllItems()
const lines = scrapbox.Page.lines
let upper_line, item_name
let is_number_found = false
for (let line of lines) {
const found_number = line.text.match(number_finder)
if (!found_number) {
upper_line = line.text
continue
}
item_name = found_number
if ((upper_line) && (count_indent(line.text) > count_indent(upper_line))) {
item_name = ${upper_line.trim()}: ${found_number}
}
scrapbox.PageMenu(menu_title).addItem({
title : item_name,
onClick: () => window.open(tel:${found_number})
})
is_number_found = true
upper_line = ''
}
if (!is_number_found) {
scrapbox.PageMenu(menu_title).addItem({
title :'No Telephone Number',
onClick: function(){}
})
}
}
})
チェックボックス
code:script.js
setTimeout(() => {
// チェックボックスとして使用する文字のリスト
const textArea = document.getElementById('text-input');
const keydownEvent = {
event: document.createEvent('Event'),
dispatch: function(keycode, withShift = false, withCommand = false) {
this.event.keyCode = keycode;
this.event.shiftKey = withShift;
this.event.metaKey = withCommand;
textArea.dispatchEvent(this.event);
}
};
keydownEvent.event.initEvent('keydown', true, true);
const inputEvent = {
event: document.createEvent('Event'),
dispatch: function(string) {
textArea.value = string;
textArea.dispatchEvent(this.event);
}
};
inputEvent.event.initEvent('input', true, true);
const boxHtmlReg = new RegExp('<span class="c-\\d">(' + checkBoxList.join('|') + ')<\/span>');
const startsWithBoxReg = new RegExp('^\\s*(' + checkBoxList.join('|') + ')');
// ボックスクリックでオンオフする
$('.lines').off('click.toggleCheckBox');
$('.lines').on('click.toggleCheckBox', e => {
const target = e.target;
if (!isFirstElementChild(target) || !boxHtmlReg.test(target.outerHTML)) return;
setTimeout(() => {
const lineString = getCursorLineString();
if (!startsWithBoxReg.test(lineString)) return;
const targetX = target.getBoundingClientRect().left;
const cursorX = document.getElementsByClassName('cursor')0.getBoundingClientRect().left; if (cursorX <= targetX) {
keydownEvent.dispatch(39); // →
}
keydownEvent.dispatch(8); // Delete
const newBox = (() => {
for (let i = 0; i < checkBoxList.length; i++) {
if (lineString.trim().startsWith(checkBoxListi)) { if (i + 1 < checkBoxList.length) {
return checkBoxListi + 1; } else {
}
}
}
})();
inputEvent.dispatch(newBox);
// この下のコメントアウトを解除すると、checked時に取消線を入れて時刻を追記します
// Mac、Porterでのみ動作します
/*
if (/Mobile/.test(navigator.userAgent) || newBox === checkBoxList0) return; setTimeout(() => {
keydownEvent.dispatch(39, true, true); // shift + command + →
inputEvent.dispatch('-');
const now = moment().format('HH:mm');
inputEvent.dispatch( ${now});
}, 50);
*/
}, 50);
});
// ボックス行で改行するとボックス自動配置
$('#text-input').off('keydown.autoInsertCheckBox');
$('#text-input').on('keydown.autoInsertCheckBox', e => {
switch (e.keyCode) {
case 13: // Enter
if (!startsWithBoxReg.test(getCursorLineString())) return;
setTimeout(() => {
if (startsWithBoxReg.test(getCursorLineString())) return;
inputEvent.dispatch(checkBoxList0); }, 50);
break;
default:
return;
}
});
function isFirstElementChild(elem) {
return elem.parentNode.firstElementChild === elem;
}
function getCursorLineString() {
return document.querySelector('.lines div.line.cursor-line').textContent;
}
}, 2000);
大見出し
code:script.js
scrapbox.PopupMenu.addButton({
title: '見出し',
onClick: text => {
return '' + text + '';
}
})
大切
code:script.js
scrapbox.PopupMenu.addButton({
title: '大切',
onClick: text => {
return '' + text + '';
}
})
コメント
code:script.js
scrapbox.PopupMenu.addButton({
title: 'コメント',
onClick: text => {
return '' + text + '';
}
})
名前囲
code:script.js
scrapbox.PopupMenu.addButton({
title: '名前囲',
onClick: text => {
return '' + text + '';
}
})
this is oshima’s page