Shinchoku

This commit is contained in:
cutls 2020-07-10 22:33:12 +09:00
parent fba3b99b54
commit 2c54e43e37
9 changed files with 7729 additions and 2771 deletions

View File

@ -1,10 +1,11 @@
async function getJson(start) { async function getApi(start, at) {
let json = {} let json = {}
let response = null let response = null
response = await fetch(start, { response = await fetch(start, {
method: 'GET', method: 'GET',
headers: { headers: {
'content-type': 'application/json' 'content-type': 'application/json',
'Authorization': `Bearer ${at}`
} }
}) })
if (!response.ok) { if (!response.ok) {
@ -14,4 +15,24 @@ async function getJson(start) {
} }
json = await response.json() json = await response.json()
return json return json
}
async function postApi(url, body, at, ideKey) {
let json = {}
let response = null
response = await fetch(url, {
method: 'POST',
headers: {
'content-type': 'application/json',
'Authorization': `Bearer ${at}`,
'Idempotency-Key': ideKey
},
body: JSON.stringify(body)
})
if (!response.ok) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
json = await response.json()
return json
} }

View File

@ -1,5 +1,5 @@
//バージョンチェッカー //バージョンチェッカー
async function verck(ver, jp) { async function verck(ver) {
console.log('%c Welcome😊 ' + ver, 'color: red;font-size:200%;') console.log('%c Welcome😊 ' + ver, 'color: red;font-size:200%;')
document.querySelector('body').classList.add(localStorage.getItem('platform')) document.querySelector('body').classList.add(localStorage.getItem('platform'))
const date = new Date() const date = new Date()
@ -8,20 +8,7 @@ async function verck(ver, jp) {
showVer = true showVer = true
console.log('%c Thank you for your update🎉', 'color: red;font-size:200%;') console.log('%c Thank you for your update🎉', 'color: red;font-size:200%;')
if (localStorage.getItem('winstore') && !pwa) { if (localStorage.getItem('winstore') && !pwa) {
M.Modal.getInstance(document.querySelector('#releasenote')).open() openRN()
}
verp = ver.replace('(', '')
verp = verp.replace('.', '-')
verp = verp.replace('.', '-')
verp = verp.replace('[', '-')
verp = verp.replace(']', '')
verp = verp.replace(')', '')
verp = verp.replace(' ', '_')
console.log('%c ' + verp, 'color: red;font-size:200%;')
if (lang.language == 'ja') {
showElm(`#release-${verp}`)
} else {
showElm('#release-en')
} }
} }
localStorage.setItem('ver', ver) localStorage.setItem('ver', ver)
@ -73,12 +60,12 @@ async function verck(ver, jp) {
// 生成する文字列に含める文字セット // 生成する文字列に含める文字セット
const c = 'abcdefghijklmnopqrstuvwxyz0123456789' const c = 'abcdefghijklmnopqrstuvwxyz0123456789'
const cl = c.length const cl = c.length
const r = '' let r = ''
for (var i = 0; i < l; i++) { for (var i = 0; i < l; i++) {
r += c[Math.floor(Math.random() * cl)] r += c[Math.floor(Math.random() * cl)]
} }
const start = 'https://thedesk.top/ver.json' const start = 'https://thedesk.top/ver.json'
const mess = await getJson(start) const mess = await getApi(start, null)
console.table(mess) console.table(mess)
if (mess) { if (mess) {
let newest = null let newest = null
@ -111,7 +98,7 @@ async function verck(ver, jp) {
lni = 0 lni = 0
} }
const getNotice = 'https://thedesk.top/notice/index.php?since_id=' + lni const getNotice = 'https://thedesk.top/notice/index.php?since_id=' + lni
const notices = await getJson(getNotice) const notices = await getApi(getNotice, null)
if (notices.length < 1) { if (notices.length < 1) {
return false return false
} else { } else {
@ -140,7 +127,10 @@ function infowebsocket() {
if (obj.type != 'counter') { if (obj.type != 'counter') {
toastInterpret(obj) toastInterpret(obj)
} else { } else {
document.querySelector('#persons').innerText = obj.text const people = document.querySelector('#persons')
if(people) {
people.innerText = obj.text
}
} }
} }
infows.onerror = function (error) { infows.onerror = function (error) {
@ -195,11 +185,11 @@ async function toastInterpret(obj) {
displayLength: 86400 displayLength: 86400
}) })
await sleep(500) await sleep(500)
const targets = document.querySelectorAll('toast-action') const targets = document.querySelectorAll('.toast-action')
for (let j = 0; j < targets.length; i++) { for (let j = 0; j < targets.length; j++) {
const target = targets[j] const target = targets[j]
const toot = target.getAttribute('data-toot') const toot = target.getAttribute('data-toot')
target.addEventListener('click', detEx(toot, 'main')) target.addEventListener('click', () => detEx(toot, 'main'))
} }
} }
@ -207,6 +197,7 @@ async function toastInterpret(obj) {
} }
} }
function openRN() { function openRN() {
console.log(kirishima)
M.Modal.getInstance(document.querySelector('#releasenote')).open() M.Modal.getInstance(document.querySelector('#releasenote')).open()
if (lang.language == 'ja') { if (lang.language == 'ja') {
verp = ver.replace('(', '').replace('.', '-').replace('.', '-').replace('[', '-').replace(']', '').replace(')', '').replace(' ', '_') verp = ver.replace('(', '').replace('.', '-').replace('.', '-').replace('[', '-').replace(']', '').replace(')', '').replace(' ', '_')

View File

@ -1,5 +1,5 @@
var defaultemojiList = ['activity', 'flag', 'food', 'nature', 'object', 'people', 'place', 'symbol'] const defaultemojiList = ['activity', 'flag', 'food', 'nature', 'object', 'people', 'place', 'symbol']
var defaultemoji = { const defaultemoji = {
activity: activity, activity: activity,
flag: flag, flag: flag,
food: food, food: food,
@ -9,8 +9,18 @@ var defaultemoji = {
place: place, place: place,
symbol: symbol symbol: symbol
} }
let defaultemojiname = {
activity: 'Activities',
flag: 'Flags',
food: 'Foods',
nature: 'Nature',
object: 'Tools',
people: 'People',
place: 'Places',
symbol: 'Symbols'
}
if (lang == 'ja') { if (lang == 'ja') {
var defaultemojiname = { defaultemojiname = {
activity: '活動', activity: '活動',
flag: '国旗', flag: '国旗',
food: '食べ物', food: '食べ物',
@ -20,33 +30,23 @@ if (lang == 'ja') {
place: '場所', place: '場所',
symbol: '記号' symbol: '記号'
} }
} else {
var defaultemojiname = {
activity: 'Activities',
flag: 'Flags',
food: 'Foods',
nature: 'Nature',
object: 'Tools',
people: 'People',
place: 'Places',
symbol: 'Symbols'
}
} }
function defaultEmoji(target) { function defaultEmoji(target) {
var announcement = false let announcement = false
if ($('#media').val() == 'announcement') { if (document.querySelector('#media').value == 'announcement') {
announcement = true announcement = true
} }
var json = defaultemoji[target] const json = defaultemoji[target]
var emojis = '' const keymap = Object.keys(json)
Object.keys(json).forEach(function(key) { let emojis = ''
var emoji = json[key] for (let i = 0; i < json.length; i++) {
if (announcement) { const key = keymap[i]
var def = `<a onclick="emojiReactionDef('${emoji['shortcode']}')" class="pointer">` const emoji = json[key]
} else { let def = `<a data-shortcode="${emoji['shortcode']}" class="pointer defEmoji">`
var def = `<a onclick="defEmoji('${emoji['shortcode']}')" class="pointer">` if (announcement) {
} def = `<a data-shortcode="${emoji['shortcode']}" class="pointer defEmoji">`
}
emojis = emojis =
emojis + emojis +
`${def} `${def}
@ -54,52 +54,39 @@ function defaultEmoji(target) {
width: 20px; height: 20px; display: inline-block; background-image: url('../../img/sheet.png'); background-size: 4900%; width: 20px; height: 20px; display: inline-block; background-image: url('../../img/sheet.png'); background-size: 4900%;
background-position:${emoji['css']};"></span> background-position:${emoji['css']};"></span>
</a>` </a>`
}) }
$('#emoji-list').html(emojis) document.querySelector('#emoji-list').innerHTML = emojis
$('#now-emoji').text(lang.lang_defaultemojis_text.replace('{{cat}}', defaultemojiname[target])) document.querySelector('#now-emoji').innerText = lang.lang_defaultemojis_text.replace('{{cat}}', defaultemojiname[target])
$('.emoji-control').addClass('hide') document.querySelector('.emoji-control').classList.add('hide')
const targets = document.querySelectorAll('.defEmoji')
for (let j = 0; j < targets.length; j++) {
const target = targets[j]
const sc = target.getAttribute('data-shortcode')
target.addEventListener('click', () => defEmoji(sc))
}
} }
function customEmoji() { function customEmoji() {
$('#emoji-suggest').val('') document.querySelector('#emoji-suggest').value = ''
$('.emoji-control').removeClass('hide') document.querySelector('.emoji-control').classList.remove('hide')
emojiList('home') emojiList('home')
} }
function defEmoji(target) { function defEmoji(target) {
var selin = $('#textarea').prop('selectionStart') const textarea = document.querySelector('#textarea')
let selin = textarea.selectionStart
if (!selin) { if (!selin) {
selin = 0 selin = 0
} }
var emojiraw = newpack.filter(function(item, index) { const hex = emojipack[target].unified.split('-')
if (item.short_name == target) return true let emoji = twemoji.convert.fromCodePoint(hex[0])
})
var hex = emojiraw[0].unified.split('-')
if (hex.length === 2) { if (hex.length === 2) {
emoji = twemoji.convert.fromCodePoint(hex[0]) + twemoji.convert.fromCodePoint(hex[1]) emoji = twemoji.convert.fromCodePoint(hex[0]) + twemoji.convert.fromCodePoint(hex[1])
} else {
emoji = twemoji.convert.fromCodePoint(hex[0])
} }
var now = $('#textarea').val() const now = textarea.value
var before = now.substr(0, selin) const before = now.substr(0, selin)
var after = now.substr(selin, now.length) const after = now.substr(selin, now.length)
newt = before + emoji + after const newt = before + emoji + after
$('#textarea').val(newt) textarea.value = newt
$('#textarea').focus() textarea.focus()
}
function faicon() {
var json = faicons
var emojis = ''
Object.keys(json).forEach(function(key) {
var emoji = json[key]
var eje = emoji.replace(/fa-/g, '')
emojis =
emojis +
'<a onclick="emojiInsert(\'[faicon]' +
eje +
'[/faicon]\')" class="pointer white-text" style="font-size:24px"><i class="fa ' +
emoji +
'"></i></a>'
})
$('#emoji-list').html(emojis)
$('#now-emoji').text('faicon')
$('.emoji-control').addClass('hide')
} }

File diff suppressed because one or more lines are too long

View File

@ -1,391 +1,119 @@
/*ログイン処理・認証までのJS*/ /*ログイン処理・認証までのJS*/
//最初に読むやつ //最初に読むやつ
//アスタルテ判定初期化
localStorage.removeItem('kirishima') localStorage.removeItem('kirishima')
localStorage.removeItem('quoters') localStorage.removeItem('quoters')
localStorage.removeItem('imas') localStorage.removeItem('imas')
localStorage.removeItem('image') //stable, 固定タグのことらしい。ふざけるな。
localStorage.removeItem('stable') localStorage.removeItem('stable')
localStorage.setItem('mode_misskey.xyz', 'misskey')
function ck() { function ck() {
var main = localStorage.getItem('main') const main = localStorage.getItem('main')
if (!main) { if (!main) {
localStorage.setItem('main', 0) localStorage.setItem('main', 0)
} }
//コード受信 //コード受信
if (location.search) { if (location.search) {
var m = location.search.match(/\?mode=([a-zA-Z-0-9]+)\&code=(.+)/) const m = location.search.match(/\?mode=([a-zA-Z-0-9]+)\&code=(.+)/)
var mode = m[1] const mode = m[1]
var codex = m[2] const codex = m[2]
if (mode == 'manager' || mode == 'login') { if (mode == 'manager' || mode == 'login') {
code(codex, mode) code(codex, mode)
} else { } else {
} }
} }
var multi = localStorage.getItem('multi') const multi = localStorage.getItem('multi')
if (!multi || multi == '[]') { if (!multi || multi == '[]') {
var date = new Date() const date = new Date()
localStorage.setItem('showSupportMe', date.getMonth() + 2) localStorage.setItem('showSupportMe', date.getMonth() + 2)
location.href = 'acct.html?mode=first&code=true' location.href = 'acct.html?mode=first&code=true'
} else { } else {
var obj = JSON.parse(multi) const obj = JSON.parse(multi)
var jp = false const keymap = Object.keys(obj)
Object.keys(obj).forEach(function(key) { for (let i = 0; i < keymap.length; i++) {
var acct = obj[key] const key = keymap[i]
const acct = obj[key]
if (acct.domain) { if (acct.domain) {
refresh(key, true) refresh(key, true)
} }
if (acct.domain == 'mstdn.jp') { }
jp = true
}
})
if (obj[0].domain) { if (obj[0].domain) {
$('#tl').show() showElm('#tl')
ticker() ticker()
multiSelector(false) multiSelector(false)
verck(ver, jp) verck(ver)
$('.stw').show() showElm('.stw')
if (localStorage.getItem('tips')) { const tips = localStorage.getItem('tips')
tips(localStorage.getItem('tips')) if (tips) {
tips(tips)
} }
$('#something-wrong img').attr('src', '../../img/thinking.svg') document.querySelector('#something-wrong img').setAttribute('src', '../../img/thinking.svg')
} }
} }
} }
ck() ck()
//ログインポップアップ
function login(url) {
if ($('#linux:checked').val() == 'on') {
var red = 'urn:ietf:wg:oauth:2.0:oob'
} else {
var red = 'thedesk://login'
}
localStorage.setItem('redirect', red)
var start = 'https://' + url + '/api/v1/apps'
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.responseType = 'json'
httpreq.send(
JSON.stringify({
scopes: 'read write follow',
client_name: 'TheDesk(PC)',
redirect_uris: red,
website: 'https://thedesk.top'
})
)
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
var json = httpreq.response
if (this.status !== 200) {
setLog(start, this.status, json)
}
var auth =
'https://' +
url +
'/oauth/authorize?client_id=' +
json['client_id'] +
'&client_secret=' +
json['client_secret'] +
'&response_type=code&redirect_uri=' +
red +
'&scope=read+write+follow'
localStorage.setItem('domain_' + acct_id, url)
localStorage.setItem('client_id', json['client_id'])
localStorage.setItem('client_secret', json['client_secret'])
$('#auth').show()
$('#masara').hide()
postMessage(['openUrl', auth], '*')
if ($('#linux:checked').val() == 'on') {
} else {
postMessage(['sendSinmpleIpc', 'quit'], '*')
}
}
}
}
//テキストボックスにURL入れた
function instance() {
var url = $('#url').val()
login(url)
}
//コードを入れた後認証
function code(code, mode) {
var red = localStorage.getItem('redirect')
localStorage.removeItem('redirect')
if (!code) {
var code = $('#code').val()
}
if (localStorage.getItem('domain_tmp')) {
var url = localStorage.getItem('domain_tmp')
} else {
var url = localStorage.getItem('domain_' + acct_id)
}
var start = 'https://' + url + '/oauth/token'
var id = localStorage.getItem('client_id')
var secret = localStorage.getItem('client_secret')
fetch(start, {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
grant_type: 'authorization_code',
redirect_uri: red,
client_id: id,
client_secret: secret,
code: code
})
})
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(json) {
todo(json)
if (json['access_token']) {
localStorage.setItem(url + '_at', json['access_token'])
if (mode == 'manager') {
getdataAdv(url, json['access_token'])
} else {
getdata()
}
}
})
}
//ユーザーデータ取得(最初)
function getdata() {
var acct_id = 0
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/v1/accounts/verify_credentials'
fetch(start, {
method: 'GET',
headers: {
'content-type': 'application/json',
Authorization: 'Bearer ' + at
}
})
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(json) {
if (json.error) {
console.error('Error:' + json.error)
M.toast({ html: lang.lang_fatalerroroccured + 'Error:' + json.error, displayLength: 5000 })
return
}
var avatar = json['avatar']
//missingがmissingなやつ
if (avatar == '/avatars/original/missing.png') {
avatar = './img/missing.svg'
}
var obj = [
{
at: at,
name: json['display_name'],
domain: domain,
user: json['acct'],
prof: avatar,
id: json['id'],
vis: json['source']['privacy']
}
]
var json = JSON.stringify(obj)
localStorage.setItem('multi', json)
localStorage.setItem('name_' + acct_id, json['display_name'])
localStorage.setItem('user_' + acct_id, json['acct'])
localStorage.setItem('user-id_' + acct_id, json['id'])
localStorage.setItem('prof_' + acct_id, avatar)
$('#masara').hide()
$('#auth').hide()
$('#tl').show()
parseColumn()
ckdb()
})
}
//ユーザーデータ取得(追加)
function getdataAdv(domain, at) {
var start = 'https://' + domain + '/api/v1/accounts/verify_credentials'
fetch(start, {
method: 'GET',
headers: {
'content-type': 'application/json',
Authorization: 'Bearer ' + at
}
})
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(json) {
if (json.error) {
console.error('Error:' + json.error)
M.toast({ html: lang.lang_fatalerroroccured + 'Error:' + json.error, displayLength: 5000 })
return
}
var avatar = json['avatar']
//missingがmissingなやつ
if (avatar == '/avatars/original/missing.png') {
avatar = '../../img/missing.svg'
}
if (json['source']['privacy']) {
var priv = json['source']['privacy']
} else {
var priv = 'public'
}
var add = {
at: at,
name: json['display_name'],
domain: domain,
user: json['acct'],
prof: avatar,
id: json['id'],
vis: priv
}
var multi = localStorage.getItem('multi')
var obj = JSON.parse(multi)
var target = obj.lengtth
obj.push(add)
localStorage.setItem('name_' + target, json['display_name'])
localStorage.setItem('user_' + target, json['acct'])
localStorage.setItem('user-id_' + target, json['id'])
localStorage.setItem('prof_' + target, avatar)
var json = JSON.stringify(obj)
localStorage.setItem('multi', json)
location.href = 'index.html'
})
}
//ユーザーデータ更新 //ユーザーデータ更新
function refresh(target, loadskip) { async function refresh(target, loadskip) {
var multi = localStorage.getItem('multi') const multi = localStorage.getItem('multi')
var obj = JSON.parse(multi) let obj = JSON.parse(multi)
if (obj[target].mode == 'misskey') { const {mode, domain, at, background, text} = obj[target]
if (mode == 'misskey') {
return return
} }
var start = 'https://' + obj[target].domain + '/api/v1/accounts/verify_credentials' const start = `https://${domain}/api/v1/accounts/verify_credentials`
fetch(start, { const json = await getApi(start, at)
method: 'GET', if (json.error) {
headers: { console.error('Error:' + json.error)
'content-type': 'application/json', M.toast({ html: lang.lang_fatalerroroccured + 'Error:' + json.error, displayLength: 5000 })
Authorization: 'Bearer ' + obj[target].at return
} }
}) let avatar = json['avatar']
.then(function(response) { //missingがmissingなやつ
if (!response.ok) { if (avatar == '/avatars/original/missing.png' || !avatar) {
response.text().then(function(text) { avatar = './img/missing.svg'
setLog(response.url, response.status, text) }
}) let ref = {
} at: at,
return response.json() name: json['display_name'],
}) domain: domain,
.catch(function(error) { user: json['acct'],
todo(error) prof: avatar,
setLog(start, 'JSON', error) id: json['id'],
console.error(error) vis: json['source']['privacy']
}) }
.then(function(json) { if (background) {
if (json.error) { ref.background = background
console.error('Error:' + json.error) }
M.toast({ html: lang.lang_fatalerroroccured + 'Error:' + json.error, displayLength: 5000 }) if (text) {
return ref.text = text
} }
var avatar = json['avatar'] if (json['source']['sensitive']) {
//missingがmissingなやつ localStorage.setItem('nsfw_' + target, 'true')
if (avatar == '/avatars/original/missing.png' || !avatar) { } else {
avatar = './img/missing.svg' localStorage.removeItem('nsfw_' + target)
} }
var ref = { obj[target] = ref
at: obj[target].at, const save = JSON.stringify(obj)
name: json['display_name'], localStorage.setItem('multi', save)
domain: obj[target].domain, if (!loadskip) {
user: json['acct'], load()
prof: avatar, }
id: json['id'],
vis: json['source']['privacy']
}
if (obj[target].background) {
ref.background = obj[target].background
}
if (obj[target].text) {
ref.text = obj[target].text
}
localStorage.setItem('name_' + target, json['display_name'])
localStorage.setItem('user_' + target, json['acct'])
localStorage.setItem('user-id_' + target, json['id'])
localStorage.setItem('prof_' + target, avatar)
localStorage.setItem('follow_' + target, json['following_count'])
if (json['source']['sensitive']) {
localStorage.setItem('nsfw_' + target, 'true')
} else {
localStorage.removeItem('nsfw_' + target)
}
obj[target] = ref
var json = JSON.stringify(obj)
localStorage.setItem('multi', json)
if (!loadskip) {
load()
}
})
} }
//MarkdownやBBCodeの対応、文字数制限をチェック //MarkdownやBBCodeの対応、文字数制限をチェック
//絶対ストリーミングを閉じさせないマン //絶対ストリーミングを閉じさせないマン
function ckdb(acct_id) { function ckdb(acct_id) {
var domain = localStorage.getItem('domain_' + acct_id) const domain = localStorage.getItem(`domain_${acct_id}`)
localStorage.removeItem('home_' + acct_id)
localStorage.removeItem('bb_' + acct_id)
localStorage.removeItem('md_' + acct_id)
localStorage.removeItem('local_' + acct_id)
localStorage.removeItem('public_' + acct_id)
localStorage.removeItem('notification_' + acct_id)
localStorage.removeItem('post_' + acct_id)
localStorage.removeItem('fav_' + acct_id)
localStorage.removeItem('bt_' + acct_id)
localStorage.removeItem('followlocale_' + acct_id)
if (domain == 'kirishima.cloud') { if (domain == 'kirishima.cloud') {
localStorage.setItem('kirishima', 'true') localStorage.setItem('kirishima', 'true')
} else if (domain == 'imastodon.net') { } else if (domain == 'imastodon.net') {
localStorage.setItem('imas', 'true') localStorage.setItem('imas', 'true')
$('.imasonly').show() showElm('.imasonly')
} }
var at = localStorage.getItem('acct_' + acct_id + '_at') const at = localStorage.getItem(`acct_${acct_id}_at`)
var bbcode = domain + '_bbcode' const letters = `${domain}_letters`
var letters = domain + '_letters' const quoteMarker = `${domain}_quote`
var quoteMarker = domain + '_quote'
if (idata) { if (idata) {
//check and replace json to idata //check and replace json to idata
var json = idata var json = idata
@ -448,13 +176,13 @@ function ckdb(acct_id) {
'content-type': 'application/json' 'content-type': 'application/json'
} }
}) })
.then(function(response) { .then(function (response) {
return response.json() return response.json()
}) })
.catch(function(error) { .catch(function (error) {
console.error(error) console.error(error)
}) })
.then(function(json) { .then(function (json) {
if (json.error) { if (json.error) {
console.error(json.error) console.error(json.error)
return return
@ -501,7 +229,7 @@ function multiSelector(parseC) {
$('#src-acct-sel').html('<option value="tootsearch">Tootsearch</option>') $('#src-acct-sel').html('<option value="tootsearch">Tootsearch</option>')
$('#add-acct-sel').html('<option value="noauth">' + lang.lang_login_noauth + '</option>') $('#add-acct-sel').html('<option value="noauth">' + lang.lang_login_noauth + '</option>')
} else { } else {
Object.keys(obj).forEach(function(key) { Object.keys(obj).forEach(function (key) {
var acct = obj[key] var acct = obj[key]
var list = key * 1 + 1 var list = key * 1 + 1
if (key + '' === last) { if (key + '' === last) {
@ -569,8 +297,8 @@ function multiSelector(parseC) {
$('#src-acct-sel').append('<option value="tootsearch">Tootsearch</option>') $('#src-acct-sel').append('<option value="tootsearch">Tootsearch</option>')
$('#add-acct-sel').append( $('#add-acct-sel').append(
'<option value="noauth">' + '<option value="noauth">' +
lang.lang_login_noauth + lang.lang_login_noauth +
'</option><option value="webview">Twitter</option>' '</option><option value="webview">Twitter</option>'
) )
$('#dir-acct-sel').append('<option value="noauth">' + lang.lang_login_noauth + '</option>') $('#dir-acct-sel').append('<option value="noauth">' + lang.lang_login_noauth + '</option>')
} }
@ -599,18 +327,18 @@ function ticker() {
'content-type': 'application/json' 'content-type': 'application/json'
} }
}) })
.then(function(response) { .then(function (response) {
if (!response.ok) { if (!response.ok) {
response.text().then(function(text) { response.text().then(function (text) {
setLog(response.url, response.status, text) setLog(response.url, response.status, text)
}) })
} }
return response.json() return response.json()
}) })
.catch(function(error) { .catch(function (error) {
console.error(error) console.error(error)
}) })
.then(function(json) { .then(function (json) {
if (json) { if (json) {
localStorage.setItem('ticker', JSON.stringify(json)) localStorage.setItem('ticker', JSON.stringify(json))
} }

View File

@ -306,4 +306,12 @@ function showElm(query) {
target.style.display = 'inherit' target.style.display = 'inherit'
} }
} }
function setAllClasses(query, className, action) {
const allTarget = document.querySelectorAll(query)
for (let i = 0; i < allTarget.length; i++) {
const target = allTarget[i]
if(action == 'add') target.classList.add(className)
if(action == 'remove') target.classList.remove(className)
}
}
const sleep = msec => new Promise(resolve => setTimeout(resolve, msec)); const sleep = msec => new Promise(resolve => setTimeout(resolve, msec));

View File

@ -108,7 +108,6 @@ async function media(b64, type, no, stamped) {
} }
$('.toot-btn-group').prop('disabled', true) $('.toot-btn-group').prop('disabled', true)
$('#post-acct-sel').prop('disabled', true) $('#post-acct-sel').prop('disabled', true)
localStorage.setItem('image', 'busy')
todo('Image Upload...') todo('Image Upload...')
var media = toBlob(b64, type) var media = toBlob(b64, type)
var fd = new FormData() var fd = new FormData()
@ -159,7 +158,6 @@ async function media(b64, type, no, stamped) {
M.toast({ html: '<span>' + lang.lang_postimg_sync + '</span><button class="btn-flat toast-action" onclick="syncDetail()">Click</button>', displayLength: 3000 }) M.toast({ html: '<span>' + lang.lang_postimg_sync + '</span><button class="btn-flat toast-action" onclick="syncDetail()">Click</button>', displayLength: 3000 })
$('#imgup').text('') $('#imgup').text('')
$('#imgsel').show() $('#imgsel').show()
localStorage.removeItem('image')
} }
} catch { } catch {
var start = 'https://' + domain + '/api/v1/media' var start = 'https://' + domain + '/api/v1/media'

View File

@ -342,7 +342,6 @@ function clear() {
$('.mastodon-choice').map(function() { $('.mastodon-choice').map(function() {
$(this).val('') $(this).val('')
}) })
localStorage.removeItem('image')
if (localStorage.getItem('mainuse') == 'main') { if (localStorage.getItem('mainuse') == 'main') {
$('#post-acct-sel').val(localStorage.getItem('main')) $('#post-acct-sel').val(localStorage.getItem('main'))
} }

View File

@ -1,65 +1,68 @@
//プロフ編集 //プロフ編集
//文字系 //文字系
function profedit() { function profedit() {
var acct_id = $('#his-data').attr("use-acct"); var acct_id = $('#his-data').attr('use-acct')
todo("Updating..."); todo('Updating...')
var domain = localStorage.getItem("domain_" + acct_id); var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem("acct_" + acct_id + "_at"); var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = "https://" + domain + "/api/v1/accounts/update_credentials"; var start = 'https://' + domain + '/api/v1/accounts/update_credentials'
var name = $("#his-name-val").val(); var name = $('#his-name-val').val()
var des = $("#his-des-val").val(); var des = $('#his-des-val').val()
var httpreq = new XMLHttpRequest(); var httpreq = new XMLHttpRequest()
httpreq.open('PATCH', start, true); httpreq.open('PATCH', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json'); httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at); httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = "json"; httpreq.responseType = 'json'
httpreq.send(JSON.stringify({ httpreq.send(
display_name: name, JSON.stringify({
note: des, display_name: name,
})); note: des,
})
)
httpreq.onreadystatechange = function () { httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) { if (httpreq.readyState === 4) {
$('#his-data').modal('close'); $('#his-data').modal('close')
todc(); todc()
} }
} }
} }
//画像系 //画像系
function imgChange(imgfile, target) { function imgChange(imgfile, target) {
var acct_id = $('#his-data').attr("use-acct"); var acct_id = $('#his-data').attr('use-acct')
todo("アップロードしています") todo('アップロードしています')
if (!imgfile.files.length) { if (!imgfile.files.length) {
console.warn("No Image to upload"); console.warn('No Image to upload')
return; return
} }
var file = imgfile.files[0]; var file = imgfile.files[0]
var fr = new FileReader(); var fr = new FileReader()
fr.onload = function (evt) { fr.onload = function (evt) {
var b64 = this.result; var b64 = this.result
var blob = toBlob(b64, 'image/png'); var blob = toBlob(b64, 'image/png')
var fd = new FormData(); var fd = new FormData()
fd.append(target, blob); fd.append(target, blob)
var domain = localStorage.getItem("domain_" + acct_id); var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem("acct_" + acct_id + "_at"); var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = "https://" + domain + "/api/v1/accounts/update_credentials"; var start = 'https://' + domain + '/api/v1/accounts/update_credentials'
var httpreq = new XMLHttpRequest(); var httpreq = new XMLHttpRequest()
httpreq.open('PATCH', start, true); httpreq.open('PATCH', start, true)
httpreq.upload.addEventListener("progress", progshow, false); httpreq.upload.addEventListener('progress', progshow, false)
httpreq.setRequestHeader('Authorization', 'Bearer ' + at); httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = "json"; httpreq.responseType = 'json'
httpreq.send(fd); httpreq.send(fd)
httpreq.onreadystatechange = function () { httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) { if (httpreq.readyState === 4) {
var json = httpreq.response; var json = httpreq.response
if(this.status!==200){ setLog(start, this.status, this.response); } if (this.status !== 200) {
$('#his-data').modal('close'); setLog(start, this.status, this.response)
todc(); }
localStorage.removeItem("image"); $('#his-data').modal('close')
todc()
} }
} }
} }
$("#prof-change").html($("#prof-change").html()); $('#prof-change').html($('#prof-change').html())
$("#header-change").html($("#header-change").html()); $('#header-change').html($('#header-change').html())
fr.readAsDataURL(file); fr.readAsDataURL(file)
} }