generated at
行の作成日時を挿入
Scrapboxでは一行ごとに新規作成日時を含む行IDが記録されています。
←左端に表示されている「テロメア」はこれに基づいています。
このUserScript (Scrapbox)はカーソル位置の行IDから新規作成日時を取り出しテキストとして挿入します。
JavaScriptのDateオブジェクトのメソッドをそのまま使っています。
toString, toUTCString, toJSON
使用例は下部の動画をご覧ください。
作成日時 2021-10-05T04:07:33.000Z TakashiSasaki

script.js
scrapbox.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); }

使用例

参考