1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-04 18:19:54 +00:00

Add local time buttons

Implements: #231
This commit is contained in:
Timur Ismagilov 2024-06-11 14:47:15 +03:00
parent a0ec4f5fbf
commit 33a477cf36
4 changed files with 28 additions and 8 deletions

View File

@ -45,8 +45,10 @@ var (
{{define "numbers"}}Нумер. список{{end}} {{define "numbers"}}Нумер. список{{end}}
{{define "mycomarkup help"}}<a href="/help/en/mycomarkup" class="shy-link">Подробнее</a> о Микоразметке{{end}} {{define "mycomarkup help"}}<a href="/help/en/mycomarkup" class="shy-link">Подробнее</a> о Микоразметке{{end}}
{{define "actions"}}Действия{{end}} {{define "actions"}}Действия{{end}}
{{define "current date"}}Текущая дата{{end}} {{define "current date utc"}}Дата UTC{{end}}
{{define "current time"}}Текущее время{{end}} {{define "current time utc"}}Время UTC{{end}}
{{define "current date local"}}Местная дата{{end}}
{{define "current time local"}}Местное время{{end}}
{{define "selflink"}}Ссылка на вас{{end}} {{define "selflink"}}Ссылка на вас{{end}}
{{define "empty heading"}}Эта гифа не существует{{end}} {{define "empty heading"}}Эта гифа не существует{{end}}

View File

@ -32,8 +32,10 @@
<aside class="edit-toolbar action-toolbar layout-card"> <aside class="edit-toolbar action-toolbar layout-card">
<h2 class="edit-toolbar__title layout-card__title">{{block "actions" .}}Actions{{end}}</h2> <h2 class="edit-toolbar__title layout-card__title">{{block "actions" .}}Actions{{end}}</h2>
<section class="edit-toolbar__buttons"> <section class="edit-toolbar__buttons">
<button class="btn edit-toolbar__btn edit-toolbar__date">{{block "current date" .}}Insert current date{{end}}</button> <button class="btn edit-toolbar__btn edit-toolbar__date-local">{{block "current date local" .}}Current local date{{end}}</button>
<button class="btn edit-toolbar__btn edit-toolbar__time">{{block "current time" .}}Insert current time{{end}}</button> <button class="btn edit-toolbar__btn edit-toolbar__time-local">{{block "current time local" .}}Current local time{{end}}</button>
<button class="btn edit-toolbar__btn edit-toolbar__date-utc">{{block "current date utc" .}}Current date UTC{{end}}</button>
<button class="btn edit-toolbar__btn edit-toolbar__time-utc">{{block "current time utc" .}}Current time UTC{{end}}</button>
{{if .Meta.U.Group | ne "anon"}} {{if .Meta.U.Group | ne "anon"}}
<button class="btn edit-toolbar__btn edit-toolbar__user-link">{{block "selflink" .}}Link yourself{{end}}</button> <button class="btn edit-toolbar__btn edit-toolbar__user-link">{{block "selflink" .}}Link yourself{{end}}</button>
{{end}} {{end}}

View File

@ -329,7 +329,7 @@ if (document.body.dataset.rrhAddr.startsWith('/edit')) {
new Shortcut(isMac ? 'Meta+Shift+x' : 'Ctrl+X', wrapStrikethrough, 'Strikethrough', { force: true }), new Shortcut(isMac ? 'Meta+Shift+x' : 'Ctrl+X', wrapStrikethrough, 'Strikethrough', { force: true }),
new Shortcut(isMac ? 'Meta+k' : 'Ctrl+k', wrapLink, 'Inline link', { force: true }), new Shortcut(isMac ? 'Meta+k' : 'Ctrl+k', wrapLink, 'Inline link', { force: true }),
// Apparently, ⌘; conflicts with a Safari's hotkey. Whatever. // Apparently, ⌘; conflicts with a Safari's hotkey. Whatever.
new Shortcut(isMac ? 'Meta+;' : 'Ctrl+;', insertDate, 'Insert date UTC', { force: true }), new Shortcut(isMac ? 'Meta+;' : 'Ctrl+;', insertDateUTC, 'Insert date UTC', { force: true }),
])) ]))
} }
} }

View File

@ -87,7 +87,7 @@ const insertHorizontalBar = textInserter('\n----\n'),
insertBulletedList = textInserter('\n* '), insertBulletedList = textInserter('\n* '),
insertNumberedList = textInserter('\n*. ') insertNumberedList = textInserter('\n*. ')
function insertDate() { function insertDateUTC() {
let date = new Date().toISOString().split('T')[0] let date = new Date().toISOString().split('T')[0]
textInserter(date)() textInserter(date)()
} }
@ -97,6 +97,20 @@ function insertTimeUTC() {
textInserter(time)() textInserter(time)()
} }
function len2(n) {
return n < 10 ? `0${n}` : `${n}`
}
function insertDateLocal() {
let d = new Date()
textInserter(`${d.getFullYear()}-${len2(d.getMonth() + 1)}-${len2(d.getDate())}`)()
}
function insertTimeLocal() {
let d = new Date()
textInserter(`${len2(d.getHours())}:${len2(d.getMinutes())}:${len2(d.getSeconds())}`)()
}
function insertUserlink() { function insertUserlink() {
const userlink = document.querySelector('.auth-links__user-link') const userlink = document.querySelector('.auth-links__user-link')
const userHypha = userlink.getAttribute('href').substring(7) // no /hypha/ const userHypha = userlink.getAttribute('href').substring(7) // no /hypha/
@ -124,8 +138,10 @@ const buttonsHandlers = {
codeblock: insertCodeblock, codeblock: insertCodeblock,
bulletedlist: insertBulletedList, bulletedlist: insertBulletedList,
numberedlist: insertNumberedList, numberedlist: insertNumberedList,
date: insertDate, 'date-utc': insertDateUTC,
time: insertTimeUTC, 'time-utc': insertTimeUTC,
'date-local': insertDateLocal,
'time-local': insertTimeLocal,
'user-link': insertUserlink, 'user-link': insertUserlink,
} }
for (const key of Object.keys(buttonsHandlers)) { for (const key of Object.keys(buttonsHandlers)) {