add Pleroma refreshable token

This commit is contained in:
cutls 2021-01-19 04:06:13 +09:00
parent eaec63adb8
commit cc5ba8af0f
6 changed files with 268 additions and 228 deletions

View File

@ -88,4 +88,7 @@ i.left {
#domain-list .title { #domain-list .title {
font-size: 1.3rem; font-size: 1.3rem;
}
.text-line-icon {
font-size: 1rem;
} }

View File

@ -32,7 +32,7 @@ function ck() {
} else { } else {
var obj = JSON.parse(multi) var obj = JSON.parse(multi)
var jp = false var jp = false
Object.keys(obj).forEach(function(key) { Object.keys(obj).forEach(function (key) {
var acct = obj[key] var acct = obj[key]
if (acct.domain) { if (acct.domain) {
refresh(key, true) refresh(key, true)
@ -50,7 +50,7 @@ function ck() {
let tipsName = localStorage.getItem('tips') let tipsName = localStorage.getItem('tips')
const matchCID = /custom:([abcdef0-9]{8}-[abcdef0-9]{4}-4[abcdef0-9]{3}-[abcdef0-9]{4}-[abcdef0-9]{12})/ const matchCID = /custom:([abcdef0-9]{8}-[abcdef0-9]{4}-4[abcdef0-9]{3}-[abcdef0-9]{4}-[abcdef0-9]{12})/
if (tipsName) { if (tipsName) {
if(tipsName.match(matchCID)) { if (tipsName.match(matchCID)) {
const id = tipsName.match(matchCID)[1] const id = tipsName.match(matchCID)[1]
tips('custom', id) tips('custom', id)
} else { } else {
@ -84,7 +84,7 @@ function login(url) {
website: 'https://thedesk.top' website: 'https://thedesk.top'
}) })
) )
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) { if (this.status !== 200) {
@ -149,20 +149,20 @@ function code(code, mode) {
code: code code: code
}) })
}) })
.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) {
todo(error) todo(error)
setLog(start, 'JSON', error) setLog(start, 'JSON', error)
console.error(error) console.error(error)
}) })
.then(function(json) { .then(function (json) {
todo(json) todo(json)
if (json['access_token']) { if (json['access_token']) {
localStorage.setItem(url + '_at', json['access_token']) localStorage.setItem(url + '_at', json['access_token'])
@ -188,20 +188,20 @@ function getdata() {
Authorization: 'Bearer ' + at Authorization: 'Bearer ' + at
} }
}) })
.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) {
todo(error) todo(error)
setLog(start, 'JSON', error) setLog(start, 'JSON', error)
console.error(error) console.error(error)
}) })
.then(function(json) { .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 })
@ -246,20 +246,20 @@ function getdataAdv(domain, at) {
Authorization: 'Bearer ' + at Authorization: 'Bearer ' + at
} }
}) })
.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) {
todo(error) todo(error)
setLog(start, 'JSON', error) setLog(start, 'JSON', error)
console.error(error) console.error(error)
}) })
.then(function(json) { .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 })
@ -298,34 +298,40 @@ function getdataAdv(domain, at) {
}) })
} }
//ユーザーデータ更新 //ユーザーデータ更新
function refresh(target, loadskip) { async function refresh(target, loadskip) {
var multi = localStorage.getItem('multi') var multi = localStorage.getItem('multi')
var obj = JSON.parse(multi) var obj = JSON.parse(multi)
if (obj[target].mode == 'misskey') { if (obj[target].mode == 'misskey') {
return return
} }
let at = obj[target].at
if (obj[target].rt) {
console.log('refresh access token')
at = await refreshPleromaAt(obj[target])
localStorage.setItem(`acct_${target}_at`, at)
}
var start = 'https://' + obj[target].domain + '/api/v1/accounts/verify_credentials' var start = 'https://' + obj[target].domain + '/api/v1/accounts/verify_credentials'
fetch(start, { fetch(start, {
method: 'GET', method: 'GET',
headers: { headers: {
'content-type': 'application/json', 'content-type': 'application/json',
Authorization: 'Bearer ' + obj[target].at Authorization: 'Bearer ' + at
} }
}) })
.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) {
todo(error) todo(error)
setLog(start, 'JSON', error) setLog(start, 'JSON', error)
console.error(error) console.error(error)
}) })
.then(function(json) { .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 })
@ -369,6 +375,29 @@ function refresh(target, loadskip) {
} }
}) })
} }
async function refreshPleromaAt(obj) {
const start = 'https://' + obj.domain + '/oauth/token'
const rt = obj.rt.split(' ')
let promise = await fetch(start, {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
grant_type : 'refresh_token',
refresh_token: rt[0],
client_id: rt[1],
client_secret: rt[2]
})
})
const json = await promise.json()
if (json.access_token) {
return json.access_token
} else {
return false
}
}
//MarkdownやBBCodeの対応、文字数制限をチェック //MarkdownやBBCodeの対応、文字数制限をチェック
//絶対ストリーミングを閉じさせないマン //絶対ストリーミングを閉じさせないマン
function ckdb(acct_id) { function ckdb(acct_id) {
@ -454,13 +483,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
@ -507,7 +536,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) {
@ -575,8 +604,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>')
} }
@ -605,18 +634,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.removeItem('ticker') localStorage.removeItem('ticker')
localStorage.setItem('sticker', JSON.stringify(json)) localStorage.setItem('sticker', JSON.stringify(json))

