行の作成日時を挿入
←左端に表示されている「
テロメア」はこれに基づいています。
JavaScriptのDateオブジェクトのメソッドをそのまま使っています。
toString, toUTCString, toJSON
使用例は下部の動画をご覧ください。
script.jsscrapbox.PageMenu.addMenu({
title : "Insert DateTime",
image : "https://gyazo.com/6a51ead9d9f6d0aaac1446ab7a75d28d/raw"
});
scrapbox.PageMenu("Insert DateTime").addItem({
title: "toString",
onClick : function(){return insertDateTimeOfLineId(function(d){return d.toString();});}
});
scrapbox.PageMenu("Insert DateTime").addItem({
title: "toUTCString",
onClick : function(){return insertDateTimeOfLineId(function(d){return d.toUTCString();});}
});
scrapbox.PageMenu("Insert DateTime").addItem({
title: "ISO8601",
onClick : function(){return insertDateTimeOfLineId(function(d){return d.toJSON();});}
});
function insertDateTimeOfLineId(f){
const textarea = document.getElementById('text-input');
textarea.focus();
setTimeout(function(){
const currentLine = document.querySelector(".cursor-line");
if(!currentLine) return null;
if(!currentLine.id) return;
const hex = "0x" + currentLine.id.substr(1, 8);
const ms = parseInt(hex) * 1000;
const d = new Date(ms);
textarea.value = f(d);
const uiEvent = document.createEvent('UIEvent');
uiEvent.initEvent('input', true, false);
textarea.dispatchEvent(uiEvent);
}, 10);
}
使用例
参考