Fix: the account color pref. is sometimes losted

This commit is contained in:
cutls 2019-11-10 20:37:13 +09:00
parent f3fa854074
commit 542ee57f93
2 changed files with 368 additions and 332 deletions

View File

@ -2,128 +2,137 @@
//最初に読むやつ //最初に読むやつ
//アスタルテ判定初期化 //アスタルテ判定初期化
localStorage.removeItem("kirishima"); localStorage.removeItem('kirishima')
localStorage.removeItem("quoters"); localStorage.removeItem('quoters')
localStorage.removeItem("imas"); localStorage.removeItem('imas')
localStorage.removeItem("image"); localStorage.removeItem('image')
localStorage.removeItem("stable"); localStorage.removeItem('stable')
localStorage.setItem("mode_misskey.xyz", "misskey"); localStorage.setItem('mode_misskey.xyz', 'misskey')
function ck() { function ck() {
var main = localStorage.getItem("main"); var 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=(.+)/); var m = location.search.match(/\?mode=([a-zA-Z-0-9]+)\&code=(.+)/)
var mode = m[1]; var mode = m[1]
var codex = m[2]; var 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"); var multi = localStorage.getItem('multi')
if (!multi || multi == "[]") { if (!multi || multi == '[]') {
var date = new Date(); var 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); 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)
} }
if (acct.domain == "mstdn.jp") { if (acct.domain == 'mstdn.jp') {
jp = true; jp = true
} }
}); })
if (obj[0].domain) { if (obj[0].domain) {
$("#tl").show(); $('#tl').show()
ticker(); ticker()
multiSelector(false); multiSelector(false)
verck(ver, jp); verck(ver, jp)
$(".stw").show(); $('.stw').show()
$("#something-wrong img").attr("src", "../../img/thinking.svg"); $('#something-wrong img').attr('src', '../../img/thinking.svg')
} }
} }
} }
ck(); ck()
//ログインポップアップ //ログインポップアップ
function login(url) { function login(url) {
if ($("#linux:checked").val() == "on") { if ($('#linux:checked').val() == 'on') {
var red = "urn:ietf:wg:oauth:2.0:oob"; var red = 'urn:ietf:wg:oauth:2.0:oob'
} else { } else {
var red = "thedesk://login"; var red = 'thedesk://login'
} }
localStorage.setItem("redirect", red); localStorage.setItem('redirect', red)
var start = "https://" + url + "/api/v1/apps"; var start = 'https://' + url + '/api/v1/apps'
var httpreq = new XMLHttpRequest(); var httpreq = new XMLHttpRequest()
httpreq.open("POST", start, true); httpreq.open('POST', start, true)
httpreq.setRequestHeader("Content-Type", "application/json"); httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.responseType = "json"; httpreq.responseType = 'json'
httpreq.send( httpreq.send(
JSON.stringify({ 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'
}) })
); )
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) {
setLog(start, this.status, json); 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"; var auth =
localStorage.setItem("domain_" + acct_id, url); 'https://' +
localStorage.setItem("client_id", json["client_id"]); url +
localStorage.setItem("client_secret", json["client_secret"]); '/oauth/authorize?client_id=' +
$("#auth").show(); json['client_id'] +
$("#masara").hide(); '&client_secret=' +
postMessage(["openUrl", auth], "*"); 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") { if ($('#linux:checked').val() == 'on') {
} else { } else {
postMessage(["sendSinmpleIpc", "quit"], "*"); postMessage(['sendSinmpleIpc', 'quit'], '*')
} }
} }
}; }
} }
//テキストボックスにURL入れた //テキストボックスにURL入れた
function instance() { function instance() {
var url = $("#url").val(); var url = $('#url').val()
login(url); login(url)
} }
//コードを入れた後認証 //コードを入れた後認証
function code(code, mode) { function code(code, mode) {
var red = localStorage.getItem("redirect"); var red = localStorage.getItem('redirect')
localStorage.removeItem("redirect"); localStorage.removeItem('redirect')
if (!code) { if (!code) {
var code = $("#code").val(); var code = $('#code').val()
} }
if (localStorage.getItem("domain_tmp")) { if (localStorage.getItem('domain_tmp')) {
var url = localStorage.getItem("domain_tmp"); var url = localStorage.getItem('domain_tmp')
} else { } else {
var url = localStorage.getItem("domain_" + acct_id); var url = localStorage.getItem('domain_' + acct_id)
} }
var start = "https://" + url + "/oauth/token"; var start = 'https://' + url + '/oauth/token'
var id = localStorage.getItem("client_id"); var id = localStorage.getItem('client_id')
var secret = localStorage.getItem("client_secret"); var secret = localStorage.getItem('client_secret')
fetch(start, { fetch(start, {
method: "POST", method: 'POST',
headers: { headers: {
"content-type": "application/json" 'content-type': 'application/json'
}, },
body: JSON.stringify({ body: 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,
@ -133,451 +142,472 @@ function code(code, mode) {
.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'])
if (mode == "manager") { if (mode == 'manager') {
getdataAdv(url, json["access_token"]); getdataAdv(url, json['access_token'])
} else { } else {
getdata(); getdata()
} }
} }
}); })
} }
//ユーザーデータ取得(最初) //ユーザーデータ取得(最初)
function getdata() { function getdata() {
var acct_id = 0; var acct_id = 0
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/verify_credentials"; var start = 'https://' + 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 " + 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 })
return; return
} }
var avatar = json["avatar"]; var avatar = json['avatar']
//missingがmissingなやつ //missingがmissingなやつ
if (avatar == "/avatars/original/missing.png") { if (avatar == '/avatars/original/missing.png') {
avatar = "./img/missing.svg"; avatar = './img/missing.svg'
} }
var obj = [ var obj = [
{ {
at: at, at: at,
name: json["display_name"], name: json['display_name'],
domain: domain, domain: domain,
user: json["acct"], user: json['acct'],
prof: avatar, prof: avatar,
id: json["id"], id: json['id'],
vis: json["source"]["privacy"] vis: json['source']['privacy']
} }
]; ]
var json = JSON.stringify(obj); var json = JSON.stringify(obj)
localStorage.setItem("multi", json); localStorage.setItem('multi', json)
localStorage.setItem("name_" + acct_id, json["display_name"]); localStorage.setItem('name_' + acct_id, json['display_name'])
localStorage.setItem("user_" + acct_id, json["acct"]); localStorage.setItem('user_' + acct_id, json['acct'])
localStorage.setItem("user-id_" + acct_id, json["id"]); localStorage.setItem('user-id_' + acct_id, json['id'])
localStorage.setItem("prof_" + acct_id, avatar); localStorage.setItem('prof_' + acct_id, avatar)
$("#masara").hide(); $('#masara').hide()
$("#auth").hide(); $('#auth').hide()
$("#tl").show(); $('#tl').show()
parseColumn(); parseColumn()
ckdb(); ckdb()
}); })
} }
//ユーザーデータ取得(追加) //ユーザーデータ取得(追加)
function getdataAdv(domain, at) { function getdataAdv(domain, at) {
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',
headers: { headers: {
"content-type": "application/json", 'content-type': 'application/json',
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 })
return; return
} }
var avatar = json["avatar"]; var avatar = json['avatar']
//missingがmissingなやつ //missingがmissingなやつ
if (avatar == "/avatars/original/missing.png") { if (avatar == '/avatars/original/missing.png') {
avatar = "../../img/missing.svg"; avatar = '../../img/missing.svg'
} }
if (json["source"]["privacy"]) { if (json['source']['privacy']) {
var priv = json["source"]["privacy"]; var priv = json['source']['privacy']
} else { } else {
var priv = "public"; var priv = 'public'
} }
var add = { var add = {
at: at, at: at,
name: json["display_name"], name: json['display_name'],
domain: domain, domain: domain,
user: json["acct"], user: json['acct'],
prof: avatar, prof: avatar,
id: json["id"], id: json['id'],
vis: priv vis: priv
}; }
var multi = localStorage.getItem("multi"); var multi = localStorage.getItem('multi')
var obj = JSON.parse(multi); var obj = JSON.parse(multi)
var target = obj.lengtth; var target = obj.lengtth
obj.push(add); obj.push(add)
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'])
localStorage.setItem("prof_" + target, avatar); localStorage.setItem('prof_' + target, avatar)
var json = JSON.stringify(obj); var json = JSON.stringify(obj)
localStorage.setItem("multi", json); localStorage.setItem('multi', json)
location.href = "index.html"; location.href = 'index.html'
}); })
} }
//ユーザーデータ更新 //ユーザーデータ更新
function refresh(target, loadskip) { 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
} }
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 ' + 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)
}); })
} }
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 })
return; return
} }
var avatar = json["avatar"]; var avatar = json['avatar']
//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 = { var ref = {
at: obj[target].at, at: obj[target].at,
name: json["display_name"], name: json['display_name'],
domain: obj[target].domain, domain: obj[target].domain,
user: json["acct"], user: json['acct'],
prof: avatar, prof: avatar,
id: json["id"], id: json['id'],
vis: json["source"]["privacy"] vis: json['source']['privacy']
}; }
localStorage.setItem("name_" + target, json["display_name"]); if (obj[target].background) {
localStorage.setItem("user_" + target, json["acct"]); ref.background = obj[target].background
localStorage.setItem("user-id_" + target, json["id"]); }
localStorage.setItem("prof_" + target, avatar); if (obj[target].text) {
localStorage.setItem("follow_" + target, json["following_count"]); ref.text = obj[target].text
if (json["source"]["sensitive"]) { }
localStorage.setItem("nsfw_" + target, "true"); 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 { } else {
localStorage.removeItem("nsfw_" + target); localStorage.removeItem('nsfw_' + target)
} }
obj[target] = ref; obj[target] = ref
var json = JSON.stringify(obj); var json = JSON.stringify(obj)
localStorage.setItem("multi", json); localStorage.setItem('multi', json)
if (!loadskip) { if (!loadskip) {
load(); load()
} }
}); })
} }
//MarkdownやBBCodeの対応、文字数制限をチェック //MarkdownやBBCodeの対応、文字数制限をチェック
//絶対ストリーミングを閉じさせないマン //絶対ストリーミングを閉じさせないマン
function ckdb(acct_id) { function ckdb(acct_id) {
var domain = localStorage.getItem("domain_" + acct_id); var domain = localStorage.getItem('domain_' + acct_id)
localStorage.removeItem("home_" + acct_id); localStorage.removeItem('home_' + acct_id)
localStorage.removeItem("bb_" + acct_id); localStorage.removeItem('bb_' + acct_id)
localStorage.removeItem("md_" + acct_id); localStorage.removeItem('md_' + acct_id)
localStorage.removeItem("local_" + acct_id); localStorage.removeItem('local_' + acct_id)
localStorage.removeItem("public_" + acct_id); localStorage.removeItem('public_' + acct_id)
localStorage.removeItem("notification_" + acct_id); localStorage.removeItem('notification_' + acct_id)
localStorage.removeItem("post_" + acct_id); localStorage.removeItem('post_' + acct_id)
localStorage.removeItem("fav_" + acct_id); localStorage.removeItem('fav_' + acct_id)
localStorage.removeItem("bt_" + acct_id); localStorage.removeItem('bt_' + acct_id)
localStorage.removeItem("followlocale_" + 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(); $('.imasonly').show()
} }
var at = localStorage.getItem("acct_" + acct_id + "_at"); var at = localStorage.getItem('acct_' + acct_id + '_at')
var bbcode = domain + "_bbcode"; var bbcode = domain + '_bbcode'
var letters = domain + "_letters"; var letters = domain + '_letters'
var quoteMarker = domain + "_quote"; var quoteMarker = domain + '_quote'
if (localStorage.getItem("instance")) { if (localStorage.getItem('instance')) {
var json = JSON.parse(localStorage.getItem("instance")); var json = JSON.parse(localStorage.getItem('instance'))
if (json[quoteMarker] == "enabled") { if (json[quoteMarker] == 'enabled') {
localStorage.setItem("quoters", "true"); localStorage.setItem('quoters', 'true')
localStorage.setItem("quote_" + acct_id, "true"); localStorage.setItem('quote_' + acct_id, 'true')
} }
if (json[bbcode]) { if (json[bbcode]) {
if (json[bbcode] == "enabled") { if (json[bbcode] == 'enabled') {
localStorage.setItem("bb_" + acct_id, "true"); localStorage.setItem('bb_' + acct_id, 'true')
} else { } else {
localStorage.removeItem("bb_" + acct_id); localStorage.removeItem('bb_' + acct_id)
$("[data-activates='bbcode']").addClass("disabled"); $("[data-activates='bbcode']").addClass('disabled')
$("[data-activates='bbcode']").prop("disabled", true); $("[data-activates='bbcode']").prop('disabled', true)
} }
} else { } else {
localStorage.removeItem("bb_" + acct_id); localStorage.removeItem('bb_' + acct_id)
$("[data-activates='bbcode']").addClass("disabled"); $("[data-activates='bbcode']").addClass('disabled')
$("[data-activates='bbcode']").addClass("disabled", true); $("[data-activates='bbcode']").addClass('disabled', true)
} }
if (json[domain + "_markdown"] == "enabled") { if (json[domain + '_markdown'] == 'enabled') {
localStorage.setItem("md_" + acct_id, "true"); localStorage.setItem('md_' + acct_id, 'true')
$(".markdown").show(); $('.markdown').show()
} else { } else {
$(".anti-markdown").hide(); $('.anti-markdown').hide()
$(".markdown").hide(); $('.markdown').hide()
localStorage.removeItem("bb_" + acct_id); localStorage.removeItem('bb_' + acct_id)
} }
if (json[domain + "_home"]) { if (json[domain + '_home']) {
localStorage.setItem("home_" + acct_id, json[domain + "_home"]); localStorage.setItem('home_' + acct_id, json[domain + '_home'])
} }
if (json[domain + "_local"]) { if (json[domain + '_local']) {
localStorage.setItem("local_" + acct_id, json[domain + "_local"]); localStorage.setItem('local_' + acct_id, json[domain + '_local'])
} }
if (json[domain + "_public"]) { if (json[domain + '_public']) {
localStorage.setItem("public_" + acct_id, json[domain + "_public"]); localStorage.setItem('public_' + acct_id, json[domain + '_public'])
} }
if (json[domain + "_notification"]) { if (json[domain + '_notification']) {
localStorage.setItem("notification_" + acct_id, json[domain + "_notification"]); localStorage.setItem('notification_' + acct_id, json[domain + '_notification'])
} }
if (json[domain + "_post"]) { if (json[domain + '_post']) {
localStorage.setItem("post_" + acct_id, json[domain + "_post"]); localStorage.setItem('post_' + acct_id, json[domain + '_post'])
} }
if (json[domain + "_fav"]) { if (json[domain + '_fav']) {
localStorage.setItem("fav_" + acct_id, json[domain + "_fav"]); localStorage.setItem('fav_' + acct_id, json[domain + '_fav'])
} }
if (json[domain + "_bt"]) { if (json[domain + '_bt']) {
localStorage.setItem("bt_" + acct_id, json[domain + "_bt"]); localStorage.setItem('bt_' + acct_id, json[domain + '_bt'])
} }
if (json[domain + "_follow"]) { if (json[domain + '_follow']) {
localStorage.setItem("followlocale_" + acct_id, json[domain + "_follow"]); localStorage.setItem('followlocale_' + acct_id, json[domain + '_follow'])
} }
} }
if (localStorage.getItem("mode_" + domain) != "misskey") { if (localStorage.getItem('mode_' + domain) != 'misskey') {
var start = "https://" + domain + "/api/v1/instance"; var start = 'https://' + domain + '/api/v1/instance'
fetch(start, { fetch(start, {
method: "GET", method: 'GET',
headers: { headers: {
"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
} }
if (json) { if (json) {
if (json["max_toot_chars"]) { if (json['max_toot_chars']) {
localStorage.setItem("letters_" + acct_id, json["max_toot_chars"]); localStorage.setItem('letters_' + acct_id, json['max_toot_chars'])
} }
if (json["urls"]["streaming_api"]) { if (json['urls']['streaming_api']) {
localStorage.setItem("streaming_" + acct_id, json["urls"]["streaming_api"]); localStorage.setItem('streaming_' + acct_id, json['urls']['streaming_api'])
} else { } else {
localStorage.removeItem("streaming_" + acct_id); localStorage.removeItem('streaming_' + acct_id)
} }
} }
}); })
} else { } else {
} }
} }
//アカウントを選択…を実装 //アカウントを選択…を実装
function multiSelector(parseC) { function multiSelector(parseC) {
var multi = localStorage.getItem("multi"); var multi = localStorage.getItem('multi')
if (!multi) { if (!multi) {
var obj = []; var obj = []
var json = JSON.stringify(obj); var json = JSON.stringify(obj)
localStorage.setItem("multi", json); localStorage.setItem('multi', json)
} else { } else {
var obj = JSON.parse(multi); var obj = JSON.parse(multi)
} }
var templete; var templete
if (localStorage.getItem("mainuse") == "main") { if (localStorage.getItem('mainuse') == 'main') {
var last = localStorage.getItem("main"); var last = localStorage.getItem('main')
} else if (localStorage.getItem("last-use")) { } else if (localStorage.getItem('last-use')) {
var last = localStorage.getItem("last-use"); var last = localStorage.getItem('last-use')
if (last == "webview" || last == "noauth") { if (last == 'webview' || last == 'noauth') {
last = "0"; last = '0'
} }
} else { } else {
var last = "0"; var last = '0'
} }
last = last + ""; last = last + ''
var sel; var sel
if (obj.length < 1) { if (obj.length < 1) {
$("#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) {
sel = "selected"; sel = 'selected'
var domain = acct.domain; var domain = acct.domain
localStorage.setItem("domain_" + key, domain); localStorage.setItem('domain_' + key, domain)
if (idata[domain + "_letters"]) { if (idata[domain + '_letters']) {
$("#textarea").attr("data-length", idata[domain + "_letters"]); $('#textarea').attr('data-length', idata[domain + '_letters'])
} else { } else {
var maxletters = localStorage.getItem("letters_" + key); var maxletters = localStorage.getItem('letters_' + key)
if (maxletters > 0) { if (maxletters > 0) {
$("#textarea").attr("data-length", maxletters); $('#textarea').attr('data-length', maxletters)
} else { } else {
$("#textarea").attr("data-length", 500); $('#textarea').attr('data-length', 500)
} }
} }
if (idata[domain + "_glitch"]) { if (idata[domain + '_glitch']) {
$("#local-button").removeClass("hide"); $('#local-button').removeClass('hide')
} }
var profimg = acct.prof; var profimg = acct.prof
//localStorage.setItem("prof_" + key, profimg); //localStorage.setItem("prof_" + key, profimg);
if (!profimg) { if (!profimg) {
profimg = "../../img/missing.svg"; profimg = '../../img/missing.svg'
} }
$("#acct-sel-prof").attr("src", profimg); $('#acct-sel-prof').attr('src', profimg)
if (domain) { if (domain) {
var cc = "(" + domain + ")"; var cc = '(' + domain + ')'
} else { } else {
var cc = ""; var cc = ''
} }
$("#toot-post-btn").text(lang.lang_toot + cc); $('#toot-post-btn').text(lang.lang_toot + cc)
if (acct.background && acct.background != "def" && acct.text && acct.text != "def") { if (acct.background && acct.background != 'def' && acct.text && acct.text != 'def') {
$("#toot-post-btn").removeClass("indigo"); $('#toot-post-btn').removeClass('indigo')
$("#toot-post-btn").css("background-color", "#" + acct.background); $('#toot-post-btn').css('background-color', '#' + acct.background)
$("#toot-post-btn").css("color", acct.text); $('#toot-post-btn').css('color', acct.text)
} else { } else {
} }
if (domain == "kirishima.cloud") { if (domain == 'kirishima.cloud') {
$("#faicon-btn").show(); $('#faicon-btn').show()
} else { } else {
$("#faicon-btn").hide(); $('#faicon-btn').hide()
} }
if (domain == "imastodon.net") { if (domain == 'imastodon.net') {
trendTag(); trendTag()
} else { } else {
$("#trendtag").html(""); $('#trendtag').html('')
} }
} else { } else {
sel = ""; sel = ''
} }
templete = '<option value="' + key + '" data-icon="' + acct.prof + '" class="left circle" ' + sel + ">" + acct.user + "@" + acct.domain + "</option>"; templete =
$(".acct-sel").append(templete); '<option value="' +
}); key +
$("#src-acct-sel").append('<option value="tootsearch">Tootsearch</option>'); '" data-icon="' +
$("#add-acct-sel").append('<option value="noauth">' + lang.lang_login_noauth + '</option><option value="webview">Twitter</option>'); acct.prof +
$("#dir-acct-sel").append('<option value="noauth">' + lang.lang_login_noauth + "</option>"); '" class="left circle" ' +
sel +
'>' +
acct.user +
'@' +
acct.domain +
'</option>'
$('.acct-sel').append(templete)
})
$('#src-acct-sel').append('<option value="tootsearch">Tootsearch</option>')
$('#add-acct-sel').append(
'<option value="noauth">' +
lang.lang_login_noauth +
'</option><option value="webview">Twitter</option>'
)
$('#dir-acct-sel').append('<option value="noauth">' + lang.lang_login_noauth + '</option>')
} }
$("select").formSelect(); $('select').formSelect()
if (!parseC) { if (!parseC) {
parseColumn(null, true); parseColumn(null, true)
} }
} }
//バージョンエンコ //バージョンエンコ
function enc(ver) { function enc(ver) {
var ver = ver.replace(/\s/g, ""); var ver = ver.replace(/\s/g, '')
var ver = ver.replace(/\(/g, "-"); var ver = ver.replace(/\(/g, '-')
var ver = ver.replace(/\)/g, ""); var ver = ver.replace(/\)/g, '')
var ver = ver.replace(/\[/g, "_"); var ver = ver.replace(/\[/g, '_')
var ver = ver.replace(/\]/g, ""); var ver = ver.replace(/\]/g, '')
return ver; return ver
} }
//インスタンスティッカー //インスタンスティッカー
function ticker() { function ticker() {
var start = "https://toot.app/toot/"; var start = 'https://toot.app/toot/'
fetch(start, { fetch(start, {
method: "GET", method: 'GET',
headers: { headers: {
"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

@ -862,6 +862,12 @@ function refresh(target) {
id: json['id'], id: json['id'],
vis: json['source']['privacy'] 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('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'])