From 4943b3ad20e93b577726f88d64818713eb234f50 Mon Sep 17 00:00:00 2001 From: cutls Date: Tue, 22 Oct 2019 14:34:23 +0900 Subject: [PATCH] Add: login by access-token --- app/js/login/manager.js | 903 ++++++++++++++-------------- app/view/make/acct.sample.html | 8 +- app/view/make/language/en/acct.json | 3 +- app/view/make/language/en/main.json | 2 +- app/view/make/language/ja/acct.json | 3 +- app/view/make/language/ja/main.json | 2 +- 6 files changed, 467 insertions(+), 454 deletions(-) diff --git a/app/js/login/manager.js b/app/js/login/manager.js index b53855bf..414b4f1f 100644 --- a/app/js/login/manager.js +++ b/app/js/login/manager.js @@ -7,7 +7,7 @@ function load() { var mode = m[1]; var codex = m[2]; if (mode == "first" && codex == "true") { - $("body").addClass("first") + $("body").addClass("first"); } else { } } @@ -34,31 +34,22 @@ function load() { console.table(obj); var templete; - Object.keys(obj).forEach(function (key) { + Object.keys(obj).forEach(function(key) { var acct = obj[key]; var list = key * 1 + 1; if (acct.background != "def" && acct.text != "def") { - var style = 'style="background-color:#' + acct.background + '; color:' + acct.text + ';"' + var style = 'style="background-color:#' + acct.background + "; color:" + acct.text + ';"'; } else { - var style = "" + var style = ""; } if (acct.name) { var name = acct.name; } else { var name = acct.user; } - templete = '
' + list + - '.' + - name + '' + escapeHTML(acct.user) + '@' + acct.domain + - '
'; + templete = '
' + list + '.' + name + "" + escapeHTML(acct.user) + "@" + acct.domain + '
'; $("#acct-list").append(templete); - colorpicker(key) + colorpicker(key); }); multisel(); var acctN = localStorage.getItem("acct"); @@ -68,7 +59,6 @@ function load() { } //全部チェックアリでいいと思うの $("#linux").prop("checked", true); - } //最初に読む load(); @@ -85,60 +75,66 @@ function data(domain) { $("#ins-user").text("Loading..."); $("#ins-ver").text("Loading..."); $("#ins-name").text("Loading..."); - $("#ins-prof").attr('src', "../../img/loading.svg"); + $("#ins-prof").attr("src", "../../img/loading.svg"); var start = "https://instances.social/api/1.0/instances/show?name=" + domain; fetch(start, { - method: 'GET', + method: "GET", headers: { - 'content-type': 'application/json', - 'Authorization': 'Bearer tC8F6xWGWBUwGScyNevYlx62iO6fdQ4oIK0ad68Oo7ZKB8GQdGpjW9TKxBnIh8grAhvd5rw3iyP9JPamoDpeLQdz62EToPJUW99hDx8rfuJfGdjQuimZPTbIOx0woA5M' - }, - }).then(function (response) { - return response.json(); - }).catch(function (error) { - todo(error); - console.error(error); - }).then(function (json) { - if (!json.error) { - $("#ins-name").text(json.name); - $("#ins-upd").text(date(json.checked_at, 'full')); - $("#ins-add").text(date(json.added_at, 'full')); - $("#ins-connect").text(json.connections); - $("#ins-toot").text(json.statuses); - $("#ins-sys").text(date(json.updated_at, 'full')); - $("#ins-per").text(json.uptime * 100); - $("#ins-user").text(json.users); - $("#ins-ver").text(json.version); - } else { - console.error(json.error); + "content-type": "application/json", + Authorization: "Bearer tC8F6xWGWBUwGScyNevYlx62iO6fdQ4oIK0ad68Oo7ZKB8GQdGpjW9TKxBnIh8grAhvd5rw3iyP9JPamoDpeLQdz62EToPJUW99hDx8rfuJfGdjQuimZPTbIOx0woA5M" } - }); + }) + .then(function(response) { + return response.json(); + }) + .catch(function(error) { + todo(error); + console.error(error); + }) + .then(function(json) { + if (!json.error) { + $("#ins-name").text(json.name); + $("#ins-upd").text(date(json.checked_at, "full")); + $("#ins-add").text(date(json.added_at, "full")); + $("#ins-connect").text(json.connections); + $("#ins-toot").text(json.statuses); + $("#ins-sys").text(date(json.updated_at, "full")); + $("#ins-per").text(json.uptime * 100); + $("#ins-user").text(json.users); + $("#ins-ver").text(json.version); + } else { + console.error(json.error); + } + }); var start = "https://" + domain + "/api/v1/instance"; fetch(start, { - method: 'GET', + method: "GET", headers: { - 'content-type': 'application/json', - }, - }).then(function (response) { - return response.json(); - }).catch(function (error) { - todo(error); - console.error(error); - }).then(function (json) { - if (!json.error) { - $("#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); - } else { - console.error(json.error); + "content-type": "application/json" } - }); + }) + .then(function(response) { + return response.json(); + }) + .catch(function(error) { + todo(error); + console.error(error); + }) + .then(function(json) { + if (!json.error) { + $("#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); + } else { + console.error(json.error); + } + }); } //アカウントデータ 消す @@ -149,15 +145,15 @@ function multiDel(target) { Swal.fire({ title: lang.lang_manager_logout, text: obj[target]["user"] + "@" + obj[target]["domain"] + lang.lang_manager_confirm, - type: 'warning', + type: "warning", showCancelButton: true, - confirmButtonColor: '#3085d6', - cancelButtonColor: '#d33', + confirmButtonColor: "#3085d6", + cancelButtonColor: "#d33", confirmButtonText: lang.lang_yesno, cancelButtonText: lang.lang_no - }).then((result) => { + }).then(result => { if (result.value) { - Object.keys(obj).forEach(function (key) { + Object.keys(obj).forEach(function(key) { var nk = key - 1; //公開範囲(差分のみ) if (key >= target) { @@ -182,7 +178,6 @@ function multiDel(target) { localStorage.setItem("user-id_" + target, localStorage.getItem("user-id_" + key)); localStorage.setItem("prof_" + target, localStorage.getItem("prof_" + key)); } - }); //とりあえず消す obj.splice(target, 1); @@ -193,7 +188,7 @@ function multiDel(target) { var col = localStorage.getItem("column"); var oldcols = JSON.parse(col); var newcols = []; - Object.keys(oldcols).forEach(function (key) { + Object.keys(oldcols).forEach(function(key) { var nk = key - 1; var oldcol = oldcols[key]; if (target < oldcol.domain) { @@ -213,9 +208,8 @@ function multiDel(target) { }); var json = JSON.stringify(newcols); localStorage.setItem("column", json); - } - }) + }); } function multiDel2(target) { var multi = localStorage.getItem("multi"); @@ -223,18 +217,18 @@ function multiDel2(target) { Swal.fire({ title: lang.lang_manager_logout, text: obj[target]["user"] + "@" + obj[target]["domain"] + lang.lang_manager_confirm, - type: 'warning', + type: "warning", showCancelButton: true, - confirmButtonColor: '#3085d6', - cancelButtonColor: '#d33', + confirmButtonColor: "#3085d6", + cancelButtonColor: "#d33", confirmButtonText: lang.lang_yesno, cancelButtonText: lang.lang_no - }).then((result) => { + }).then(result => { if (result.value) { obj.splice(target, 1); var json = JSON.stringify(obj); localStorage.setItem("multi", json); - Object.keys(obj).forEach(function (key) { + Object.keys(obj).forEach(function(key) { if (key >= target) { var oldvis = localStorage.getItem("vis-memory-" + key); if (oldvis) { @@ -250,17 +244,19 @@ function multiDel2(target) { }); var col = localStorage.getItem("column"); if (!col) { - var obj = [{ - domain: 0, - type: 'local' - }]; + 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) { + Object.keys(cobj).forEach(function(key) { var column = cobj[key]; if (column.domain > target) { var nk = key - 1; @@ -275,16 +271,15 @@ function multiDel2(target) { localStorage.setItem("column", json); load(); } - }) + }); } //サポートインスタンス function support() { - Object.keys(idata).forEach(function (key) { + Object.keys(idata).forEach(function(key) { var instance = idata[key]; if (instance == "instance") { - templete = '' + idata[key + "_name"] + '(' + key + ')'; + templete = "' + idata[key + "_name"] + "(" + key + ")"; $("#support").append(templete); } }); @@ -294,207 +289,173 @@ function support() { function login(url) { var multi = localStorage.getItem("multi"); var obj = JSON.parse(multi); - if ($('#misskey:checked').val() == "on") { + if ($("#misskey:checked").val() == "on") { $("#misskey").prop("checked", true); misskeyLogin(url); return; } - $("#compt").hide() - if ($('#linux:checked').val() == "on") { - var red = "urn:ietf:wg:oauth:2.0:oob" - if(~url.indexOf("pixelfed")){ - red = "https://thedesk.top/hello.html" + $("#compt").hide(); + if ($("#linux:checked").val() == "on") { + var red = "urn:ietf:wg:oauth:2.0:oob"; + if (~url.indexOf("pixelfed")) { + red = "https://thedesk.top/hello.html"; } } else { - var red = 'thedesk://manager'; + var red = "thedesk://manager"; } localStorage.setItem("redirect", red); var start = "https://" + url + "/api/v1/apps"; var httpreq = new XMLHttpRequest(); - httpreq.open('POST', start, true); - httpreq.setRequestHeader('Content-Type', 'application/json'); + httpreq.open("POST", start, true); + httpreq.setRequestHeader("Content-Type", "application/json"); httpreq.responseType = "json"; - httpreq.send(JSON.stringify({ - scopes: 'read write follow', - client_name: "TheDesk(PC)", - redirect_uris: red, - website: "https://thedesk.top" - })); - httpreq.onreadystatechange = function () { + httpreq.send( + JSON.stringify({ + scopes: "read write follow", + client_name: "TheDesk(PC)", + redirect_uris: red, + website: "https://thedesk.top" + }) + ); + httpreq.onreadystatechange = function() { if (httpreq.readyState === 4) { var json = httpreq.response; 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); + 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("client_id", json["client_id"]); localStorage.setItem("client_secret", json["client_secret"]); $("#auth").show(); - versionChecker(url) + versionChecker(url); $("#add").hide(); - postMessage(["openUrl", auth], "*") - if ($('#linux:checked').val() == "on") { } else { - postMessage(["sendSinmpleIpc", "quit"], "*") + postMessage(["openUrl", auth], "*"); + if ($("#linux:checked").val() == "on") { + } else { + postMessage(["sendSinmpleIpc", "quit"], "*"); } } - } + }; } function versionChecker(url) { var start = "https://" + url + "/api/v1/instance"; fetch(start, { - method: 'GET', + method: "GET", headers: { - 'content-type': 'application/json', - }, - }).then(function (response) { - return response.json(); - }).catch(function (error) { - todo(error); - console.error(error); - }).then(function (json) { - var version = json.version - if (version) { - var reg = version.match(/^([0-9])\.[0-9]\.[0-9]/u); - if (reg) { - versionCompat(reg[1], reg, json.title, reg[0]) - } + "content-type": "application/json" } - }); -} -function versionCompat(prefix, ver, title, real) { - $("#compt-instance").text(title) - $("#compt-ver").text(real) - if(~real.indexOf("compatible")){ - $("#compt-warn").show() - }else{ - $("#compt-warn").hide() - } - $("#compt-list").html("") - var start = "../../source/version.json"; - fetch(start, { - method: 'GET', - headers: { - 'content-type': 'application/json', - }, - }).then(function (response) { - return response.json(); - }).catch(function (error) { - todo(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) { - jl++ - if (key != real && !complete) { - for (var i = 0; i < data.length; i++) { - var e = "" - if (i == 0) { - e = "(" + key + ")" - } - $("#compt-list").append('
  • ' + data[i] + e + '
  • ') - ct++; - e = "" - } - jl2++ - } else if (!complete) { - complete = true + }) + .then(function(response) { + return response.json(); + }) + .catch(function(error) { + todo(error); + console.error(error); + }) + .then(function(json) { + var version = json.version; + if (version) { + var reg = version.match(/^([0-9])\.[0-9]\.[0-9]/u); + if (reg) { + versionCompat(reg[1], reg, json.title, reg[0]); } } }); - if(lang.language == "ja" && ct > 0){ - if (jl2!=jl && prefix!="1") { - $("#compt").show() - } +} +function versionCompat(prefix, ver, title, real) { + $("#compt-instance").text(title); + $("#compt-ver").text(real); + if (~real.indexOf("compatible")) { + $("#compt-warn").show(); + } else { + $("#compt-warn").hide(); + } + $("#compt-list").html(""); + var start = "../../source/version.json"; + fetch(start, { + method: "GET", + headers: { + "content-type": "application/json" } - }); - + }) + .then(function(response) { + return response.json(); + }) + .catch(function(error) { + todo(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) { + jl++; + if (key != real && !complete) { + for (var i = 0; i < data.length; i++) { + var e = ""; + if (i == 0) { + e = "(" + key + ")"; + } + $("#compt-list").append("
  • " + data[i] + e + "
  • "); + ct++; + e = ""; + } + jl2++; + } else if (!complete) { + complete = true; + } + } + }); + if (lang.language == "ja" && ct > 0) { + if (jl2 != jl && prefix != "1") { + $("#compt").show(); + } + } + }); } //これが後のMisskeyである。 function misskeyLogin(url) { if (!url) { var url = $("#misskey-url").val(); } - var start = "https://" + url + "/api/app/create"; + var start = "http://" + url + "/api/app/create"; var httpreq = new XMLHttpRequest(); - httpreq.open('POST', start, true); - httpreq.setRequestHeader('Content-Type', 'application/json'); + httpreq.open("POST", start, true); + httpreq.setRequestHeader("Content-Type", "application/json"); httpreq.responseType = "json"; localStorage.setItem("msky", "true"); - httpreq.send(JSON.stringify({ - name: "TheDesk(PC)", - description: "Mastodon client for PC", - permission: [ - "account-read", - "account-write", - "account/read", - "account/write", - "drive-read", - "drive-write", - "favorite-read", - "favorite-write", - "favorites-read", - "following-read", - "following-write", - "messaging-read", - "messaging-write", - "note-read", - "note-write", - "notification-read", - "notification-write", - "reaction-read", - "reaction-write", - "vote-read", - "vote-write", - "read:account", - "write:account", - "read:drive", - "write:drive", - "read:blocks", - "write:blocks", - "read:favorites", - "write:favorites", - "read:following", - "write:following", - "read:messaging", - "write:messaging", - "read:mutes", - "write:mutes", - "write:notes", - "read:notifications", - "write:notifications", - "read:reactions", - "write:reactions", - "write:votes" - ] - })); - httpreq.onreadystatechange = function () { + httpreq.send( + JSON.stringify({ + name: "TheDesk(PC)", + description: "Mastodon and Misskey client for PC", + permission: ["account-read", "account-write", "account/read", "account/write", "drive-read", "drive-write", "favorite-read", "favorite-write", "favorites-read", "following-read", "following-write", "messaging-read", "messaging-write", "note-read", "note-write", "notification-read", "notification-write", "reaction-read", "reaction-write", "vote-read", "vote-write", "read:account", "write:account", "read:drive", "write:drive", "read:blocks", "write:blocks", "read:favorites", "write:favorites", "read:following", "write:following", "read:messaging", "write:messaging", "read:mutes", "write:mutes", "write:notes", "read:notifications", "write:notifications", "read:reactions", "write:reactions", "write:votes"] + }) + ); + httpreq.onreadystatechange = function() { if (httpreq.readyState === 4) { var json = httpreq.response; - misskeyAuth(url, json.secret) + misskeyAuth(url, json.secret); } - } - - + }; } function misskeyAuth(url, mkc) { var start = "https://" + url + "/api/auth/session/generate"; var httpreq = new XMLHttpRequest(); - httpreq.open('POST', start, true); - httpreq.setRequestHeader('Content-Type', 'application/json'); + httpreq.open("POST", start, true); + httpreq.setRequestHeader("Content-Type", "application/json"); httpreq.responseType = "json"; - localStorage.setItem("mkc", mkc) + localStorage.setItem("mkc", mkc); localStorage.setItem("msky", "true"); - httpreq.send(JSON.stringify({ - appSecret: mkc - })); - httpreq.onreadystatechange = function () { + httpreq.send( + JSON.stringify({ + appSecret: mkc + }) + ); + httpreq.onreadystatechange = function() { if (httpreq.readyState === 4) { var json = httpreq.response; var token = json.token; @@ -503,16 +464,16 @@ function misskeyAuth(url, mkc) { $("#add").hide(); $("#misskey").prop("checked", false); localStorage.setItem("domain_tmp", url); - postMessage(["openUrl", json.url], "*") + postMessage(["openUrl", json.url], "*"); } - } + }; } //テキストボックスにURL入れた function instance() { var url = $("#url").val(); if (url.indexOf("@") != -1 || url.indexOf("https") != -1) { - alert("入力形式が違います。(Cutls@mstdn.jpにログインする場合、入力するのは\"mstdn.jp\"です。)") + alert('入力形式が違います。(Cutls@mstdn.jpにログインする場合、入力するのは"mstdn.jp"です。)'); return false; } login(url); @@ -520,24 +481,30 @@ function instance() { //コード入れてAccessTokenゲット function code(code) { - localStorage.removeItem("redirect") + localStorage.removeItem("redirect"); if (!code) { var code = $("#code").val(); $("#code").val(""); } + if(!code || code==""){ + M.toast({ html: lang.lang_fatalerroroccured + "Error: no code", displayLength: 5000 }); + return false + } var url = localStorage.getItem("domain_tmp"); localStorage.removeItem("domain_tmp"); if (localStorage.getItem("msky") == "true") { var start = "https://" + url + "/api/auth/session/userkey"; var httpreq = new XMLHttpRequest(); - httpreq.open('POST', start, true); - httpreq.setRequestHeader('Content-Type', 'application/json'); + httpreq.open("POST", start, true); + httpreq.setRequestHeader("Content-Type", "application/json"); httpreq.responseType = "json"; - httpreq.send(JSON.stringify({ - token: code, - appSecret: localStorage.getItem("mkc") - })); - httpreq.onreadystatechange = function () { + httpreq.send( + JSON.stringify({ + token: code, + appSecret: localStorage.getItem("mkc") + }) + ); + httpreq.onreadystatechange = function() { if (httpreq.readyState === 4) { var json = httpreq.response; var i = sha256(json.accessToken + localStorage.getItem("mkc")); @@ -553,10 +520,10 @@ function code(code) { vis: priv, mode: "misskey" }; - localStorage.setItem("mode_" + url, "misskey") + localStorage.setItem("mode_" + url, "misskey"); var multi = localStorage.getItem("multi"); var obj = JSON.parse(multi); - var target = obj.lengtth; + var target = obj.length; obj.push(add); localStorage.setItem("name_" + target, json["user"]["name"]); localStorage.setItem("user_" + target, json["user"]["username"]); @@ -565,33 +532,35 @@ function code(code) { var json = JSON.stringify(obj); localStorage.setItem("multi", json); if ($("body").hasClass("first")) { - location.href = "index.html" + location.href = "index.html"; } load(); return; } - } + }; return; } else { - var red = "urn:ietf:wg:oauth:2.0:oob" - if(~url.indexOf("pixelfed")){ - red = "https://thedesk.top/hello.html" + var red = "urn:ietf:wg:oauth:2.0:oob"; + if (~url.indexOf("pixelfed")) { + red = "https://thedesk.top/hello.html"; } var start = "https://" + url + "/oauth/token"; var id = localStorage.getItem("client_id"); var secret = localStorage.getItem("client_secret"); var httpreq = new XMLHttpRequest(); - httpreq.open('POST', start, true); - httpreq.setRequestHeader('Content-Type', 'application/json'); + httpreq.open("POST", start, true); + httpreq.setRequestHeader("Content-Type", "application/json"); httpreq.responseType = "json"; - httpreq.send(JSON.stringify({ - grant_type: "authorization_code", - redirect_uri: red, - client_id: id, - client_secret: secret, - code: code - })); - httpreq.onreadystatechange = function () { + httpreq.send( + JSON.stringify({ + grant_type: "authorization_code", + redirect_uri: red, + client_id: id, + client_secret: secret, + code: code + }) + ); + httpreq.onreadystatechange = function() { if (httpreq.readyState === 4) { var json = httpreq.response; if (json["access_token"]) { @@ -600,139 +569,193 @@ function code(code) { getdata(url, json["access_token"]); } } - } + }; } - } //ユーザーデータ取得 function getdata(domain, at) { var start = "https://" + domain + "/api/v1/accounts/verify_credentials"; fetch(start, { - method: 'GET', + method: "GET", headers: { - 'content-type': 'application/json', - 'Authorization': 'Bearer ' + at - }, - }).then(function (response) { - return response.json(); - }).catch(function (error) { - todo(error); - console.error(error); - }).then(function (json) { - if (json.error) { - console.error("Error:" + json.error); - M.toast({ html: lang.lang_fatalerroroccured + "Error:" + json.error, displayLength: 5000 }) - return; - } - var avatar = json["avatar"]; - //missingがmissingなやつ - if (avatar == "/avatars/original/missing.png") { - avatar = "../../img/missing.svg"; - } - if (json["source"]) { - var priv = json["source"]["privacy"]; - } else { - var priv = "public"; + "content-type": "application/json", + Authorization: "Bearer " + at } + }) + .then(function(response) { + return response.json(); + }) + .catch(function(error) { + todo(error); + console.error(error); + }) + .then(function(json) { + if (json.error) { + console.error("Error:" + json.error); + M.toast({ html: lang.lang_fatalerroroccured + "Error:" + json.error, displayLength: 5000 }); + return; + } + var avatar = json["avatar"]; + //missingがmissingなやつ + if (avatar == "/avatars/original/missing.png") { + avatar = "../../img/missing.svg"; + } + if (json["source"]) { + var priv = json["source"]["privacy"]; + } else { + var priv = "public"; + } + var add = { + at: at, + name: json["display_name"], + domain: domain, + user: json["acct"], + prof: avatar, + id: json["id"], + vis: priv, + mode: "mastodon" + }; + var multi = localStorage.getItem("multi"); + var obj = JSON.parse(multi); + var target = obj.length; + obj.push(add); + localStorage.setItem("name_" + target, json["display_name"]); + localStorage.setItem("user_" + target, json["acct"]); + localStorage.setItem("user-id_" + target, json["id"]); + localStorage.setItem("prof_" + target, avatar); + var json = JSON.stringify(obj); + localStorage.setItem("multi", json); + if ($("body").hasClass("first")) { + location.href = "index.html"; + } + load(); + }); +} +//アクセストークン直接入力 +function atSetup(type) { + var url = localStorage.getItem("domain_tmp"); + localStorage.removeItem("domain_tmp"); + var multi = localStorage.getItem("multi"); + var avatar = "../../img/missing.svg"; + var priv = "public"; + if (type == "misskey") { + var i = $("#misskey-key").val(); var add = { - at: at, - name: json["display_name"], - domain: domain, - user: json["acct"], + at: i, + name: "Pseudo Account", + domain: url, + user: "user+pseudo", prof: avatar, - id: json["id"], + id: "id+pseudo", vis: priv, - mode: "mastodon" + mode: "misskey" }; - var multi = localStorage.getItem("multi"); - var obj = JSON.parse(multi); - var target = obj.lengtth; - obj.push(add); - localStorage.setItem("name_" + target, json["display_name"]); - localStorage.setItem("user_" + target, json["acct"]); - localStorage.setItem("user-id_" + target, json["id"]); - localStorage.setItem("prof_" + target, avatar); - var json = JSON.stringify(obj); - localStorage.setItem("multi", json); - if ($("body").hasClass("first")) { - location.href = "index.html" - } - load(); - }); + localStorage.setItem("mode_" + url, "misskey"); + } else { + var i = $("#code").val(); + var add = { + at: i, + name: "Pseudo Account", + domain: url, + user: "user+pseudo", + prof: avatar, + id: "id+pseudo", + vis: priv, + mode: "" + }; + } + if(!i || i==""){ + M.toast({ html: lang.lang_fatalerroroccured + "Error: access token", displayLength: 5000 }); + return false + } + var obj = JSON.parse(multi); + var target = obj.length; + obj.push(add); + localStorage.setItem("name_" + target, add["name"]); + 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); + refresh(target); } //ユーザーデータ更新 function refresh(target) { var multi = localStorage.getItem("multi"); var obj = JSON.parse(multi); + console.log(obj) if (obj[target].mode == "misskey") { misskeyRefresh(obj, target, obj[target].domain); - 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, { - method: 'GET', + method: "GET", headers: { - 'content-type': 'application/json', - 'Authorization': 'Bearer ' + obj[target].at - }, - }).then(function (response) { - return response.json(); - }).catch(function (error) { - todo(error); - console.error(error); - }).then(function (json) { - if (json.error) { - console.error("Error:" + json.error); - M.toast({ html: lang.lang_fatalerroroccured + "Error:" + json.error, displayLength: 5000 }) - return; + "content-type": "application/json", + Authorization: "Bearer " + obj[target].at } - var avatar = json["avatar"]; - //missingがmissingなやつ - if (avatar == "/avatars/original/missing.png" || !avatar) { - avatar = "./img/missing.svg"; - } - var ref = { - at: obj[target].at, - name: json["display_name"], - domain: obj[target].domain, - user: json["acct"], - prof: avatar, - id: json["id"], - vis: json["source"]["privacy"] - }; - 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); - if(json["source"]["sensitive"]){ - localStorage.setItem("nsfw_" + target, "true"); - }else{ - localStorage.removeItem("nsfw_" + target); - } - obj[target] = ref; - var json = JSON.stringify(obj); - localStorage.setItem("multi", json); + }) + .then(function(response) { + return response.json(); + }) + .catch(function(error) { + todo(error); + console.error(error); + }) + .then(function(json) { + if (json.error) { + console.error("Error:" + json.error); + M.toast({ html: lang.lang_fatalerroroccured + "Error:" + json.error, displayLength: 5000 }); + return; + } + var avatar = json["avatar"]; + //missingがmissingなやつ + if (avatar == "/avatars/original/missing.png" || !avatar) { + avatar = "./img/missing.svg"; + } + var ref = { + at: obj[target].at, + name: json["display_name"], + domain: obj[target].domain, + user: json["acct"], + prof: avatar, + id: json["id"], + vis: json["source"]["privacy"] + }; + 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); + if (json["source"]["sensitive"]) { + localStorage.setItem("nsfw_" + target, "true"); + } else { + localStorage.removeItem("nsfw_" + target); + } + obj[target] = ref; + var json = JSON.stringify(obj); + localStorage.setItem("multi", json); - load(); - }); + load(); + }); } function misskeyRefresh(obj, target, url) { var start = "https://" + url + "/api/users/show"; var httpreq = new XMLHttpRequest(); - httpreq.open('POST', start, true); - httpreq.setRequestHeader('Content-Type', 'application/json'); + httpreq.open("POST", start, true); + httpreq.setRequestHeader("Content-Type", "application/json"); httpreq.responseType = "json"; - httpreq.send(JSON.stringify({ - username: obj[target].user, - i: localStorage.getItem("at") - })); - httpreq.onreadystatechange = function () { + httpreq.send( + JSON.stringify({ + username: obj[target].user, + i: obj[target].at + }) + ); + httpreq.onreadystatechange = function() { if (httpreq.readyState === 4) { var json = httpreq.response; - return; - var avatar = json["user"]["avatarURL"]; + var avatar = json["user"]["avatarUrl"]; var priv = "public"; var add = { at: json.accessToken, @@ -745,7 +768,7 @@ function misskeyRefresh(obj, target, url) { }; var multi = localStorage.getItem("multi"); var obj = JSON.parse(multi); - var target = obj.lengtth; + var target = obj.length; obj.push(add); localStorage.setItem("name_" + target, json["user"]["name"]); localStorage.setItem("user_" + target, json["user"]["username"]); @@ -756,7 +779,7 @@ function misskeyRefresh(obj, target, url) { load(); return; } - } + }; } //アカウントを選択…を実装 function multisel() { @@ -773,14 +796,14 @@ function multisel() { var sel; if (obj.length < 1) { $("#src-acct-sel").html(''); - $("#add-acct-sel").html(''); + $("#add-acct-sel").html('"); } else { - Object.keys(obj).forEach(function (key) { + Object.keys(obj).forEach(function(key) { var acct = obj[key]; var list = key * 1 + 1; if (key == last) { sel = "selected"; - mainb = '(' + lang.lang_manager_def + ')' + mainb = "(" + lang.lang_manager_def + ")"; var domain = localStorage.getItem("domain_" + key); var profimg = localStorage.getItem("prof_" + key); var domain = localStorage.getItem("domain_" + key); @@ -789,46 +812,21 @@ function multisel() { } } else { sel = ""; - mainb = "" + mainb = ""; } - templete = ''; + templete = '"; $(".acct-sel").append(templete); - }); } - $('select').formSelect(); + $("select").formSelect(); } function mainacct() { var acct_id = $("#main-acct-sel").val(); localStorage.setItem("main", acct_id); - M.toast({ html: lang.lang_manager_mainAcct, displayLength: 3000 }) + M.toast({ html: lang.lang_manager_mainAcct, displayLength: 3000 }); } function colorpicker(key) { - temp = - '
    ' + lang.lang_manager_none + '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    ' + - '
    '; + temp = '
    " + lang.lang_manager_none + "
    " + '
    " + '
    " + '
    " + '
    " + '
    " + '
    " + '
    " + '
    " + '
    " + '
    " + '
    " + '
    " + '
    " + '
    " + '
    " + '
    " + '
    " + '
    " + '
    " + '
    " + '
    "; $("#colorsel_" + key).html(temp); } function coloradd(key, bg, txt) { @@ -841,18 +839,18 @@ function coloradd(key, bg, txt) { var json = JSON.stringify(o); localStorage.setItem("multi", json); if (txt == "def") { - $("#acct_" + key).attr("style", "") + $("#acct_" + key).attr("style", ""); } else { - $("#acct_" + key).css('background-color', '#' + bg); + $("#acct_" + key).css("background-color", "#" + bg); if (txt == "black") { var bghex = "000000"; - var ichex = "9e9e9e" + var ichex = "9e9e9e"; } else if (txt == "white") { var bghex = "ffffff"; - var ichex = "eeeeee" + var ichex = "eeeeee"; } - $("#acct_" + key + " .nex").css('color', '#' + ichex); - $("#acct_" + key).css('color', '#' + bghex); + $("#acct_" + key + " .nex").css("color", "#" + ichex); + $("#acct_" + key).css("color", "#" + bghex); } } //入力時にハッシュタグと@をサジェスト @@ -863,50 +861,59 @@ var input = document.getElementById("url"); var prev_val = input.value; var oldSuggest; var suggest; -input.addEventListener("focus", function () { - $("#ins-suggest").html(""); - window.clearInterval(timer); - timer = window.setInterval(function () { - var new_val = input.value; - if (prev_val != new_val) { - if (new_val.length > 3) { - var start = "https://instances.social/api/1.0/instances/search?q=" + - new_val; - fetch(start, { - method: 'GET', - headers: { - 'content-type': 'application/json', - 'Authorization': 'Bearer tC8F6xWGWBUwGScyNevYlx62iO6fdQ4oIK0ad68Oo7ZKB8GQdGpjW9TKxBnIh8grAhvd5rw3iyP9JPamoDpeLQdz62EToPJUW99hDx8rfuJfGdjQuimZPTbIOx0woA5M' - }, - }).then(function (response) { - return response.json(); - }).catch(function (error) { - todo(error); - console.error(error); - }).then(function (json) { - if (!json.error) { - var urls = "Suggest:"; - Object.keys(json.instances).forEach(function (key) { - var url = json.instances[key]; - urls = urls + ' ' + escapeHTML(url.name) + ' '; +input.addEventListener( + "focus", + function() { + $("#ins-suggest").html(""); + window.clearInterval(timer); + timer = window.setInterval(function() { + var new_val = input.value; + if (prev_val != new_val) { + if (new_val.length > 3) { + var start = "https://instances.social/api/1.0/instances/search?q=" + new_val; + fetch(start, { + method: "GET", + headers: { + "content-type": "application/json", + Authorization: "Bearer tC8F6xWGWBUwGScyNevYlx62iO6fdQ4oIK0ad68Oo7ZKB8GQdGpjW9TKxBnIh8grAhvd5rw3iyP9JPamoDpeLQdz62EToPJUW99hDx8rfuJfGdjQuimZPTbIOx0woA5M" + } + }) + .then(function(response) { + return response.json(); + }) + .catch(function(error) { + todo(error); + console.error(error); + }) + .then(function(json) { + if (!json.error) { + var urls = "Suggest:"; + Object.keys(json.instances).forEach(function(key) { + var url = json.instances[key]; + urls = urls + " ' + escapeHTML(url.name) + " "; + }); + $("#ins-suggest").html(urls); + } else { + console.error(json.error); + } }); - $("#ins-suggest").html(urls); - } else { - console.error(json.error); - } - }); + } + oldSuggest = suggest; + prev_value = new_val; } - oldSuggest = suggest; - prev_value = new_val; - } - }, 1000); -}, false); + }, 1000); + }, + false +); -input.addEventListener("blur", function () { - window.clearInterval(timer); -}, false); +input.addEventListener( + "blur", + function() { + window.clearInterval(timer); + }, + false +); //acctで未読マーカーは要らない function asReadEnd() { - postMessage(["asReadComp", ""], "*") -} \ No newline at end of file + postMessage(["asReadComp", ""], "*"); +} diff --git a/app/view/make/acct.sample.html b/app/view/make/acct.sample.html index fe1c1ffc..5668d7f7 100644 --- a/app/view/make/acct.sample.html +++ b/app/view/make/acct.sample.html @@ -131,8 +131,10 @@
    diff --git a/app/view/make/language/en/acct.json b/app/view/make/language/en/acct.json index 28f8e8ea..c0654208 100644 --- a/app/view/make/language/en/acct.json +++ b/app/view/make/language/en/acct.json @@ -18,5 +18,6 @@ "ko":"", "thisismisskey":"Login as Misskey", "misskeylogin":"Read Docs(ja) to login Misskey.", - "nodata":"No data" + "nodata":"No data", + "accessTokenSetup": "Use access token to login(click after fill not code but access-token in box: Advanced)" } \ No newline at end of file diff --git a/app/view/make/language/en/main.json b/app/view/make/language/en/main.json index eec9cc73..3aead17b 100644 --- a/app/view/make/language/en/main.json +++ b/app/view/make/language/en/main.json @@ -9,7 +9,7 @@ "lang_edit": "Edit", "lang_del": "Delete", "lang_add": "Add", - "lang_fatalerroroccured": "Some errors are occured, please restart TheDesk.", + "lang_fatalerroroccured": "Error", "lang_speech": "Google US English", "lang_lang": "Language", "lang_langlocale": "English", diff --git a/app/view/make/language/ja/acct.json b/app/view/make/language/ja/acct.json index 91c864e0..ee49608c 100644 --- a/app/view/make/language/ja/acct.json +++ b/app/view/make/language/ja/acct.json @@ -18,5 +18,6 @@ "ko":"個", "thisismisskey":"Misskeyとしてログイン", "misskeylogin":"ドキュメントを参照して正しいコードを入れてください。", - "nodata":"アカウントがありません" + "nodata":"アカウントがありません", + "accessTokenSetup": "アクセストークンを用いたセットアップ(コードの代わりにアクセストークンを入力してクリックしてください: 上級者向け)" } \ No newline at end of file diff --git a/app/view/make/language/ja/main.json b/app/view/make/language/ja/main.json index f8f55c0c..9be7b398 100644 --- a/app/view/make/language/ja/main.json +++ b/app/view/make/language/ja/main.json @@ -9,7 +9,7 @@ "lang_edit": "編集", "lang_del": "削除", "lang_add": "追加", - "lang_fatalerroroccured": "エラーが発生しました。しばらく待ってから再起動してください。", + "lang_fatalerroroccured": "エラーが発生しました。", "lang_speech": "Google 日本語", "lang_lang": "言語", "lang_langlocale": "日本語",