custard
#member
https://gyazo.com/dba813d5b534615dfdccf8465a6da866
ここはcustardのページですcustard.icon
学生です. よければ以下をご参照ください:
Cosenseを使用する目的
アカウント
Cosenseプロジェクト
/main-custardはMOCから辿れます
アンチパターンな気もしてます
2025/3/30 始めてから1ヶ月ほどのため,試行錯誤中test.icon
イラスト/ノーコピーライトガール
使用している画像の大半がここ
cf. https://fromtheasia.com/illustration/nocopyrightgirl
cf. どこか
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
})
cf. /scrasobox/テンプレートを使ってページを作成(UserScript版)
code: style.css
button#Templates.tool-btn:hover { text-decoration: none }
button#Templates.tool-btn::before { position: absolute; content: '\f067'; font: 900 21px/46px 'Font Awesome 5 Free' }
button#Templates.tool-btn img { opacity: 0 }
code: script.js
addTemplateItemsToPageMenu()
function addTemplateItemsToPageMenu() {
// define templates
const __templates = [
{ title: '📄 daily', template: '/api/code/main-custard/template/daily_log.js' },
{ title: '📄 weekly', template: '/api/code/main-custard/template/weekly_log.js' },
{ title: '📄 reading', template: '/api/code/main-custard/template/reading_list.js' }
]
const __templMenuTitle = 'Templates'
scrapbox.PageMenu.addMenu({ title: __templMenuTitle, image: '/assets/img/logo.png', onClick: () => { } })
__templates.forEach((i) => {
scrapbox.PageMenu(__templMenuTitle).addItem({
title: i.title,
onClick: () => { __loadTemplate(i.template) }})
})
var __loadTemplate = function (templateUrl) {
if (scrapbox.Page.lines && scrapbox.Page.lines.length == 1) {
// タイトル行をクリックしたことにする
const line = document.getElementById('L' + scrapbox.Page.lines0.id)
const lastChar = line.querySelector('span.char-index:last-of-type')
const textarea = document.getElementById('text-input')
lastChar.dispatchEvent(new MouseEvent('click', {bubbles: true, cancelable: true}))
textarea.dispatchEvent(new KeyboardEvent('keydown', {bubbles: true, cancelable: true, keyCode: 35}))
// テンプレートを読み込む
$('#text-input').load(templateUrl, function (response, status, xhr) {
if (status == "success") {
try {
// 読み込んだテンプレートをテキストエリアにセットしまして
textarea.value = /\.js$/.test(templateUrl) ? eval(response) : response
// テキストエリアのinputイベントを出しまして
textarea.dispatchEvent(new InputEvent('input', {bubbles: true, cancelable: true}))
} catch (ex) {
console.log("あぼーん\n" + ex)
}
} else {
console.log("あぼーん \n" + status)
}
})
}
}
}
template
2025/6/1