2018-01-28 21:22:43 +09:00
|
|
|
/*ログイン処理・認証までのJS*/
|
|
|
|
//最初に読むやつ
|
2018-03-31 11:39:06 +09:00
|
|
|
|
2019-11-10 20:37:13 +09:00
|
|
|
localStorage.removeItem('kirishima')
|
|
|
|
localStorage.removeItem('quoters')
|
|
|
|
localStorage.removeItem('imas')
|
2020-07-10 22:33:12 +09:00
|
|
|
//stable, 固定タグのことらしい。ふざけるな。
|
2019-11-10 20:37:13 +09:00
|
|
|
localStorage.removeItem('stable')
|
2020-07-12 00:48:15 +09:00
|
|
|
const acctList = JSON.parse(localStorage.getItem('multi'))
|
2020-07-10 22:33:12 +09:00
|
|
|
|
2020-07-21 09:06:58 +09:00
|
|
|
async function ck() {
|
2020-07-10 22:33:12 +09:00
|
|
|
const main = localStorage.getItem('main')
|
2019-05-19 16:39:30 +09:00
|
|
|
if (!main) {
|
2020-07-12 00:48:15 +09:00
|
|
|
localStorage.setItem('main', '0')
|
2018-05-20 15:17:10 +09:00
|
|
|
}
|
2019-11-04 01:10:06 +09:00
|
|
|
|
2018-02-18 14:43:11 +09:00
|
|
|
//コード受信
|
2019-05-19 16:39:30 +09:00
|
|
|
if (location.search) {
|
2020-07-10 22:33:12 +09:00
|
|
|
const m = location.search.match(/\?mode=([a-zA-Z-0-9]+)\&code=(.+)/)
|
|
|
|
const mode = m[1]
|
|
|
|
const codex = m[2]
|
2019-11-10 20:37:13 +09:00
|
|
|
if (mode == 'manager' || mode == 'login') {
|
|
|
|
code(codex, mode)
|
2019-05-19 16:39:30 +09:00
|
|
|
} else {
|
2018-02-18 14:43:11 +09:00
|
|
|
}
|
|
|
|
}
|
2020-07-10 22:33:12 +09:00
|
|
|
const multi = localStorage.getItem('multi')
|
2019-11-10 20:37:13 +09:00
|
|
|
if (!multi || multi == '[]') {
|
2020-07-10 22:33:12 +09:00
|
|
|
const date = new Date()
|
2019-11-10 20:37:13 +09:00
|
|
|
localStorage.setItem('showSupportMe', date.getMonth() + 2)
|
|
|
|
location.href = 'acct.html?mode=first&code=true'
|
2019-05-19 16:39:30 +09:00
|
|
|
} else {
|
2020-07-10 22:33:12 +09:00
|
|
|
const obj = JSON.parse(multi)
|
|
|
|
const keymap = Object.keys(obj)
|
2020-07-12 00:48:15 +09:00
|
|
|
let req = false
|
2020-07-10 22:33:12 +09:00
|
|
|
for (let i = 0; i < keymap.length; i++) {
|
|
|
|
const key = keymap[i]
|
|
|
|
const acct = obj[key]
|
2019-05-19 16:39:30 +09:00
|
|
|
if (acct.domain) {
|
2020-07-21 09:06:58 +09:00
|
|
|
let refreshed = await refresh(key, true)
|
2020-07-21 12:44:53 +09:00
|
|
|
if (refreshed) req = true
|
2019-05-19 16:39:30 +09:00
|
|
|
}
|
2020-07-10 22:33:12 +09:00
|
|
|
}
|
2020-07-21 12:44:53 +09:00
|
|
|
if (req) {
|
2020-07-12 00:48:15 +09:00
|
|
|
Swal.fire({
|
|
|
|
title: 'Reload required',
|
|
|
|
text: lang.lang_login_changedData,
|
|
|
|
type: 'info',
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonText: lang.lang_no,
|
|
|
|
cancelButtonText: lang.lang_yesno
|
|
|
|
}).then(result => {
|
2020-07-21 12:44:53 +09:00
|
|
|
if (result) location.reload()
|
2020-07-12 00:48:15 +09:00
|
|
|
})
|
|
|
|
}
|
2019-05-19 16:39:30 +09:00
|
|
|
if (obj[0].domain) {
|
2020-07-10 22:33:12 +09:00
|
|
|
showElm('#tl')
|
2019-11-10 20:37:13 +09:00
|
|
|
ticker()
|
2020-07-21 12:44:53 +09:00
|
|
|
parseColumn()
|
2020-07-10 22:33:12 +09:00
|
|
|
verck(ver)
|
|
|
|
showElm('.stw')
|
2020-07-21 12:44:53 +09:00
|
|
|
const tipsType = localStorage.getItem('tips')
|
|
|
|
if (tipsType) {
|
|
|
|
tips(tipsType)
|
2020-04-08 15:27:47 +09:00
|
|
|
}
|
2020-07-10 22:33:12 +09:00
|
|
|
document.querySelector('#something-wrong img').setAttribute('src', '../../img/thinking.svg')
|
2019-02-05 11:33:32 +09:00
|
|
|
}
|
2018-01-28 21:22:43 +09:00
|
|
|
}
|
|
|
|
}
|
2019-11-10 20:37:13 +09:00
|
|
|
ck()
|
2020-07-10 22:33:12 +09:00
|
|
|
//ユーザーデータ更新
|
|
|
|
async function refresh(target, loadskip) {
|
2020-07-12 00:48:15 +09:00
|
|
|
let obj = acctList
|
|
|
|
let requireReload = false
|
|
|
|
const { mode, domain, at, background, text, name, prof, vis } = obj[target]
|
2020-07-10 22:33:12 +09:00
|
|
|
if (mode == 'misskey') {
|
|
|
|
return
|
2018-02-26 00:32:10 +09:00
|
|
|
}
|
2020-07-10 22:33:12 +09:00
|
|
|
const start = `https://${domain}/api/v1/accounts/verify_credentials`
|
2020-07-21 09:06:58 +09:00
|
|
|
let json
|
2020-07-21 12:44:53 +09:00
|
|
|
try {
|
2020-07-21 09:06:58 +09:00
|
|
|
json = await getApi(start, at)
|
|
|
|
} catch {
|
|
|
|
return false
|
|
|
|
}
|
2020-07-10 22:33:12 +09:00
|
|
|
if (json.error) {
|
|
|
|
console.error('Error:' + json.error)
|
|
|
|
M.toast({ html: lang.lang_fatalerroroccured + 'Error:' + json.error, displayLength: 5000 })
|
|
|
|
return
|
2019-11-10 20:37:13 +09:00
|
|
|
}
|
2020-07-21 12:44:53 +09:00
|
|
|
if (!json) return false
|
2020-07-10 22:33:12 +09:00
|
|
|
let avatar = json['avatar']
|
|
|
|
//missingがmissingなやつ
|
|
|
|
if (avatar == '/avatars/original/missing.png' || !avatar) {
|
|
|
|
avatar = './img/missing.svg'
|
|
|
|
}
|
2020-07-21 09:06:58 +09:00
|
|
|
const newName = json.display_name
|
|
|
|
const newProf = avatar
|
|
|
|
const newVis = json.source.privacy
|
2020-07-12 00:48:15 +09:00
|
|
|
if (newName != name || newProf != prof || newVis != vis) {
|
|
|
|
let ref = {
|
|
|
|
at: at,
|
2020-07-21 09:06:58 +09:00
|
|
|
name: newName,
|
2020-07-12 00:48:15 +09:00
|
|
|
domain: domain,
|
|
|
|
user: json['acct'],
|
|
|
|
prof: avatar,
|
|
|
|
id: json['id'],
|
2020-07-21 09:06:58 +09:00
|
|
|
vis: newVis
|
2020-07-12 00:48:15 +09:00
|
|
|
}
|
|
|
|
if (background) {
|
|
|
|
ref.background = background
|
|
|
|
}
|
|
|
|
if (text) {
|
|
|
|
ref.text = text
|
|
|
|
}
|
|
|
|
if (json['source']['sensitive']) {
|
|
|
|
localStorage.setItem('nsfw_' + target, true)
|
|
|
|
} else {
|
|
|
|
localStorage.removeItem('nsfw_' + target)
|
|
|
|
}
|
|
|
|
obj[target] = ref
|
|
|
|
const save = JSON.stringify(obj)
|
|
|
|
localStorage.setItem('multi', save)
|
|
|
|
requireReload = true
|
2018-02-18 14:43:11 +09:00
|
|
|
}
|
2020-07-10 22:33:12 +09:00
|
|
|
if (!loadskip) {
|
|
|
|
load()
|
2020-07-12 00:48:15 +09:00
|
|
|
} else {
|
|
|
|
return requireReload
|
2018-08-17 02:21:40 +09:00
|
|
|
}
|
|
|
|
}
|
2018-03-27 11:39:35 +09:00
|
|
|
//MarkdownやBBCodeの対応、文字数制限をチェック
|
2018-08-17 02:21:40 +09:00
|
|
|
//絶対ストリーミングを閉じさせないマン
|
2020-07-21 12:44:53 +09:00
|
|
|
async function ckdb(acct_id) {
|
2020-07-10 22:33:12 +09:00
|
|
|
const domain = localStorage.getItem(`domain_${acct_id}`)
|
2019-11-10 20:37:13 +09:00
|
|
|
if (domain == 'kirishima.cloud') {
|
2020-07-12 00:48:15 +09:00
|
|
|
localStorage.setItem('kirishima', true)
|
2019-11-10 20:37:13 +09:00
|
|
|
} else if (domain == 'imastodon.net') {
|
2020-07-12 00:48:15 +09:00
|
|
|
localStorage.setItem('imas', true)
|
2020-07-10 22:33:12 +09:00
|
|
|
showElm('.imasonly')
|
2018-02-09 01:43:11 +09:00
|
|
|
}
|
2020-07-10 22:33:12 +09:00
|
|
|
const at = localStorage.getItem(`acct_${acct_id}_at`)
|
|
|
|
const letters = `${domain}_letters`
|
|
|
|
const quoteMarker = `${domain}_quote`
|
2020-07-12 00:48:15 +09:00
|
|
|
|
2020-07-10 14:16:39 +09:00
|
|
|
if (idata) {
|
2020-07-10 14:21:24 +09:00
|
|
|
//check and replace json to idata
|
2020-08-31 00:23:55 +09:00
|
|
|
const json = idata
|
2019-11-10 20:37:13 +09:00
|
|
|
if (json[quoteMarker] == 'enabled') {
|
2020-07-12 00:48:15 +09:00
|
|
|
localStorage.setItem('quoters', true)
|
2020-07-21 12:44:53 +09:00
|
|
|
localStorage.setItem(quoteMarker, true)
|
2019-05-19 16:39:30 +09:00
|
|
|
}
|
2020-07-12 00:48:15 +09:00
|
|
|
}
|
|
|
|
if (!isMisskey(domain)) {
|
|
|
|
const start = `https://${domain}/api/v1/instance`
|
2020-07-21 12:44:53 +09:00
|
|
|
let json
|
|
|
|
try {
|
|
|
|
json = await getApi(start, null)
|
|
|
|
} catch {
|
|
|
|
return null
|
|
|
|
}
|
2020-07-12 00:48:15 +09:00
|
|
|
if (!json || json.error) {
|
|
|
|
return
|
2019-05-19 16:39:30 +09:00
|
|
|
}
|
2020-07-12 00:48:15 +09:00
|
|
|
const mtc = json['max_toot_chars']
|
|
|
|
if (mtc) {
|
2020-07-21 12:44:53 +09:00
|
|
|
localStorage.setItem(letters, mtc)
|
2019-05-19 16:39:30 +09:00
|
|
|
}
|
2020-07-12 00:48:15 +09:00
|
|
|
if (json['feature_quote']) {
|
2020-07-21 12:44:53 +09:00
|
|
|
localStorage.setItem(quoteMarker, true)
|
2019-05-19 16:39:30 +09:00
|
|
|
}
|
2020-07-12 00:48:15 +09:00
|
|
|
const str = json['urls']['streaming_api']
|
|
|
|
if (str) {
|
2020-07-21 12:44:53 +09:00
|
|
|
localStorage.setItem(`streaming_${domain}`, str)
|
2019-05-19 16:39:30 +09:00
|
|
|
}
|
2018-02-25 17:41:34 +09:00
|
|
|
}
|
2018-01-28 21:22:43 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
//アカウントを選択…を実装
|
2020-07-21 12:44:53 +09:00
|
|
|
function multiSelector() {
|
|
|
|
let obj = acctList
|
|
|
|
//if (!obj) obj = JSON.parse(localStorage.getItem('multi'))
|
|
|
|
let template = ''
|
2020-07-12 00:48:15 +09:00
|
|
|
//StringなのはlocalStorageがStringしか返さないから
|
|
|
|
let lastUsed = '0'
|
2019-11-10 20:37:13 +09:00
|
|
|
if (localStorage.getItem('mainuse') == 'main') {
|
2020-07-12 00:48:15 +09:00
|
|
|
lastUsed = localStorage.getItem('main')
|
2019-11-10 20:37:13 +09:00
|
|
|
} else if (localStorage.getItem('last-use')) {
|
2020-07-12 00:48:15 +09:00
|
|
|
lastUsed = localStorage.getItem('last-use')
|
2020-07-21 09:06:58 +09:00
|
|
|
if (lastUsed == 'webview' || lastUsed == 'noauth') {
|
2020-07-12 00:48:15 +09:00
|
|
|
lastUsed = '0'
|
2019-05-20 22:34:58 +09:00
|
|
|
}
|
2019-05-19 16:39:30 +09:00
|
|
|
} else {
|
2020-07-12 00:48:15 +09:00
|
|
|
lastUsed = '0'
|
2018-05-20 15:17:10 +09:00
|
|
|
}
|
2020-07-12 00:48:15 +09:00
|
|
|
let sel
|
2019-05-19 16:39:30 +09:00
|
|
|
if (obj.length < 1) {
|
2020-07-12 00:48:15 +09:00
|
|
|
document.querySelector('#src-acct-sel').innerHTML = '<option value="tootsearch">Tootsearch</option>'
|
|
|
|
document.querySelector('#add-acct-sel').innerHTML = `<option value="noauth">${lang.lang_login_noauth}</option>`
|
2019-05-19 16:39:30 +09:00
|
|
|
} else {
|
2020-07-12 00:48:15 +09:00
|
|
|
for (let i = 0; i < obj.length; i++) {
|
|
|
|
const acct = obj[i]
|
2020-07-21 12:44:53 +09:00
|
|
|
const strKey = i.toString()
|
2020-07-21 09:06:58 +09:00
|
|
|
if (strKey == lastUsed) {
|
2019-11-10 20:37:13 +09:00
|
|
|
sel = 'selected'
|
2020-07-12 00:48:15 +09:00
|
|
|
const domain = acct.domain
|
|
|
|
const letters = idata[`${domain}_letters`]
|
|
|
|
const textarea = document.querySelector('#textarea')
|
|
|
|
if (letters) {
|
|
|
|
textarea.setAttribute('data-length', letters)
|
2019-05-19 16:39:30 +09:00
|
|
|
} else {
|
2020-07-12 00:48:15 +09:00
|
|
|
//手動でアカマネで変えれちゃうから
|
2020-07-21 12:44:53 +09:00
|
|
|
const maxLetters = localStorage.getItem(`${domain}_letters`)
|
2020-07-12 00:48:15 +09:00
|
|
|
if (maxLetters > 0) {
|
|
|
|
textarea.setAttribute('data-length', maxLetters)
|
2019-05-19 16:39:30 +09:00
|
|
|
} else {
|
2020-07-12 00:48:15 +09:00
|
|
|
textarea.setAttribute('data-length', 500)
|
2019-05-19 16:39:30 +09:00
|
|
|
}
|
2018-09-01 22:02:15 +09:00
|
|
|
}
|
2020-07-12 00:48:15 +09:00
|
|
|
if (idata[`${domain}_glitch`]) {
|
|
|
|
document.querySelector('#local-button').classList.remove('hide')
|
2019-05-19 16:39:30 +09:00
|
|
|
}
|
2020-07-12 00:48:15 +09:00
|
|
|
let profimg = acct.prof
|
2019-05-19 16:39:30 +09:00
|
|
|
if (!profimg) {
|
2019-11-10 20:37:13 +09:00
|
|
|
profimg = '../../img/missing.svg'
|
2019-05-19 16:39:30 +09:00
|
|
|
}
|
2020-07-21 09:06:58 +09:00
|
|
|
document.querySelector('#acct-sel-prof').setAttribute('src', profimg)
|
2020-07-12 00:48:15 +09:00
|
|
|
let cc = ''
|
2019-05-19 16:39:30 +09:00
|
|
|
if (domain) {
|
2020-07-12 00:48:15 +09:00
|
|
|
cc = `(${domain})`
|
2019-05-19 16:39:30 +09:00
|
|
|
}
|
2020-07-12 00:48:15 +09:00
|
|
|
const tpb = document.querySelector('#toot-post-btn')
|
|
|
|
tpb.innerText = lang.lang_toot + cc
|
2019-11-10 20:37:13 +09:00
|
|
|
if (acct.background && acct.background != 'def' && acct.text && acct.text != 'def') {
|
2020-07-12 00:48:15 +09:00
|
|
|
tpb.classList.remove('indigo')
|
|
|
|
tpb.style.backgroundColor = `#${acct.background}`
|
|
|
|
tpb.style.color = `#${acct.text}`
|
2019-05-19 16:39:30 +09:00
|
|
|
}
|
2019-11-10 20:37:13 +09:00
|
|
|
if (domain == 'imastodon.net') {
|
|
|
|
trendTag()
|
2019-05-19 16:39:30 +09:00
|
|
|
} else {
|
2020-07-21 12:44:53 +09:00
|
|
|
if (document.querySelector('#trendtag')) document.querySelector('#trendtag').innerHTML = ''
|
2019-05-19 16:39:30 +09:00
|
|
|
}
|
|
|
|
} else {
|
2019-11-10 20:37:13 +09:00
|
|
|
sel = ''
|
2018-04-16 22:58:14 +09:00
|
|
|
}
|
2020-07-21 12:44:53 +09:00
|
|
|
template = template + `
|
|
|
|
<option value="${strKey}" data-icon="${acct.prof}" class="left circle" ${sel}>@${acct.user}@${acct.domain}
|
2020-07-12 00:48:15 +09:00
|
|
|
</option>
|
|
|
|
`
|
|
|
|
}
|
2020-07-21 12:44:53 +09:00
|
|
|
const forSrc = template + '<option value="tootsearch">Tootsearch</option>'
|
|
|
|
const forAdd = template + `
|
2020-07-21 09:06:58 +09:00
|
|
|
<option value="noauth">${lang.lang_login_noauth}</option>
|
|
|
|
<option value="webview">Twitter</option>
|
2020-07-21 12:44:53 +09:00
|
|
|
`
|
|
|
|
const forDir = template + `<option value="noauth">${lang.lang_login_noauth}</option>`
|
|
|
|
document.querySelector('#post-acct-sel').innerHTML = template
|
|
|
|
document.querySelector('#list-acct-sel').innerHTML = template
|
|
|
|
document.querySelector('#filter-acct-sel').innerHTML = template
|
|
|
|
document.querySelector('#src-acct-sel').innerHTML = forSrc
|
|
|
|
document.querySelector('#add-acct-sel').innerHTML = forAdd
|
|
|
|
document.querySelector('#dir-acct-sel').innerHTML = forDir
|
2019-07-06 23:16:41 +09:00
|
|
|
}
|
2020-07-21 12:44:53 +09:00
|
|
|
const elems = document.querySelectorAll('select')
|
|
|
|
M.FormSelect.init(elems, null)
|
2018-01-28 21:22:43 +09:00
|
|
|
}
|
2018-12-09 03:46:01 +09:00
|
|
|
//インスタンスティッカー
|
2020-07-21 09:06:58 +09:00
|
|
|
async function ticker() {
|
2020-07-12 00:48:15 +09:00
|
|
|
const start = 'https://toot-app.thedesk.top/toot/index.php'
|
2020-07-21 09:06:58 +09:00
|
|
|
const json = await getApi(start, null)
|
2020-07-21 12:44:53 +09:00
|
|
|
if (json) localStorage.setItem('ticker', JSON.stringify(json))
|
2019-11-04 01:10:06 +09:00
|
|
|
}
|
2020-07-12 00:48:15 +09:00
|
|
|
function isMisskey(domain) {
|
|
|
|
return localStorage.getItem(`mode_${domain}`) == 'misskey'
|
|
|
|
}
|