View File

@ -36,7 +36,7 @@ function load() {
var domains = [] var domains = []
var templete var templete
$('#acct-list').html('') $('#acct-list').html('')
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 (acct.background != 'def' && acct.text != 'def') { if (acct.background != 'def' && acct.text != 'def') {
@ -55,6 +55,9 @@ function load() {
<div class="card-content "> <div class="card-content ">
<span class="lts">${list}.</span><img src="${acct.prof}" width="40" height="40" /> <span class="lts">${list}.</span><img src="${acct.prof}" width="40" height="40" />
<span class="card-title">${name}</span>${escapeHTML(acct.user)}@${acct.domain} <span class="card-title">${name}</span>${escapeHTML(acct.user)}@${acct.domain}
<a onclick="login('${acct.domain}')" class="pointer white-text waves-effect" title="${lang.lang_manager_refreshAt}">
<i class="material-icons text-line-icon">login</i>
</a>
</div> </div>
<div class="card-action"> <div class="card-action">
<button class="btn-flat waves-effect disTar pointer white-text" onclick="refresh('${key}')"> <button class="btn-flat waves-effect disTar pointer white-text" onclick="refresh('${key}')">
@ -72,7 +75,7 @@ function load() {
}) })
domains = _.uniq(domains) domains = _.uniq(domains)
$('#domain-list').html('') $('#domain-list').html('')
Object.keys(domains).forEach(function(key2) { Object.keys(domains).forEach(function (key2) {
var domain = domains[key2] var domain = domains[key2]
if (localStorage.getItem('letters_' + key2)) { if (localStorage.getItem('letters_' + key2)) {
var maxChars = localStorage.getItem('letters_' + key2) var maxChars = localStorage.getItem('letters_' + key2)
@ -108,7 +111,7 @@ load()
support() support()
function maxChars(domain, uid) { function maxChars(domain, uid) {
var value = $('#maxChars' + uid).val() var value = $('#maxChars' + uid).val()
if(value*1 < 1 || !Number.isInteger(value*1)) { if (value * 1 < 1 || !Number.isInteger(value * 1)) {
Swal.fire({ Swal.fire({
type: 'error', type: 'error',
title: 'Error' title: 'Error'
@ -127,8 +130,8 @@ function maxChars(domain, uid) {
localStorage.removeItem('multi') localStorage.removeItem('multi')
} }
} }
Object.keys(obj).forEach(function(key) { Object.keys(obj).forEach(function (key) {
if(obj[key].domain == domain) localStorage.setItem('letters_' + key, value) if (obj[key].domain == domain) localStorage.setItem('letters_' + key, value)
}) })
console.log('#maxChars' + uid, value) console.log('#maxChars' + uid, value)
load() load()
@ -208,7 +211,7 @@ 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) { Object.keys(obj).forEach(function (key) {
var nk = key - 1 var nk = key - 1
//公開範囲(差分のみ) //公開範囲(差分のみ)
if (key >= target) { if (key >= target) {
@ -227,7 +230,9 @@ function multiDel(target) {
var olddom = localStorage.getItem('domain_' + key) var olddom = localStorage.getItem('domain_' + key)
localStorage.setItem('domain_' + nk, olddom) localStorage.setItem('domain_' + nk, olddom)
var oldat = localStorage.getItem('acct_' + key + '_at') var oldat = localStorage.getItem('acct_' + key + '_at')
var oldrt = localStorage.getItem('acct_' + key + '_rt')
localStorage.setItem('acct_' + nk + '_at', oldat) localStorage.setItem('acct_' + nk + '_at', oldat)
localStorage.setItem('acct_' + nk + '_rt', oldrt)
localStorage.setItem('name_' + nk, localStorage.getItem('name_' + key)) localStorage.setItem('name_' + nk, localStorage.getItem('name_' + key))
localStorage.setItem('user_' + target, localStorage.getItem('user_' + key)) localStorage.setItem('user_' + target, localStorage.getItem('user_' + key))
localStorage.setItem('user-id_' + target, localStorage.getItem('user-id_' + key)) localStorage.setItem('user-id_' + target, localStorage.getItem('user-id_' + key))
@ -243,7 +248,7 @@ function multiDel(target) {
var col = localStorage.getItem('column') var col = localStorage.getItem('column')
var oldcols = JSON.parse(col) var oldcols = JSON.parse(col)
var newcols = [] var newcols = []
Object.keys(oldcols).forEach(function(key) { Object.keys(oldcols).forEach(function (key) {
var nk = key - 1 var nk = key - 1
var oldcol = oldcols[key] var oldcol = oldcols[key]
if (target < oldcol.domain) { if (target < oldcol.domain) {
@ -253,19 +258,19 @@ function multiDel(target) {
} }
var type = oldcol.type var type = oldcol.type
var data = null var data = null
if(oldcol.data) { if (oldcol.data) {
data = oldcol.data data = oldcol.data
} }
var background = null var background = null
if(oldcol.background) { if (oldcol.background) {
background = oldcol.background background = oldcol.background
} }
var text = null var text = null
if(oldcol.text) { if (oldcol.text) {
text = oldcol.text text = oldcol.text
} }
var left_fold = false var left_fold = false
if(oldcol.left_fold) { if (oldcol.left_fold) {
left_fold = true left_fold = true
} }
//消した垢のコラムじゃないときコピー //消した垢のコラムじゃないときコピー
@ -303,7 +308,7 @@ function multiDel2(target) {
obj.splice(target, 1) obj.splice(target, 1)
var json = JSON.stringify(obj) var json = JSON.stringify(obj)
localStorage.setItem('multi', json) localStorage.setItem('multi', json)
Object.keys(obj).forEach(function(key) { Object.keys(obj).forEach(function (key) {
if (key >= target) { if (key >= target) {
var oldvis = localStorage.getItem('vis-memory-' + key) var oldvis = localStorage.getItem('vis-memory-' + key)
if (oldvis) { if (oldvis) {
@ -331,7 +336,7 @@ function multiDel2(target) {
} else { } else {
var cobj = JSON.parse(col) var cobj = JSON.parse(col)
} }
Object.keys(cobj).forEach(function(key) { Object.keys(cobj).forEach(function (key) {
var column = cobj[key] var column = cobj[key]
if (column.domain > target) { if (column.domain > target) {
var nk = key - 1 var nk = key - 1
@ -351,7 +356,7 @@ function multiDel2(target) {
//サポートインスタンス //サポートインスタンス
function support() { function support() {
Object.keys(idata).forEach(function(key) { Object.keys(idata).forEach(function (key) {
var instance = idata[key] var instance = idata[key]
if (instance == 'instance') { if (instance == 'instance') {
templete = templete =
@ -399,7 +404,7 @@ function login(url) {
website: 'https://thedesk.top' website: 'https://thedesk.top'
}) })
) )
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) { if (this.status !== 200) {
@ -437,20 +442,20 @@ function versionChecker(url) {
'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) {
todo(error) todo(error)
setLog(start, 'JSON', error) setLog(start, 'JSON', error)
console.error(error) console.error(error)
}) })
.then(function(json) { .then(function (json) {
var version = json.version var version = json.version
if (version) { if (version) {
var reg = version.match(/^([0-9])\.[0-9]\.[0-9]/u) var reg = version.match(/^([0-9])\.[0-9]\.[0-9]/u)
@ -476,25 +481,25 @@ function versionCompat(prefix, ver, title, real) {
'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) {
todo(error) todo(error)
setLog(start, 'JSON', error) setLog(start, 'JSON', error)
console.error(error) console.error(error)
}) })
.then(function(json) { .then(function (json) {
var complete = false var complete = false
var ct = 0 var ct = 0
var jl = 0 var jl = 0
var jl2 = 0 var jl2 = 0
Object.keys(json).forEach(function(key) { Object.keys(json).forEach(function (key) {
var data = json[key] var data = json[key]
if (data) { if (data) {
jl++ jl++
@ -581,7 +586,7 @@ function misskeyLogin(url) {
] ]
}) })
) )
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) { if (this.status !== 200) {
@ -605,7 +610,7 @@ function misskeyAuth(url, mkc) {
appSecret: mkc appSecret: mkc
}) })
) )
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) { if (this.status !== 200) {
@ -629,9 +634,8 @@ function instance() {
alert('入力形式が違います。(Cutls@mstdn.jpにログインする場合、入力するのは"mstdn.jp"です。)') alert('入力形式が違います。(Cutls@mstdn.jpにログインする場合、入力するのは"mstdn.jp"です。)')
return false return false
} }
login(url) login(url)
} }
//コード入れてAccessTokenゲット //コード入れてAccessTokenゲット
function code(code) { function code(code) {
localStorage.removeItem('redirect') localStorage.removeItem('redirect')
@ -657,7 +661,7 @@ function code(code) {
appSecret: localStorage.getItem('mkc') appSecret: localStorage.getItem('mkc')
}) })
) )
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) { if (this.status !== 200) {
@ -716,7 +720,7 @@ function code(code) {
code: code code: code
}) })
) )
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) { if (this.status !== 200) {
@ -725,14 +729,16 @@ function code(code) {
if (json['access_token']) { if (json['access_token']) {
$('#auth').hide() $('#auth').hide()
$('#add').show() $('#add').show()
getdata(url, json['access_token']) getdata(url, json)
} }
} }
} }
} }
} }
//ユーザーデータ取得 //ユーザーデータ取得
function getdata(domain, at) { function getdata(domain, json) {
var at = json['access_token']
var rt = `${json['refresh_token']} ${localStorage.getItem('client_id')} ${localStorage.getItem('client_secret')}`
var start = 'https://' + domain + '/api/v1/accounts/verify_credentials' var start = 'https://' + domain + '/api/v1/accounts/verify_credentials'
fetch(start, { fetch(start, {
method: 'GET', method: 'GET',
@ -741,20 +747,20 @@ function getdata(domain, at) {
Authorization: 'Bearer ' + at Authorization: 'Bearer ' + at
} }
}) })
.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) {
todo(error) todo(error)
setLog(start, 'JSON', error) setLog(start, 'JSON', error)
console.error(error) console.error(error)
}) })
.then(function(json) { .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 })
@ -772,6 +778,7 @@ function getdata(domain, at) {
} }
var add = { var add = {
at: at, at: at,
rt: rt ? rt : null,
name: json['display_name'], name: json['display_name'],
domain: domain, domain: domain,
user: json['acct'], user: json['acct'],
@ -782,8 +789,24 @@ function getdata(domain, at) {
} }
var multi = localStorage.getItem('multi') var multi = localStorage.getItem('multi')
var obj = JSON.parse(multi) var obj = JSON.parse(multi)
var target = obj.length let addTarget = -1
obj.push(add) let ct = 0
for (let acct of obj) {
if (acct.domain === domain && acct.user === json['acct']) {
console.log('detected dupl addct')
addTarget = ct
break
}
ct++
}
if (addTarget == -1) {
var target = obj.length
obj.push(add)
} else {
console.log('dupl acct_' + addTarget)
obj[addTarget] = add
var target = addTarget
}
localStorage.setItem('name_' + target, json['display_name']) localStorage.setItem('name_' + target, json['display_name'])
localStorage.setItem('user_' + target, json['acct']) localStorage.setItem('user_' + target, json['acct'])
localStorage.setItem('user-id_' + target, json['id']) localStorage.setItem('user-id_' + target, json['id'])
@ -807,6 +830,7 @@ function atSetup(type) {
var i = $('#misskey-key').val() var i = $('#misskey-key').val()
var add = { var add = {
at: i, at: i,
rt: null,
name: 'Pseudo Account', name: 'Pseudo Account',
domain: url, domain: url,
user: 'user+pseudo', user: 'user+pseudo',
@ -820,6 +844,7 @@ function atSetup(type) {
var i = $('#code').val() var i = $('#code').val()
var add = { var add = {
at: i, at: i,
rt: null,
name: 'Pseudo Account', name: 'Pseudo Account',
domain: url, domain: url,
user: 'user+pseudo', user: 'user+pseudo',
@ -862,25 +887,25 @@ function refresh(target) {
Authorization: 'Bearer ' + obj[target].at Authorization: 'Bearer ' + obj[target].at
} }
}) })
.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)
}) })
} }
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) {
todo(error) todo(error)
setLog(start, 'JSON', error) setLog(start, 'JSON', error)
console.error(error) console.error(error)
}) })
.then(function(json) { .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 })
@ -893,6 +918,7 @@ function refresh(target) {
} }
var ref = { var ref = {
at: obj[target].at, at: obj[target].at,
rt: obj[target].rt ? obj[target].rt : null,
name: json['display_name'], name: json['display_name'],
domain: obj[target].domain, domain: obj[target].domain,
user: json['acct'], user: json['acct'],
@ -934,7 +960,7 @@ function misskeyRefresh(obj, target, url) {
i: obj[target].at i: obj[target].at
}) })
) )
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) { if (this.status !== 200) {
@ -944,6 +970,7 @@ function misskeyRefresh(obj, target, url) {
var priv = 'public' var priv = 'public'
var add = { var add = {
at: json.accessToken, at: json.accessToken,
rt: null,
name: json['user']['name'], name: json['user']['name'],
domain: url, domain: url,
user: json['user']['username'], user: json['user']['username'],
@ -983,7 +1010,7 @@ function multisel() {
$('#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) {
@ -1073,10 +1100,10 @@ var oldSuggest
var suggest var suggest
input.addEventListener( input.addEventListener(
'focus', 'focus',
function() { function () {
$('#ins-suggest').html('') $('#ins-suggest').html('')
window.clearInterval(timer) window.clearInterval(timer)
timer = window.setInterval(function() { timer = window.setInterval(function () {
var new_val = input.value var new_val = input.value
if (prev_val != new_val) { if (prev_val != new_val) {
if (new_val.length > 3) { if (new_val.length > 3) {
@ -1089,23 +1116,23 @@ input.addEventListener(
'Bearer tC8F6xWGWBUwGScyNevYlx62iO6fdQ4oIK0ad68Oo7ZKB8GQdGpjW9TKxBnIh8grAhvd5rw3iyP9JPamoDpeLQdz62EToPJUW99hDx8rfuJfGdjQuimZPTbIOx0woA5M' 'Bearer tC8F6xWGWBUwGScyNevYlx62iO6fdQ4oIK0ad68Oo7ZKB8GQdGpjW9TKxBnIh8grAhvd5rw3iyP9JPamoDpeLQdz62EToPJUW99hDx8rfuJfGdjQuimZPTbIOx0woA5M'
} }
}) })
.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) {
todo(error) todo(error)
setLog(start, 'JSON', error) setLog(start, 'JSON', error)
console.error(error) console.error(error)
}) })
.then(function(json) { .then(function (json) {
if (!json.error) { if (!json.error) {
var urls = 'Suggest:' var urls = 'Suggest:'
Object.keys(json.instances).forEach(function(key) { Object.keys(json.instances).forEach(function (key) {
var url = json.instances[key] var url = json.instances[key]
urls = urls =
urls + urls +
@ -1127,7 +1154,7 @@ input.addEventListener(
input.addEventListener( input.addEventListener(
'blur', 'blur',
function() { function () {
window.clearInterval(timer) window.clearInterval(timer)
}, },
false false

View File

@ -51,6 +51,7 @@ function parseColumn(target, dontclose) {
localStorage.setItem('prof_' + key, acct.prof) localStorage.setItem('prof_' + key, acct.prof)
localStorage.setItem('domain_' + key, acct.domain) localStorage.setItem('domain_' + key, acct.domain)
localStorage.setItem('acct_' + key + '_at', acct.at) localStorage.setItem('acct_' + key + '_at', acct.at)
localStorage.setItem('acct_' + key + '_rt', acct.rt ? acct.rt : null)
if(!target) mastodonBaseStreaming(key) if(!target) mastodonBaseStreaming(key)
ckdb(key) ckdb(key)
//フィルターデータ読もう //フィルターデータ読もう

View File

@ -405,6 +405,7 @@ function importSettingsCore(obj) {
localStorage.setItem('prof_' + key, acct.prof) localStorage.setItem('prof_' + key, acct.prof)
localStorage.setItem('domain_' + key, acct.domain) localStorage.setItem('domain_' + key, acct.domain)
localStorage.setItem('acct_' + key + '_at', acct.at) localStorage.setItem('acct_' + key + '_at', acct.at)
localStorage.setItem('acct_' + key + '_rt', acct.rt ? acct.rt : null)
} }
localStorage.setItem('column', JSON.stringify(obj.columns)) localStorage.setItem('column', JSON.stringify(obj.columns))
if (obj.config) { if (obj.config) {

View File

@ -1,154 +1,133 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="@@lang@@"> <html lang="@@lang@@">
<head>
<title>Account Manager - TheDesk</title>
<meta content="width=device-width,initial-scale=1.0" name="viewport" />
<link href="../../css/themes.css" type="text/css" rel="stylesheet">
<link
href="../../@@node_base@@/materialize-css/dist/css/materialize.css"
type="text/css"
rel="stylesheet"
/>
<link href="../../css/master.css" type="text/css" rel="stylesheet" />
<link href="../../css/tl.css" rel="stylesheet" type="text/css" />
<link href="../../css/userdata.css" rel="stylesheet" type="text/css" />
<link
href="../../@@node_base@@/@fortawesome/fontawesome-free/css/all.min.css"
type="text/css"
rel="stylesheet"
/>
<link href="../../css/acct.css" rel="stylesheet" type="text/css" />
<meta charset="utf-8" />
@@comment-start@@
<script type="text/javascript">
var _jipt = []
_jipt.push(['project', 'thedesk'])
</script>
<script type="text/javascript" src="https://cdn.crowdin.com/jipt/jipt.js"></script>
@@comment-end@@
@@pwa@@ @@store@@
</head>
<body id="mainView" class="@@pwaClass@@"> <head>
<script type="text/javascript" src="../../@@node_base@@/jquery/dist/jquery.js"></script> <title>Account Manager - TheDesk</title>
<script type="text/javascript" src="../../js/platform/first.js"></script> <meta content="width=device-width,initial-scale=1.0" name="viewport" />
<script <link href="../../css/themes.css" type="text/css" rel="stylesheet">
type="text/javascript" <link href="../../@@node_base@@/materialize-css/dist/css/materialize.css" type="text/css" rel="stylesheet" />
src="../../@@node_base@@/materialize-css/dist/js/materialize.js" <link href="../../css/master.css" type="text/css" rel="stylesheet" />
></script> <link href="../../css/tl.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="main.js"></script> <link href="../../css/userdata.css" rel="stylesheet" type="text/css" />
<script <link href="../../@@node_base@@/@fortawesome/fontawesome-free/css/all.min.css" type="text/css" rel="stylesheet" />
type="text/javascript" <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
src="../../@@node_base@@/sweetalert2/dist/sweetalert2.all.min.js" <link href="../../css/acct.css" rel="stylesheet" type="text/css" />
></script> <meta charset="utf-8" />
<script> @@comment-start@@
var misskeytoken = false <script type="text/javascript">
</script> var _jipt = []
<script type="text/javascript" src="../../js/common/time.js"></script> _jipt.push(['project', 'thedesk'])
<div class="hide-first"> </script>
<a href="index.html" class="btn waves-effect orange nex" style="width:100%; max-width:200px;" <script type="text/javascript" src="https://cdn.crowdin.com/jipt/jipt.js"></script>
>@@back@@</a @@comment-end@@
><br /> @@pwa@@ @@store@@
<h5>@@list@@</h5> </head>
<div id="acct-list"></div>
<div class="divider"></div> <body id="mainView" class="@@pwaClass@@">
</div> <script type="text/javascript" src="../../@@node_base@@/jquery/dist/jquery.js"></script>
<div class="hide-second"> <script type="text/javascript" src="../../js/platform/first.js"></script>
<a href="setting.html">@@haveExported@@</a> <script type="text/javascript" src="../../@@node_base@@/materialize-css/dist/js/materialize.js"></script>
</div> <script type="text/javascript" src="main.js"></script>
<div> <script type="text/javascript" src="../../@@node_base@@/sweetalert2/dist/sweetalert2.all.min.js"></script>
<h5>@@add@@</h5> <script>
<br /> var misskeytoken = false
<div id="add"> </script>
<div class="row"> <script type="text/javascript" src="../../js/common/time.js"></script>
<div class="col s8"> <div class="hide-first">
@@addAcct@@<br /> <a href="index.html" class="btn waves-effect orange nex" style="width:100%; max-width:200px;">@@back@@</a><br />
<input type="text" id="url" style="width:70%" placeholder="ex)mstdn.jp" /> <h5>@@list@@</h5>
<div id="ins-suggest"></div> <div id="acct-list"></div>
<button class="btn waves-effect" onclick="instance()">Login</button><br /> <div class="divider"></div>
<div class="pwa"> </div>
@@codesetupwarn@@<br /> <div class="hide-second">
<label> <a href="setting.html">@@haveExported@@</a>
<input type="checkbox" class="filled-in" id="linux" /> </div>
<span>@@codesetup@@</span> <div>
</label> <h5>@@add@@</h5>
<br /> <br />
</div> <div id="add">
<div class="row">
<div class="col s8">
@@addAcct@@<br />
<input type="text" id="url" style="width:70%" placeholder="ex)mstdn.jp" />
<div id="ins-suggest"></div>
<button class="btn waves-effect" onclick="instance()">Login</button><br />
<div class="pwa">
@@codesetupwarn@@<br />
<label> <label>
<input type="checkbox" class="filled-in" id="misskey" /> <input type="checkbox" class="filled-in" id="linux" />
<span>@@thisismisskey@@</span> </label <span>@@codesetup@@</span>
><br /> </label>
</div> <br />
<div class="col s4 scr" aria-hidden="true">
<span style="font-family:Open Sans;">Supports</span>
<div id="support" class="collection transparent"></div>
</div> </div>
<label>
<input type="checkbox" class="filled-in" id="misskey" />
<span>@@thisismisskey@@</span> </label><br />
</div>
<div class="col s4 scr" aria-hidden="true">
<span style="font-family:Open Sans;">Supports</span>
<div id="support" class="collection transparent"></div>
</div> </div>
</div> </div>
<div id="auth" style="display:none"> </div>
@@codepastewarn@@<br /> <div id="auth" style="display:none">
<input type="text" id="code" placeholder="@@codepaste@@" required /> @@codepastewarn@@<br />
<button class="btn waves-effect" onclick="code()">Auth</button><br /> <input type="text" id="code" placeholder="@@codepaste@@" required />
<br /> <button class="btn waves-effect" onclick="code()">Auth</button><br />
<a onclick="atSetup()" class="pointer">@@accessTokenSetup@@</a> <br />
<div id="compt" style="display:none" class="scr"> <a onclick="atSetup()" class="pointer">@@accessTokenSetup@@</a>
<h5>ログイン前に必ずご確認ください</h5> <div id="compt" style="display:none" class="scr">
<span id="compt-instance"></span>はバージョンが<span id="compt-ver"></span <h5>ログイン前に必ずご確認ください</h5>
>のため以下の機能がご利用いただけません。 <span id="compt-instance"></span>はバージョンが<span id="compt-ver"></span>のため以下の機能がご利用いただけません。
<span id="compt-warn" style="display:none" <span id="compt-warn"
>また、このインスタンスはMastodonではなくそのAPI上の互換実装であり、TheDeskでは利用を想定していないため非保証となります。</span style="display:none">また、このインスタンスはMastodonではなくそのAPI上の互換実装であり、TheDeskでは利用を想定していないため非保証となります。</span>
> <ul id="compt-list"></ul>
<ul id="compt-list"></ul>
</div>
</div>
<div id="misskeylogin" style="display:none">
<h5>AppSecret</h5>
@@misskeylogin@@<br />
<input type="hidden" id="misskey-url" />
<input type="text" id="misskey-key" placeholder="@@codepaste@@" required />
<button class="btn waves-effect" onclick="misskeyLogin()">Auth</button><br />
<br />
<a onclick="atSetup('misskey')" class="pointer">@@accessTokenSetup@@</a>
</div> </div>
</div> </div>
<div class="hide-first"> <div id="misskeylogin" style="display:none">
<h5>@@mainacct@@</h5> <h5>AppSecret</h5>
<div class="input-field" style="width:300px"> @@misskeylogin@@<br />
<span data-trans="your_acct">@@selacct@@</span> <input type="hidden" id="misskey-url" />
<br /> <input type="text" id="misskey-key" placeholder="@@codepaste@@" required />
<select <button class="btn waves-effect" onclick="misskeyLogin()">Auth</button><br />
id="main-acct-sel" <br />
class="acct-sel" <a onclick="atSetup('misskey')" class="pointer">@@accessTokenSetup@@</a>
style="color:black"
onchange="mainacct()"
></select>
<label></label>
</div>
<ul id="domain-list" class="collection transparent"></ul>
<div id="instance-data">
Some instance data by
<a href="https://instances.social" target="_blank">instances.social API</a><br />
<h5 id="ins-title"></h5>
Administered by:<a id="ins-admin"></a><br />
<span id="ins-desc"></span><br />
<img src="../../img/loading.svg" id="ins-prof" width="200" /><br />
<br />
@@domain@@:<span id="ins-name"></span><br />
@@connect@@:<span id="ins-connect"></span>@@ko@@<br />
@@toots@@:<span id="ins-toot"></span>@@ko@@<br />
@@users@@:<span id="ins-user"></span>@@users@@<br />
@@safety@@:<span id="ins-per"></span>%<br />
@@ver@@:<span id="ins-ver"></span>@<span id="ins-upd"></span><br />
</div>
</div> </div>
<script type="text/javascript" src="../../js/ui/theme.js"></script> </div>
<script type="text/javascript" src="../../js/ui/tips.js"></script> <div class="hide-first">
<script type="text/javascript" src="../../js/platform/end.js"></script> <h5>@@mainacct@@</h5>
<script type="text/javascript" src="../../js/common/sha256.js"></script> <div class="input-field" style="width:300px">
<script type="text/javascript" src="../../@@node_base@@/lodash/lodash.min.js"></script> <span data-trans="your_acct">@@selacct@@</span>
<script type="text/javascript" src="../../js/login/instance.js"></script> <br />
<script type="text/javascript" src="../../js/login/manager.js"></script> <select id="main-acct-sel" class="acct-sel" style="color:black" onchange="mainacct()"></select>
<script type="text/javascript" src="../../js/tl/date.js"></script> <label></label>
<script>$('body').addClass(localStorage.getItem('platform'))</script> </div>
</body> <ul id="domain-list" class="collection transparent"></ul>
</html> <div id="instance-data">
Some instance data by
<a href="https://instances.social" target="_blank">instances.social API</a><br />
<h5 id="ins-title"></h5>
Administered by:<a id="ins-admin"></a><br />
<span id="ins-desc"></span><br />
<img src="../../img/loading.svg" id="ins-prof" width="200" /><br />
<br />
@@domain@@:<span id="ins-name"></span><br />
@@connect@@:<span id="ins-connect"></span>@@ko@@<br />
@@toots@@:<span id="ins-toot"></span>@@ko@@<br />
@@users@@:<span id="ins-user"></span>@@users@@<br />
@@safety@@:<span id="ins-per"></span>%<br />
@@ver@@:<span id="ins-ver"></span>@<span id="ins-upd"></span><br />
</div>
</div>
<script type="text/javascript" src="../../js/ui/theme.js"></script>
<script type="text/javascript" src="../../js/ui/tips.js"></script>
<script type="text/javascript" src="../../js/platform/end.js"></script>
<script type="text/javascript" src="../../js/common/sha256.js"></script>
<script type="text/javascript" src="../../@@node_base@@/lodash/lodash.min.js"></script>
<script type="text/javascript" src="../../js/login/instance.js"></script>
<script type="text/javascript" src="../../js/login/manager.js"></script>
<script type="text/javascript" src="../../js/tl/date.js"></script>
<script>$('body').addClass(localStorage.getItem('platform'))</script>
</body>
</html>