nishio
https://gyazo.com/03051565f03a70a83b182fda5965e187
/icons/-.icon
1. 箇条書きの先頭を全てTabに置き換える
2. 文中の全角・半角空白を取り除く
3. 文字化けを修正する (今回は での を での に直す)
4. 全角英数字を半角英数字に置き換える
5. 全角括弧を半角括弧に置き換える
6. 括弧で囲まれた前後に空白を入れる
7. コードブロック記法の前後に空白を入れる
code:script.js
scrapbox.PopupMenu.addButton({
title: 'format',
onClick: text => text.split('\n').map(function(line) {
return line.replace(/^\s*/g, s => s.replace(/\s/g, '\t'))
// .replace(/ /g, '')
.replace(/ぁ-ん|ァ-ヴ゙/g, s => String.fromCharCode(s.charCodeAt(0) + 1)) .replace(/A-Za-z0-9/g, s => String.fromCharCode(s.charCodeAt(0) - 0xFEE0)) .replace('(', '(')
.replace(')', ')')
.replace(/\S\(/g, s => s.charAt(0) + ()
.replace(/\)\S/g, s => ') ' + s.charAt(1))
.replace(/\S.*/g, s => s.charAt(0) + ' ' + s.slice(1))
.replace(/.*\S/g, s => s.slice(0, -1) + ' ' + s.slice(-1))
}).join('\n')
})
tweetメニュ
code:script.js
scrapbox.PageMenu.addItem({
title: 'Tweet',
onClick: () => window.open(https://twitter.com/intent/tweet?url=${encodeURIComponent(location.href)}&text=${encodeURIComponent(document.title)})
})
文字数カウントメニュ
code:script.js
scrapbox.PageMenu.addItem({
title: () => {
if (!scrapbox.Page.lines) return
const chars = scrapbox.Page.lines.map(line => line.text.length).reduce((a,b) => a + b)
const words = scrapbox.Page.lines.map(line => line.text.split(/\s+/).length).reduce((a,b) => a + b)
return ${chars}文字 ${words}単語 ${scrapbox.Page.lines.length}行
},
onClick: () => null
})
文字カウントポップアップ
code:script.js
scrapbox.PopupMenu.addButton({
title: function (text) {
const chars = text.replace(/\r\n/g, '').length const words = text.trim().split(/\r\n\s+/).length return ${chars}c ${words}w
},
onClick: () => null
})
行頭に引用符を付けるスクリプト
code:script.js
scrapbox.PopupMenu.addButton({
title: 'quote',
onClick: text => text.split(/\n/).map(line => > ${line}).join('\n')
})
Google翻訳ポップアップ
code:script.js
scrapbox.PopupMenu.addButton({
title: 'Google翻訳',
onClick: text => window.open(https://translate.google.com/#ja/en/${text})
})
ページの1部分を新規ページに切り出すポップアップ
code:script.js
scrapbox.PopupMenu.addButton({
title: 'NewPage',
onClick: text => {
const lines = text.split(/\r\n/g) .trim()
.replace(/\^\+.icon\]/gm, '')
const projectRoot = (() => {
const tmp = location.href.split('/')
tmp.pop()
return tmp.join('/')
})()
const currentPageTitle = decodeURIComponent(location.href.split(/\//g).pop())
lines.unshift(from [${currentPageTitle}])
const body = encodeURIComponent(lines.join('\n'))
window.open(${projectRoot}/${title}?body=${body})
return [${title}]
}
})
選択文字列をプロジェクト内で検索ポップアップ
code:script.js
// 選択された文字列をScrapboxプロジェクト内で検索する
// Scapbox検索ボックスを使ったときと同じ結果ページを開く
scrapbox.PopupMenu.addButton({
title: 'SB内検索',
onClick: function (text) {
var projectName = 'shio';
}
});
日付書式
code:script.js
scrapbox.TimeStamp.addFormat("]YYYY/MM/DD[ HH:mm:ss")
scrapbox.TimeStamp.addFormat("]YYYY/MM/DD[")
Gyazoに飛ぶメニュウの追加
code:script.js
scrapbox.PageMenu.addMenu(
{title:"Gyazo",
})
文字数カウンタ
code:script.js
const __charCounterProject__ = scrapbox.Project.name
const __charCounterSetup__ = setInterval(function() {
if (document.getElementById('editor') && scrapbox.Page.lines)
clearInterval(__charCounterSetup__)
else
return
const fmt = (n) => { return new Intl.NumberFormat('en-US').format(n).padStart(6) }
$('<pre id="__charCounterPopup__"></pre>').css('opacity', '0').appendTo('body')
const counterWrapper = $('<div id="__charCounter__"></div>').appendTo('#editor')
const linesText = document.querySelector('.lines').innerText
const chars = linesText.split(/\s+/).join('').length
const counter = $(<span>${fmt(chars)} chars</span>)
.css('opacity', '.45').appendTo(counterWrapper)
counter.hover(
function() {
$(this).css('opacity', '.85')
// page texts without title
const linesText = document.querySelector('.lines').innerText
const chars = linesText.split(/\s+/).join('').length
const words = linesText.split(/\s+/).length
const w = document.getElementById('__charCounter__')
const posX = (window.innerWidth - w.offsetWidth) / 2
const posY = w.offsetTop + w.offsetHeight
$('#__charCounterPopup__')
.html(`${fmt(chars)} chars
${fmt(words)} words
${fmt(scrapbox.Page.lines.length)} lines`)
.css('top', calc(${posY}px - .2em))
.css('right', calc(${posX}px - 3em))
.css('opacity', '1')
},
function() {
$(this).css('opacity', '.45')
$('#__charCounterPopup__').css('opacity', '0')
}
)
const updateCounter = function() {
if (scrapbox.Project.name !== __charCounterProject__
|| document.querySelector('body.presentation')) {
$('#__charCounter__ ').hide()
} else if (scrapbox.Page.lines) {
const linesText = document.querySelector('.lines').innerText
const chars = linesText.split(/\s+/).join('').length
$('#__charCounter__ span').text(${fmt(chars)} chars)
$('#__charCounter__ ').show()
}
}
$('#text-input').on('input', updateCounter).on('paste', updateCounter)
setInterval(updateCounter, 3000)
}, 3000)