Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

実況モード強化 #903

Merged
merged 5 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/js/common/keyshortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ export function initKeyboard() {
}
}
}
//Ctrl+Alt+Enter:実況なし投稿
if (e.metaKey || (e.ctrlKey && wv)) {
if (e.altKey) {
if (e.keyCode === 13) {
post(undefined,undefined,true)
return false
}
}
}
//Ctrl+Alt+C:全消し(実況タグセットなし)
if (e.metaKey || (e.ctrlKey && wv)) {
if (e.altKey) {
if (e.keyCode === 67) {
clear(true)
return false
}
}
}
//Ctrl+Enter:投稿
if (e.metaKey || (e.ctrlKey && wv)) {
if (e.keyCode === 13) {
Expand Down
22 changes: 15 additions & 7 deletions app/js/post/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function sec() {
}
post(mode)
}
export async function post(postVis?: IVis, dry?: boolean) {
export async function post(postVis?: IVis, dry?: boolean, tagClear?: boolean ) {
if (!navigator.onLine && !dry) {
draftToggle(true)
addToDraft()
Expand Down Expand Up @@ -74,8 +74,14 @@ export async function post(postVis?: IVis, dry?: boolean) {
const editTarget = $('#tootmodal').attr('data-edit')
if (editTarget) start = start + `/${editTarget}`
const reply = $('#reply').val()
const stable = localStorage.getItem('stable')
if (stable && !str.match(stable)) str = `${str} #${stable}`
const stable = JSON.parse(localStorage.getItem('stable') || '[]')
for (const tag of stable){
if (tagClear){
str = str.replace(new RegExp(`(\\s#${tag}\\s)`, 'g'), ' ').replace(new RegExp(`(^#${tag}\\s|\\s#${tag}$|^#${tag}$)`, 'g'), '')
} else {
if (!str.match(tag)) str = `${str} #${tag}`
}
}
const toot: StatusTheDeskExtend = {
status: str,
}
Expand Down Expand Up @@ -179,12 +185,14 @@ export function expPostMode() {
})
}
}
//クリア(Shift+C)
export function clear() {
//クリア(Shift+C,Alt+Shift+C:Alt+Shift+Cの場合は実況タグをセットしない)
export function clear(clearTags?: boolean) {
$('#textarea').val('')
$('#ideKey').val('')
if (localStorage.getItem('stable')) {
$('#textarea').val('#' + localStorage.getItem('stable') + ' ')
const stable = JSON.parse(localStorage.getItem('stable') || '[]')
if (!clearTags && stable.length) {
const tags = `#${stable.join(' #')} `
$('#textarea').val(tags)
}
$('#textarea').attr('placeholder', lang.lang_toot)
$('#reply').val('')
Expand Down
36 changes: 28 additions & 8 deletions app/js/tl/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import lang from '../common/lang'
import { columnReload, tl } from './tl'
import { brInsert } from '../post/emoji'
import { escapeHTML } from '../platform/first'
import { toast } from '../common/declareM'
import { characterCounterInit, toast } from '../common/declareM'
import api from '../common/fetch'
import { getColumn, setColumn } from '../common/storage'
import { IColumnData, IColumnTag, IColumnType } from '../../interfaces/Storage'
Expand Down Expand Up @@ -70,6 +70,20 @@ function tagPin(tag: string) {
export function tagRemove(key: number) {
const tags = localStorage.getItem('tag') || '[]'
const obj = JSON.parse(tags)
const pt = localStorage.getItem('stable') || '[]'
const nowPT = JSON.parse(pt)
let str = $('#textarea').val()?.toString() || ''
for (const PTag of nowPT) {
if (PTag === obj[key]) {
str = str.replace(new RegExp(`(\\s#${PTag}\\s)`, 'g'), ' ').replace(new RegExp(`(^#${PTag}\\s|\\s#${PTag}$|^#${PTag}$)`, 'g'), '')
$('#textarea').val(str)
characterCounterInit($('#textarea'))
nowPT.splice(nowPT.indexOf(obj[key]), 1)
localStorage.setItem('stable', JSON.stringify(nowPT))
toast({ html: PTag + ' ' + lang.lang_tags_unrealtime, displayLength: 3000 })
break
}
}
obj.splice(key, 1)
const json = JSON.stringify(obj)
localStorage.setItem('tag', json)
Expand All @@ -80,12 +94,12 @@ export function favTag() {
const tagArr = localStorage.getItem('tag') || '[]'
const obj = JSON.parse(tagArr)
let tags = ''
const nowPT = localStorage.getItem('stable')
const nowPT = JSON.parse(localStorage.getItem('stable') || '[]')
let key = 0
for (const tagRaw of obj) {
let ptt = lang.lang_tags_unrealtime
let nowon = `(${lang.lang_tags_realtime})`
if (nowPT !== tagRaw) {
if (!nowPT.includes(tagRaw)) {
ptt = lang.lang_tags_realtime
nowon = ''
}
Expand Down Expand Up @@ -121,12 +135,18 @@ export function tagTL(a: IColumnType, b: string, d: string) {
}
export function autoToot(tag: string) {
tag = escapeHTML(tag)
const nowPT = localStorage.getItem('stable')
if (nowPT === tag) {
localStorage.removeItem('stable')
toast({ html: lang.lang_tags_unrealtime, displayLength: 3000 })
const nowPT = JSON.parse(localStorage.getItem('stable') || '[]')
if (nowPT.includes(tag)) {
let str = $('#textarea').val()?.toString() || ''
str = str.replace(new RegExp(`(\\s#${tag}\\s)`, 'g'), ' ').replace(new RegExp(`(^#${tag}\\s|\\s#${tag}$|^#${tag}$)`, 'g'), '')
$('#textarea').val(str)
characterCounterInit($('#textarea'))
nowPT.splice(nowPT.indexOf(tag), 1)
localStorage.setItem('stable', JSON.stringify(nowPT))
toast({ html: tag + ' ' + lang.lang_tags_unrealtime, displayLength: 3000 })
} else {
localStorage.setItem('stable', tag)
nowPT.push(tag)
localStorage.setItem('stable', JSON.stringify(nowPT))
toast({
html: lang.lang_tags_tagwarn.replace('{{tag}}', tag).replace('{{tag}}', tag),
displayLength: 3000,
Expand Down