Templates
code:daily-report.js
import { Template } from '/api/code/rokoucha/Templates/template.js'
export class DailyReport extends Template {
constructor() {
super('๐ DailyReport')
}
get today() {
return new Date()
}
get pageTitle() {
return format(this.today)
}
get body() {
return `#DailyReports
}
}
code:daily-report-log.js
import { Template } from '/api/code/rokoucha/Templates/template.js'
export class DailyReportLog extends Template {
constructor() {
super('๐ DailyReport(Log)')
/** @var {Date} Today date */
this.today = new Date()
}
beforeRender() {
/** @var {string|null} User input date string */
const prompt = window.prompt('Date?')
/** @var {Date} Created date from string(or default date) */
const date = (prompt === null || prompt === '') ? new Date() : new Date(prompt)
if (isNaN(date.getTime())) {
window.alert(date)
throw new Error('Invalid date')
}
this.today = date
}
get pageTitle() {
return format(this.today)
}
get body() {
return `#DailyReports
}
}
code: event-tasks.js
import { Template } from '/api/code/rokoucha/Templates/template.js'
export class EventTasks extends Template {
constructor() {
super('๐ Event tasks')
}
get pageTitle() {
return '12/34 hogehoge'
}
get body() {
return `#memo
ๆใก็ฉ
โฌ ในใใ
ใใใใจ
โฌ ใใใใใ
`
}
}
code: mokumoku.js
import { Template } from '/api/code/rokoucha/Templates/template.js'
export class Mokumoku extends Template {
constructor() {
super('โ๏ธ Mokumoku')
/** @var {Date} Today date */
this.today = new Date()
}
beforeRender() {
/** @var {string|null} User input date string */
const prompt = window.prompt('Date?')
/** @var {Date} Created date from string(or default date) */
const date = (prompt === null || prompt === '') ? new Date() : new Date(prompt)
if (isNaN(date.getTime())) {
window.alert(date)
throw new Error('Invalid date')
}
this.today = date
}
get pageTitle() {
return format(this.today, '.')
}
get body() {
return `
}
}
code: template.js
/** Template **abstract** class */
export class Template {
/** abstract @params {string} templateTitle Template title, @params {string} menuTitle Template menu title */
constructor(templateTitle, menuTitle = 'Templates') {
/** @var {string} Template title */
this.templateTitle = templateTitle
/** @var {string} Template menu title */
this.menuTitle = menuTitle
if(typeof scrapbox.PageMenu().menus.get(this.menuTitle) === 'undefined') {
scrapbox.PageMenu.addMenu({
title: this.menuTitle,
image: '/assets/img/favicon/apple-touch-icon.png',
onClick: () => {}
})
}
scrapbox.PageMenu(this.menuTitle).addItem({
title: this.templateTitle,
onClick: () => {this.render()}
})
}
/** @returns {void} Before render action */
beforeRender() {}
/** @returns {void} Render template to edit */
render() {
if (scrapbox.Page.lines && scrapbox.Page.lines.length == 1) {
this.beforeRender()
const edit = document.getElementById('text-input')
edit.value = `${this.pageTitle}
${this.body}`
const inputEvent = new Event('input', { bubbles: true, cancelable: true })
edit.dispatchEvent(inputEvent)
}
}
/** abstract @returns {string} Page title */
get pageTitle() {
return
}
/** abstract @returns {string} Body text */
get body() {
return
}
}
code: dateutil.js
/** @params {Date} date, @params {string} delimiter, @returns {string} Formatted date text */
export const format = (date, delimiter = '-') => ${date.getFullYear()}${delimiter}${String(date.getMonth()+1).padStart(2, '0')}${delimiter}${String(date.getDate()).padStart(2, '0')}
/** @params {Date} date, @params {number} day, @returns {Date} Added Date object */
export const addDay = (date, day = 1) => {
const addedDate = new Date(date.toISOString())
addedDate.setDate(addedDate.getDate() + day)
return addedDate
}
code:templates.js
import { DailyReport } from '/api/code/rokoucha/Templates/daily-report.js'
import { DailyReportLog } from '/api/code/rokoucha/Templates/daily-report-log.js'
import { EventTasks } from '/api/code/rokoucha/Templates/event-tasks.js'
import { Mokumoku } from '/api/code/rokoucha/Templates/mokumoku.js'
new DailyReport()
new DailyReportLog()
new EventTasks()
new Mokumoku()