today shinchoku

This commit is contained in:
cutls 2020-08-31 00:23:55 +09:00
parent 541ebbbb19
commit 8eadb8287d
3 changed files with 372 additions and 679 deletions

View File

@ -7,15 +7,6 @@ $(function ($) {
const hasFocus2 = isFocused('textarea') const hasFocus2 = isFocused('textarea')
const postBox = document.querySelector('#textarea') const postBox = document.querySelector('#textarea')
let wv = false let wv = false
if (document.getElementById('webview')) {
if (document.querySelector('#webviewsel:checked').value) {
wv = false
} else {
wv = true
}
} else {
wv = true
}
//Enter //Enter
if (e.keyCode === 13) { if (e.keyCode === 13) {
if (isFocused('#src')) { if (isFocused('#src')) {

View File

@ -145,7 +145,7 @@ async function ckdb(acct_id) {
if (idata) { if (idata) {
//check and replace json to idata //check and replace json to idata
var json = idata const json = idata
if (json[quoteMarker] == 'enabled') { if (json[quoteMarker] == 'enabled') {
localStorage.setItem('quoters', true) localStorage.setItem('quoters', true)
localStorage.setItem(quoteMarker, true) localStorage.setItem(quoteMarker, true)

View File

@ -10,9 +10,7 @@ function load() {
setAllClasses('body', 'first', 'add') setAllClasses('body', 'first', 'add')
} }
} }
const multi = localStorage.getItem('multi') const obj = acctList
if (!multi) return false
const obj = JSON.parse(multi)
let domains = [] let domains = []
let template = '' let template = ''
document.querySelector('#acct-list').innerHTML = '' document.querySelector('#acct-list').innerHTML = ''
@ -49,12 +47,12 @@ function load() {
document.querySelector('#domain-list').innerHTML = '' document.querySelector('#domain-list').innerHTML = ''
const keymap = Object.keys(domains) const keymap = Object.keys(domains)
let templateDomainList = '' let templateDomainList = ''
for(let j = 0; j < domains.length; j++) { for (let j = 0; j < domains.length; j++) {
const key = keymap[j] const key = keymap[j]
const domain = domains[key] const domain = domains[key]
let maxChars = 500 let maxChars = 500
const thisLtrs = localStorage.getItem(`${domain}_letters`) const thisLtrs = localStorage.getItem(`${domain}_letters`)
if(thisLtrs) maxChars = thisLtrs if (thisLtrs) maxChars = thisLtrs
templateDomainList = templateDomainList + ` templateDomainList = templateDomainList + `
<li class="collection-item transparent"> <li class="collection-item transparent">
<div> <div>
@ -91,67 +89,49 @@ function maxChars(domain, uid) {
return false return false
} }
const multi = localStorage.getItem('multi') const multi = localStorage.getItem('multi')
if(!multi) return false if (!multi) return false
const obj = JSON.parse(multi) const obj = JSON.parse(multi)
for(let k = 0; k < obj.length; k++) { for (let k = 0; k < obj.length; k++) {
if (obj[k].domain == domain) localStorage.setItem(`${domain}_letters`, value) if (obj[k].domain == domain) localStorage.setItem(`${domain}_letters`, value)
} }
load() load()
} }
//instances.social/instances API //instances.social/instances API
async function data(domain, acct_id) { async function data(domain, acct_id) {
$('#ins-upd').text('Loading...') document.querySelector('#ins-upd').innerText = 'Loading...'
$('#ins-add').text('Loading...') document.querySelector('#ins-add').innerText = 'Loading...'
$('#ins-connect').text('Loading...') document.querySelector('#ins-connect').innerText = 'Loading...'
$('#ins-toot').text('Loading...') document.querySelector('#ins-toot').innerText = 'Loading...'
$('#ins-sys').text('Loading...') document.querySelector('#ins-sys').innerText = 'Loading...'
$('#ins-per').text('Loading...') document.querySelector('#ins-per').innerText = 'Loading...'
$('#ins-user').text('Loading...') document.querySelector('#ins-user').innerText = 'Loading...'
$('#ins-ver').text('Loading...') document.querySelector('#ins-var').innerText = 'Loading...'
$('#ins-name').text('Loading...') document.querySelector('#ins-name').innerText = 'Loading...'
$('#ins-prof').attr('src', '../../img/loading.svg') document.querySelector('#ins-prof').setAttribute('src', '../../img/loading.svg')
var start = 'https://instances.social/api/1.0/instances/show?name=' + domain const start = 'https://instances.social/api/1.0/instances/show?name=' + domain
let promise = await fetch(start, { const json = await getApi(start, 'tC8F6xWGWBUwGScyNevYlx62iO6fdQ4oIK0ad68Oo7ZKB8GQdGpjW9TKxBnIh8grAhvd5rw3iyP9JPamoDpeLQdz62EToPJUW99hDx8rfuJfGdjQuimZPTbIOx0woA5M')
method: 'GET', document.querySelector('#ins-name').innerText = json.name
headers: { document.querySelector('#ins-upd').innerText = date(json.checked_at, 'full')
'content-type': 'application/json', document.querySelector('#ins-add').innerText = date(json.added_at, 'full')
Authorization: document.querySelector('#ins-connect').innerText = json.connections
'Bearer tC8F6xWGWBUwGScyNevYlx62iO6fdQ4oIK0ad68Oo7ZKB8GQdGpjW9TKxBnIh8grAhvd5rw3iyP9JPamoDpeLQdz62EToPJUW99hDx8rfuJfGdjQuimZPTbIOx0woA5M' document.querySelector('#ins-toot').innerText = json.statuses
} document.querySelector('#ins-sys').innerText = date(json.updated_at, 'full')
}) document.querySelector('#ins-per').innerText = json.uptime * 100
var json = await promise.json() document.querySelector('#ins-user').innerText = json.users
$('#ins-name').text(json.name) document.querySelector('#ins-ver').innerText = json.version
$('#ins-upd').text(date(json.checked_at, 'full')) const start2 = 'https://' + domain + '/api/v1/instance'
$('#ins-add').text(date(json.added_at, 'full')) const json2 = await getApi(start2, null)
$('#ins-connect').text(json.connections) document.querySelector('#ins-title').innerText = json2.title
$('#ins-toot').text(json.statuses) document.querySelector('#ins-desc').innerText = json2.description
$('#ins-sys').text(date(json.updated_at, 'full')) document.querySelector('#ins-email').innerText = json2.email
$('#ins-per').text(json.uptime * 100) document.querySelector('#ins-toot').innerText = json2.stats.status_count
$('#ins-user').text(json.users) document.querySelector('#ins-user').innerText = json2.user_count
$('#ins-ver').text(json.version) document.querySelector('#ins-ver').innerText = json2.version
var start = 'https://' + domain + '/api/v1/instance' document.querySelector('#ins-prof').innerText = json2.version
let promise2 = await fetch(start, { document.querySelector('#ins-prof').setAttribute('src', json2.thumbnail)
method: 'GET', document.querySelector('#ins-admin').innerText = `${escapeHTML(json2.contact_account.display_name)}(${json2.contact_account.acct})`
headers: { document.querySelector('#ins-admin').setAttribute('href', `index.html?mode=user&code=${json2.contact_account.username}@${domain}`)
'content-type': 'application/json' if (json2['max_toot_chars']) {
}
})
var json = await promise2.json()
$('#ins-title').text(json.title)
$('#ins-desc').html(json.description)
$('#ins-email').text(json.email)
$('#ins-toot').text(json.stats.status_count)
$('#ins-user').text(json.stats.user_count)
$('#ins-ver').text(json.version)
$('#ins-prof').attr('src', json.thumbnail)
$('#ins-admin').text(
escapeHTML(json.contact_account.display_name) + '(' + json.contact_account.acct + ')'
)
$('#ins-admin').attr(
'href',
'index.html?mode=user&code=' + json.contact_account.username + '@' + domain
)
if (json['max_toot_chars']) {
localStorage.setItem('letters_' + acct_id, json['max_toot_chars']) localStorage.setItem('letters_' + acct_id, json['max_toot_chars'])
load() load()
} }
@ -159,8 +139,7 @@ async function data(domain, acct_id) {
//アカウントデータ 消す //アカウントデータ 消す
function multiDel(target) { function multiDel(target) {
var multi = localStorage.getItem('multi') const obj = acctList
var obj = JSON.parse(multi)
//削除確認ダイアログ //削除確認ダイアログ
Swal.fire({ Swal.fire({
title: lang.lang_manager_logout, title: lang.lang_manager_logout,
@ -173,69 +152,39 @@ function multiDel(target) {
cancelButtonText: lang.lang_no cancelButtonText: lang.lang_no
}).then(result => { }).then(result => {
if (result.value) { if (result.value) {
Object.keys(obj).forEach(function (key) { for (let i = 0; i < obj.length; i++) {
var nk = key - 1 const nk = i - 1
//公開範囲(差分のみ)
if (key >= target) { if (key >= target) {
var oldvis = localStorage.getItem('vis-memory-' + key) const oldvis = localStorage.getItem(`vis-memory-${i}`)
if (oldvis) { if (oldvis) localStorage.setItem(`vis-memory-${nk}`, oldvis)
localStorage.setItem('vis-memory-' + nk, oldvis)
} }
} }
//独自ロケール
localStorage.removeItem('home_' + key)
localStorage.removeItem('local_' + key)
localStorage.removeItem('public_' + key)
localStorage.removeItem('notification_' + key)
//アクセストークンとドメイン、プロフ(差分)
if (key > target) {
var olddom = localStorage.getItem('domain_' + key)
localStorage.setItem('domain_' + nk, olddom)
var oldat = localStorage.getItem('acct_' + key + '_at')
localStorage.setItem('acct_' + nk + '_at', oldat)
localStorage.setItem('name_' + nk, localStorage.getItem('name_' + key))
localStorage.setItem('user_' + target, localStorage.getItem('user_' + key))
localStorage.setItem('user-id_' + target, localStorage.getItem('user-id_' + key))
localStorage.setItem('prof_' + target, localStorage.getItem('prof_' + key))
}
})
//とりあえず消す //とりあえず消す
obj.splice(target, 1) obj.splice(target, 1)
var json = JSON.stringify(obj) const json = JSON.stringify(obj)
localStorage.setItem('multi', json) localStorage.setItem('multi', json)
load() load()
//カラムデータコンフリクト //カラムデータコンフリクト
var col = localStorage.getItem('column') const col = localStorage.getItem('column')
var oldcols = JSON.parse(col) const oldcols = JSON.parse(col)
var newcols = [] const newcols = []
Object.keys(oldcols).forEach(function (key) { for (let i = 0; i < oldcols.length; i++) {
var nk = key - 1 const nk = i - 1
var oldcol = oldcols[key] const oldcol = oldcols[i]
if (target < oldcol.domain) { let newdom = oldcol.domain
var newdom = oldcol.domain - 1 if (target < oldcol.domain) newdom = oldcol.domain - 1
} else { const type = oldcol.type
var newdom = oldcol.domain let data = null
} if (oldcol.data) data = oldcol.data
var type = oldcol.type let background = null
var data = null if (oldcol.background) background = oldcol.background
if (oldcol.data) { let text = null
data = oldcol.data if (oldcol.text) text = oldcol.text
} let left_fold = false
var background = null if (oldcol.left_fold) left_fold = true
if (oldcol.background) {
background = oldcol.background
}
var text = null
if (oldcol.text) {
text = oldcol.text
}
var left_fold = false
if (oldcol.left_fold) {
left_fold = true
}
//消した垢のコラムじゃないときコピー //消した垢のコラムじゃないときコピー
if (target != oldcol.domain) { if (target != oldcol.domain) {
var add = { const add = {
domain: newdom, domain: newdom,
type: type, type: type,
data: data, data: data,
@ -245,231 +194,101 @@ function multiDel(target) {
} }
newcols.push(add) newcols.push(add)
} }
})
var json = JSON.stringify(newcols)
localStorage.setItem('column', json)
} }
}) const newjson = JSON.stringify(newcols)
} localStorage.setItem('column', newjson)
function multiDel2(target) { location.reload()
var multi = localStorage.getItem('multi')
var obj = JSON.parse(multi)
Swal.fire({
title: lang.lang_manager_logout,
text: obj[target]['user'] + '@' + obj[target]['domain'] + lang.lang_manager_confirm,
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: lang.lang_yesno,
cancelButtonText: lang.lang_no
}).then(result => {
if (result.value) {
obj.splice(target, 1)
var json = JSON.stringify(obj)
localStorage.setItem('multi', json)
Object.keys(obj).forEach(function (key) {
if (key >= target) {
var oldvis = localStorage.getItem('vis-memory-' + key)
if (oldvis) {
var nk = key - 1
localStorage.setItem('vis-memory-' + nk, oldvis)
}
}
localStorage.removeItem('home_' + key)
localStorage.removeItem('local_' + key)
localStorage.removeItem('public_' + key)
localStorage.removeItem('notification_' + key)
refresh(key)
})
var col = localStorage.getItem('column')
if (!col) {
var obj = [
{
domain: 0,
type: 'local'
}
]
localStorage.setItem('card_0', 'true')
var json = JSON.stringify(obj)
localStorage.setItem('column', json)
} else {
var cobj = JSON.parse(col)
}
Object.keys(cobj).forEach(function (key) {
var column = cobj[key]
if (column.domain > target) {
var nk = key - 1
column.domain = nk
cobj[key] = column
} else if (column.domain == target) {
localStorage.removeItem('card_' + tlid)
cobj.splice(key, 1)
}
})
var json = JSON.stringify(column)
localStorage.setItem('column', json)
load()
} }
}) })
} }
//サポートインスタンス //サポートインスタンス
function support() { function support() {
Object.keys(idata).forEach(function (key) { let i = 0
var instance = idata[key] let template = ''
const keys = Object.keys(idata)
for (const instance of idata) {
if (instance == 'instance') { if (instance == 'instance') {
templete = template = template + `<a onclick="login('${key}') class="collection-item pointer transparent">
'<a onclick="login(\'' + ${idata[`${keys[i]}_name`]}
key + </a>`
'\')" class="collection-item pointer transparent">' +
idata[key + '_name'] +
'(' +
key +
')</a>'
$('#support').append(templete)
} }
}) i++
}
document.querySelector('#support').innerHTML = template
} }
//URL指定してポップアップ //URL指定してポップアップ
function login(url) { async function login(url) {
var multi = localStorage.getItem('multi') if (document.querySelector('#misskey').checked) {
var obj = JSON.parse(multi)
if ($('#misskey:checked').val() == 'on') {
$('#misskey').prop('checked', true)
misskeyLogin(url) misskeyLogin(url)
return return
} }
$('#compt').hide() document.querySelector('#compt').style.display = 'none'
if ($('#linux:checked').val() == 'on') { let red = 'thedesk://manager'
var red = 'urn:ietf:wg:oauth:2.0:oob' if (document.querySelector('#linux').checked) {
if (~url.indexOf('pixelfed')) { red = 'urn:ietf:wg:oauth:2.0:oob'
red = 'https://thedesk.top/hello.html' if (~url.indexOf('pixelfed')) red = 'https://thedesk.top/hello.html'
}
} else {
var red = 'thedesk://manager'
} }
localStorage.setItem('redirect', red) localStorage.setItem('redirect', red)
var start = 'https://' + url + '/api/v1/apps' const start = 'https://' + url + '/api/v1/apps'
var httpreq = new XMLHttpRequest() let json
httpreq.open('POST', start, true) const body = JSON.stringify({
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.responseType = 'json'
httpreq.send(
JSON.stringify({
scopes: 'read write follow', scopes: 'read write follow',
client_name: 'TheDesk(PC)', client_name: 'TheDesk(PC)',
redirect_uris: red, redirect_uris: red,
website: 'https://thedesk.top' website: 'https://thedesk.top'
}) })
) const json = await postApi(start, body, null, null)
httpreq.onreadystatechange = function () { const auth = `https://${url}/oauth/authorize?client_id=${json.client_id}&client_secret=${json.client_secret}&response_type=code&scope=read+write+follow&redirect_uri=${encodeURIComponent(red)}`
if (httpreq.readyState === 4) {
var json = httpreq.response
if (this.status !== 200) {
setLog(start, this.status, json)
}
localStorage.setItem('msky', 'false')
var auth =
'https://' +
url +
'/oauth/authorize?client_id=' +
json['client_id'] +
'&client_secret=' +
json['client_secret'] +
'&response_type=code&scope=read+write+follow&redirect_uri=' +
encodeURIComponent(red)
localStorage.setItem('domain_tmp', url) localStorage.setItem('domain_tmp', url)
localStorage.setItem('client_id', json['client_id']) localStorage.setItem('client_id', json['client_id'])
localStorage.setItem('client_secret', json['client_secret']) localStorage.setItem('client_secret', json['client_secret'])
$('#auth').show() document.querySelector('#auth').style.display = 'block'
versionChecker(url) versionChecker(url)
$('#add').hide() document.querySelector('#add').style.display = 'none'
postMessage(['openUrl', auth], '*') postMessage(['openUrl', auth], '*')
if ($('#linux:checked').val() == 'on') { if (!document.querySelector('#linux').checked) postMessage(['sendSinmpleIpc', 'quit'], '*')
} else {
postMessage(['sendSinmpleIpc', 'quit'], '*')
}
}
}
} }
function versionChecker(url) { async function versionChecker(url) {
var start = 'https://' + url + '/api/v1/instance' const start = `https://${url}/api/v1/instance`
fetch(start, { const json = await getApi(start, null)
method: 'GET', const version = json.version
headers: {
'content-type': 'application/json'
}
})
.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) {
var version = json.version
if (version) { if (version) {
var reg = version.match(/^([0-9])\.[0-9]\.[0-9]/u) const reg = version.match(/^([0-9])\.[0-9]\.[0-9]/u)
if (reg) { if (reg) {
versionCompat(reg[1], reg, json.title, reg[0]) versionCompat(reg[1], reg, json.title, reg[0])
} }
} }
})
} }
function versionCompat(prefix, ver, title, real) {
$('#compt-instance').text(title) async function versionCompat(prefix, ver, title, real) {
$('#compt-ver').text(real) document.querySelector('#compt-instance').innerText = title
document.querySelector('#compt-ver').innerText = real
if (~real.indexOf('compatible')) { if (~real.indexOf('compatible')) {
$('#compt-warn').show() document.querySelector('#compt-warn').style.display = 'block'
} else { } else {
$('#compt-warn').hide() document.querySelector('#compt-warn').style.display = 'none'
} }
$('#compt-list').html('') document.querySelector('#compt-list').innnerHTML = ''
var start = '../../source/version.json' const json = await getApi('../../source/version.json', null)
fetch(start, { let complete = false
method: 'GET', let ct = 0
headers: { let jl = 0
'content-type': 'application/json' let jl2 = 0
} let template = ''
}) for (const key in json) {
.then(function (response) { if (complete) break
if (!response.ok) { const data = json[key]
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) {
var complete = false
var ct = 0
var jl = 0
var jl2 = 0
Object.keys(json).forEach(function (key) {
var data = json[key]
if (data) { if (data) {
jl++ jl++
if (key != real && !complete) { if (key != real && !complete) {
for (var i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
var e = '' let e = ''
if (i == 0) { if (i == 0) {
e = '(' + key + ')' e = `(${key})`
} }
$('#compt-list').append('<li>' + data[i] + e + '</li>') template = `<li>${data[i]}${e}</li>`
ct++ ct++
e = '' e = ''
} }
@ -478,27 +297,22 @@ function versionCompat(prefix, ver, title, real) {
complete = true complete = true
} }
} }
}) }
document.querySelector('#compt-list').innnerHTML = template
if (lang.language == 'ja' && ct > 0) { if (lang.language == 'ja' && ct > 0) {
if (jl2 != jl && prefix != '1') { if (jl2 != jl && prefix != '1') {
$('#compt').show() document.querySelector('#compt').style.display = 'block'
} }
} }
})
} }
//これが後のMisskeyである。
function misskeyLogin(url) { async function misskeyLogin(url) {
if (!url) { if (!url) {
var url = $('#misskey-url').val() url = document.querySelector('#misskey-url').value
} }
var start = 'https://' + url + '/api/app/create' const start = `https://${url}/api/app/create`
var httpreq = new XMLHttpRequest() const httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true) const body = JSON.stringify({
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.responseType = 'json'
localStorage.setItem('msky', 'true')
httpreq.send(
JSON.stringify({
name: 'TheDesk(PC)', name: 'TheDesk(PC)',
description: 'Mastodon and Misskey client for PC', description: 'Mastodon and Misskey client for PC',
permission: [ permission: [
@ -545,232 +359,153 @@ function misskeyLogin(url) {
'write:votes' 'write:votes'
] ]
}) })
) const json = await postApi(start, body, null, null)
httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) {
var json = httpreq.response
if (this.status !== 200) {
setLog(start, this.status, json)
}
misskeyAuth(url, json.secret) misskeyAuth(url, json.secret)
}
}
} }
function misskeyAuth(url, mkc) { async function misskeyAuth(url, mkc) {
var start = 'https://' + url + '/api/auth/session/generate' const start = 'https://' + url + '/api/auth/session/generate'
var httpreq = new XMLHttpRequest() const body = JSON.stringify({
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.responseType = 'json'
localStorage.setItem('mkc', mkc)
localStorage.setItem('msky', 'true')
httpreq.send(
JSON.stringify({
appSecret: mkc appSecret: mkc
}) })
) const json = await postApi(start, body, null, null)
httpreq.onreadystatechange = function () { const token = json.token
if (httpreq.readyState === 4) { localStorage.setItem('mkc', mkc)
var json = httpreq.response document.querySelector('#auth').style.display = 'block'
if (this.status !== 200) { document.querySelector('#code').value = token
setLog(start, this.status, json) document.querySelector('#add').style.display = 'none'
}
var token = json.token
$('#auth').show()
$('#code').val(token)
$('#add').hide()
$('#misskey').prop('checked', false)
localStorage.setItem('domain_tmp', url) localStorage.setItem('domain_tmp', url)
postMessage(['openUrl', json.url], '*') postMessage(['openUrl', json.url], '*')
}
}
} }
//テキストボックスにURL入れた //テキストボックスにURL入れた
function instance() { function instance() {
var url = $('#url').val() const url = document.querySelector('#url').value
if (url.indexOf('@') != -1 || url.indexOf('https') != -1) { if (url.indexOf('@') != -1 || url.indexOf('https') != -1) {
alert('入力形式が違います。(Cutls@mstdn.jpにログインする場合、入力するのは"mstdn.jp"です。)') Swal.fire({
type: 'error',
title: '入力形式が違います。(Cutls@mstdn.jpにログインする場合、入力するのは"mstdn.jp"です。)'
})
return false return false
} }
login(url) login(url)
} }
//コード入れてAccessTokenゲット //コード入れてAccessTokenゲット
function code(code) { async function code(code) {
localStorage.removeItem('redirect') localStorage.removeItem('redirect')
if (!code) { if (!code) {
var code = $('#code').val() code = document.querySelector('#code').value
$('#code').val('') document.querySelector('#code').value = ''
} }
if (!code || code == '') { if (!code || code == '') {
M.toast({ html: lang.lang_fatalerroroccured + 'Error: no code', displayLength: 5000 }) M.toast({ html: lang.lang_fatalerroroccured + 'Error: no code', displayLength: 5000 })
return false return false
} }
var url = localStorage.getItem('domain_tmp') const url = localStorage.getItem('domain_tmp')
localStorage.removeItem('domain_tmp') localStorage.removeItem('domain_tmp')
if (localStorage.getItem('msky') == 'true') { if (document.querySelector('#misskey').checked) {
var start = 'https://' + url + '/api/auth/session/userkey' document.querySelector('#misskey').checked = false
var httpreq = new XMLHttpRequest() const mkc = localStorage.getItem('mkc')
httpreq.open('POST', start, true) localStorage.removeItem('mkc')
httpreq.setRequestHeader('Content-Type', 'application/json') const start = `https://${url}/api/auth/session/userkey`
httpreq.responseType = 'json' const body = JSON.stringify({
httpreq.send(
JSON.stringify({
token: code, token: code,
appSecret: localStorage.getItem('mkc') appSecret: mkc
}) })
) const json = await postApi(start, body, null, null)
httpreq.onreadystatechange = function () { const i = sha256(json.accessToken + mkc)
if (httpreq.readyState === 4) { const { avatarUrl, name, username, id } = json.user
var json = httpreq.response const add = {
if (this.status !== 200) {
setLog(start, this.status, json)
}
var i = sha256(json.accessToken + localStorage.getItem('mkc'))
var avatar = json['user']['avatarUrl']
var priv = 'public'
var add = {
at: i, at: i,
name: json['user']['name'], name: name,
domain: url, domain: url,
user: json['user']['username'], user: username,
prof: avatar, prof: avatarUrl,
id: json['user']['id'], id: id,
vis: priv, vis: 'public',
mode: 'misskey' mode: 'misskey'
} }
localStorage.setItem('mode_' + url, 'misskey') const multi = localStorage.getItem('multi')
var multi = localStorage.getItem('multi') let obj = JSON.parse(multi)
var obj = JSON.parse(multi)
var target = obj.length
obj.push(add) obj.push(add)
localStorage.setItem('name_' + target, json['user']['name']) const write = JSON.stringify(obj)
localStorage.setItem('user_' + target, json['user']['username']) localStorage.setItem('multi', write)
localStorage.setItem('user-id_' + target, json['user']['id']) if (document.getElementsByTagName('body').classList.contains('first')) {
localStorage.setItem('prof_' + target, avatar)
var json = JSON.stringify(obj)
localStorage.setItem('multi', json)
if ($('body').hasClass('first')) {
location.href = 'index.html' location.href = 'index.html'
} }
load() load()
return return
} }
} let red = 'urn:ietf:wg:oauth:2.0:oob'
return
} else {
var red = 'urn:ietf:wg:oauth:2.0:oob'
if (~url.indexOf('pixelfed')) { if (~url.indexOf('pixelfed')) {
red = 'https://thedesk.top/hello.html' red = 'https://thedesk.top/hello.html'
} }
var start = 'https://' + url + '/oauth/token' const start = `https://${url}/oauth/token`
var id = localStorage.getItem('client_id') const id = localStorage.getItem('client_id')
var secret = localStorage.getItem('client_secret') localStorage.removeItem('client_id')
var httpreq = new XMLHttpRequest() const secret = localStorage.getItem('client_secret')
httpreq.open('POST', start, true) localStorage.removeItem('client_secret')
httpreq.setRequestHeader('Content-Type', 'application/json') const body = JSON.stringify({
httpreq.responseType = 'json'
httpreq.send(
JSON.stringify({
grant_type: 'authorization_code', grant_type: 'authorization_code',
redirect_uri: red, redirect_uri: red,
client_id: id, client_id: id,
client_secret: secret, client_secret: secret,
code: code code: code
}) })
) const json = await postApi(start, body, null, null)
httpreq.onreadystatechange = function () { if (json.access_token) {
if (httpreq.readyState === 4) { document.querySelector('#add').style.display = 'block'
var json = httpreq.response document.querySelector('#auth').style.display = 'none'
if (this.status !== 200) { getdata(url, json.access_token)
setLog(start, this.status, json)
}
if (json['access_token']) {
$('#auth').hide()
$('#add').show()
getdata(url, json['access_token'])
}
}
}
} }
} }
//ユーザーデータ取得 //ユーザーデータ取得
function getdata(domain, at) { async function getdata(domain, at) {
var start = 'https://' + 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',
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) { if (json.error) {
console.error('Error:' + json.error) console.error('Error:' + json.error)
M.toast({ html: lang.lang_fatalerroroccured + 'Error:' + json.error, displayLength: 5000 }) M.toast({ html: lang.lang_fatalerroroccured + 'Error:' + json.error, displayLength: 5000 })
return return
} }
var avatar = json['avatar'] const {avatar: avatarRaw, display_name: displayName, acct, id, source} = json
//missingがmissingなやつ let avatar = avatarRaw
if (avatar == '/avatars/original/missing.png') { if (avatar == '/avatars/original/missing.png') {
avatar = '../../img/missing.svg' avatar = '../../img/missing.svg'
} }
if (json['source']) { let priv = 'public'
var priv = json['source']['privacy'] if(source) priv = source.privacy
} else { const add = {
var priv = 'public'
}
var add = {
at: at, at: at,
name: json['display_name'], name: displayName,
domain: domain, domain: domain,
user: json['acct'], user: acct,
prof: avatar, prof: avatar,
id: json['id'], id: id,
vis: priv, vis: priv,
mode: 'mastodon' mode: 'mastodon'
} }
var multi = localStorage.getItem('multi') const multi = localStorage.getItem('multi')
var obj = JSON.parse(multi) let obj = JSON.parse(multi)
var target = obj.length
obj.push(add) obj.push(add)
localStorage.setItem('name_' + target, json['display_name']) const json = JSON.stringify(obj)
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) localStorage.setItem('multi', json)
if ($('body').hasClass('first')) { if (document.getElementsByTagName('body').classList.contains('first')) {
location.href = 'index.html' location.href = 'index.html'
} }
load() load()
})
} }
//アクセストークン直接入力 //アクセストークン直接入力
function atSetup(type) { function atSetup(type) {
var url = localStorage.getItem('domain_tmp') const url = localStorage.getItem('domain_tmp')
localStorage.removeItem('domain_tmp') localStorage.removeItem('domain_tmp')
var multi = localStorage.getItem('multi') const multi = localStorage.getItem('multi')
var avatar = '../../img/missing.svg' const avatar = '../../img/missing.svg'
var priv = 'public' const priv = 'public'
let add
if (type == 'misskey') { if (type == 'misskey') {
var i = $('#misskey-key').val() const i = document.querySelector('#misskey-key').value
var add = { add = {
at: i, at: i,
name: 'Pseudo Account', name: 'Pseudo Account',
domain: url, domain: url,
@ -780,10 +515,9 @@ function atSetup(type) {
vis: priv, vis: priv,
mode: 'misskey' mode: 'misskey'
} }
localStorage.setItem('mode_' + url, 'misskey')
} else { } else {
var i = $('#code').val() const i = document.querySelector('#code').value
var add = { add = {
at: i, at: i,
name: 'Pseudo Account', name: 'Pseudo Account',
domain: url, domain: url,
@ -791,101 +525,69 @@ function atSetup(type) {
prof: avatar, prof: avatar,
id: 'id+pseudo', id: 'id+pseudo',
vis: priv, vis: priv,
mode: '' mode: 'mastodon'
} }
} }
if (!i || i == '') { if (!i || i == '') {
M.toast({ html: lang.lang_fatalerroroccured + 'Error: access token', displayLength: 5000 }) M.toast({ html: lang.lang_fatalerroroccured + 'Error: access token', displayLength: 5000 })
return false return false
} }
var obj = JSON.parse(multi) let obj = JSON.parse(multi)
var target = obj.length
obj.push(add) obj.push(add)
localStorage.setItem('name_' + target, add['name']) const json = JSON.stringify(obj)
localStorage.setItem('user_' + target, add['username'])
localStorage.setItem('user-id_' + target, add['id'])
localStorage.setItem('prof_' + target, avatar)
var json = JSON.stringify(obj)
localStorage.setItem('multi', json) localStorage.setItem('multi', json)
refresh(target) refresh(target)
} }
//ユーザーデータ更新 //ユーザーデータ更新
function refresh(target) { async function refresh(i) {
var multi = localStorage.getItem('multi') const multi = localStorage.getItem('multi')
var obj = JSON.parse(multi) const obj = JSON.parse(multi)
console.log(obj) const target = obj[i]
if (obj[target].mode == 'misskey') { if (target.mode == 'misskey') {
misskeyRefresh(obj, target, obj[target].domain) misskeyRefresh(obj, target, target.domain)
return return
} }
var start = 'https://' + obj[target].domain + '/api/v1/accounts/verify_credentials' const start = `https://${target.domain}/api/v1/accounts/verify_credentials`
fetch(start, { const json = await getApi(start, target.at)
method: 'GET',
headers: {
'content-type': 'application/json',
Authorization: 'Bearer ' + obj[target].at
}
})
.then(function (response) {
if (!response.ok) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
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) { if (json.error) {
console.error('Error:' + json.error) console.error('Error:' + json.error)
M.toast({ html: lang.lang_fatalerroroccured + 'Error:' + json.error, displayLength: 5000 }) M.toast({ html: lang.lang_fatalerroroccured + 'Error:' + json.error, displayLength: 5000 })
return return
} }
var avatar = json['avatar'] const {avatar: avatarRaw, display_name: displayName, acct, id, source} = json
let avatar = avatarRaw
//missingがmissingなやつ //missingがmissingなやつ
if (avatar == '/avatars/original/missing.png' || !avatar) { if (avatar == '/avatars/original/missing.png' || !avatar) {
avatar = './img/missing.svg' avatar = './img/missing.svg'
} }
var ref = { let priv = 'public'
at: obj[target].at, if(source) priv = source.privacy
name: json['display_name'], const ref = {
domain: obj[target].domain, at: target.at,
user: json['acct'], name: displayName,
domain: target.domain,
user: acct,
prof: avatar, prof: avatar,
id: json['id'], id: id,
vis: json['source']['privacy'] vis: priv
} }
if (obj[target].background) { if (target.background) {
ref.background = obj[target].background ref.background = target.background
} }
if (obj[target].text) { if (target.text) {
ref.text = obj[target].text ref.text = target.text
} }
localStorage.setItem('name_' + target, json['display_name']) if (source.sensitive) {
localStorage.setItem('user_' + target, json['acct']) localStorage.setItem('nsfw_' + i, 'true')
localStorage.setItem('user-id_' + target, json['id'])
localStorage.setItem('prof_' + target, avatar)
if (json['source']['sensitive']) {
localStorage.setItem('nsfw_' + target, 'true')
} else { } else {
localStorage.removeItem('nsfw_' + target) localStorage.removeItem('nsfw_' + i)
} }
obj[target] = ref obj[i] = ref
var json = JSON.stringify(obj) const json = JSON.stringify(obj)
localStorage.setItem('multi', json) localStorage.setItem('multi', json)
load() load()
})
} }
function misskeyRefresh(obj, target, url) { function misskeyRefresh(obj, target, url) {
var start = 'https://' + url + '/api/users/show' var start = 'https://' + url + '/api/users/show'