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

Commit

Permalink
Merge pull request #903 from moz65535/Enhanced_commentary_mode
Browse files Browse the repository at this point in the history
実況モード強化
  • Loading branch information
Cutls authored Apr 22, 2023
2 parents 876c36b + b017cea commit 5fa6046
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 15 deletions.
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 @@ -180,12 +186,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

0 comments on commit 5fa6046

Please sign in to comment.