108meguru
https://lh6.googleusercontent.com/-t_-Fvp5DjmU/AAAAAAAAAAI/AAAAAAAAATU/RQg39MtWRVs/photo.jpg
こちらは、めぐる。のいろいろなものを詰め込んでいる、ScrapBox『Megulabo.』です。
ブログから、思いつきまでいろいろ置いてあります。
趣味はライブ参戦、ものつくり、消しゴムはんこ。
BUMPとシドがらぶ。がっこうのせんせい7年目。
ファシグラをたまーにどこかで描いてます。
特別支援所属。日本LD学会会員。東京コーディネータ研究会所属。
特別支援教育士取得中。日々の記録に挑戦。
/icons/-.icon
code:script.js
const __appliedProject__ = scrapbox.Project.name
const __charCounterSetup__ = setInterval(function() {
// ページが準備できるのを待ちたいので、スクリプトがロードされてから3秒くらいしたら処理開始↓↓
if (document.getElementById('editor') && scrapbox.Page.lines)
clearInterval(__charCounterSetup__)
else
return // ページの準備ができてないときはまた3秒待つ
// 下準備
const $id = id => document.getElementById(id)
const $query = q => document.querySelector(q)
const fmt = n => new Intl.NumberFormat('en-US').format(n).padStart(6)
// 文字数カウンター表示用のエレメントを作ってく
const linesText = $query('.lines').innerText.trim()
const chars = linesText.split(/\s+/).join('').length
var counterWrapper = document.createElement('div')
counterWrapper.id = '__charCounter__'
counterWrapper.innerHTML = <span>${fmt(chars)} chars</span> +
'<pre id="__charCounterPopup__" style="opacity:0"></pre>'
$id('editor').appendChild(counterWrapper)
const counter = $query('#__charCounter__ span')
const popup = $id('__charCounterPopup__')
// 文字数カウンターにマウスカーソルを乗せたときに詳細をポップアップする
counter.addEventListener('mouseover',
function() {
const linesText = $query('.lines').innerText.trim()
const chars = linesText.split(/\s+/).join('').length
const words = linesText.split(/\s+/).length
popup.innerHTML = ${fmt(chars)} chars\n +
${fmt(words)} words\n +
${fmt(scrapbox.Page.lines.length)} lines
popup.style.opacity = 1
})
// 文字数カウンターからマウスカーソルが離れたら詳細ポップアップを見えなくする
counter.addEventListener('mouseout', function() { popup.style.opacity = 0 })
// 文字数のみを数え直す関数
const updateCounter = function() {
if ($query('.presentation')
|| scrapbox.Project.name !== __appliedProject__) {
// プレゼンモードになってたり、よそのプロジェクトを表示してたら文字数カウンターを非表示にする
counterWrapper.style.display = 'none'
} else if (scrapbox.Page.lines) {
// ここで数え直ししてます
const linesText = $query('.lines').innerText.trim()
const chars = linesText.split(/\s+/).join('').length
counter.innerText = ${fmt(chars)} chars
counterWrapper.style.display = 'block'
}
}
// 数え直すタイミングは、テキスト入力時とペースト時
$id('text-input').addEventListener('input', updateCounter)
$id('text-input').addEventListener('paste', updateCounter)
// 何もしなくても3秒ごとに数え直す
setInterval(updateCounter, 3000)
}, 3000)
code:script.js
scrapbox.TimeStamp.addFormat('YYYY年M月D日')
結果: 2017年9月6日
タグ付き日付フォーマットを追加する
code:script.js
scrapbox.TimeStamp.addFormat(']YYYY年M月[D日h時m分')
一部の記号は[ ]の中に入れる必要があります
関数で追加する
文字列を返す関数も登録できます
code:script.js
scrapbox.TimeStamp.addFormat(() => new Date().toLocaleString())
結果: 2017/9/6 21:45:50
ブックマーク
code:script.js
javascript: (function() {
var prj = "your-prj-name";
var cat = "#WebScrap%5Cn";
var title = window.prompt("Scrap Scrapbox to " + prj , document.title);
var toDoubleDigits = function(num) {
num += "";
if (num.length === 1) {num = "0" + num;}
return num;
};
var date = new Date();
var yyyy = date.getFullYear();
var mm = toDoubleDigits(date.getMonth() + 1);
var dd = toDoubleDigits(date.getDate());
var hh = toDoubleDigits(date.getHours());
var MM = toDoubleDigits(date.getMinutes());
var ymdtag = "#" + yyyy + " #" + mm + dd + " " + hh + ":" + MM + "%5Cn"; if (!title) return;
var quote = window.getSelection().toString();
if (quote.trim()) lines = lines.concat(quote.split(/%5Cn/g).map(function(line) { return "> " + line }));
lines.push("");
var body = encodeURIComponent(ymdtag + cat + lines.join("%5Cn"));
window.open("https://scrapbox.io/" + prj + "/" + encodeURIComponent(title.trim()) + "?body=" + body) })();