2018-01-28 23:22:43 +11:00
|
|
|
/*ログイン処理・認証までのJS*/
|
|
|
|
//最初に読むやつ
|
2018-02-09 03:43:11 +11:00
|
|
|
//アスタルテ判定初期化
|
|
|
|
localStorage.removeItem("kirishima")
|
2018-02-19 04:41:25 +11:00
|
|
|
localStorage.removeItem("image");
|
2018-03-27 13:39:35 +11:00
|
|
|
var idata={
|
|
|
|
"kirishima.cloud":"instance",
|
|
|
|
"kirishima.cloud_name":"アスタルテ",
|
|
|
|
"kirishima.cloud_letters":"6229",
|
|
|
|
"kirishima.cloud_bbcode":"enabled",
|
|
|
|
"kirishima.cloud_markdown":"disabled",
|
|
|
|
"knzk.me":"instance",
|
|
|
|
"knzk.me_name":"神崎丼",
|
|
|
|
"knzk.me_letters":"5000",
|
|
|
|
"knzk.me_bbcode":"disabled",
|
|
|
|
"knzk.me_markdown":"disabled",
|
|
|
|
"mastodos.com":"instance",
|
|
|
|
"mastodos.com_name":"マストどす",
|
|
|
|
"mastodos.com_letters":"500",
|
|
|
|
"mastodos.com_bbcode":"disabled",
|
|
|
|
"mastodos.com_markdown":"disabled",
|
|
|
|
"dev.kirishima.cloud":"hidden",
|
|
|
|
"dev.kirishima.cloud_name":"アスタルテ(Dev)",
|
|
|
|
"dev.kirishima.cloud_letters":"6229",
|
|
|
|
"dev.kirishima.cloud_bbcode":"enabled",
|
|
|
|
"dev.kirishima.cloud_markdown":"disabled",
|
|
|
|
"mstdn.y-zu.org":"instance",
|
|
|
|
"mstdn.y-zu.org_name":"Yづドン!(502 BadGateway)",
|
|
|
|
"mstdn.y-zu.org_letters":"500",
|
|
|
|
"mstdn.y-zu.org_bbcode":"disabled",
|
|
|
|
"mstdn.y-zu.org_markdown":"disabled",
|
|
|
|
"imastodon.net":"instance",
|
|
|
|
"imastodon.net_name":"im@stodon",
|
|
|
|
"imastodon.net_letters":"500",
|
|
|
|
"imastodon.net_bbcode":"disabled",
|
|
|
|
"imastodon.net_markdown":"disabled",
|
|
|
|
"imastodon.net_home":"オフィス",
|
|
|
|
"imastodon.net_local":"楽屋",
|
|
|
|
"imastodon.net_notification":"ホワイトボード",
|
|
|
|
"imastodon.net_public":"ライブステージ",
|
|
|
|
"mstdn.osaka":"instance",
|
|
|
|
"mstdn.osaka_name":"大阪丼",
|
|
|
|
"mstdn.osaka_letters":"500",
|
|
|
|
"mstdn.osaka_bbcode":"disabled",
|
|
|
|
"mstdn.osaka_markdown":"disabled",
|
|
|
|
"mstdn.osaka_home":"ウチ",
|
|
|
|
"mstdn.osaka_local":"近所",
|
|
|
|
"mstdn.osaka_notification":"あめちゃん",
|
|
|
|
"mstdn.osaka_public":"新世界",
|
|
|
|
"mstdn.kemono-friends.info":"instance",
|
|
|
|
"mstdn.kemono-friends.info_name":"ますとどんちほー",
|
|
|
|
"mstdn.kemono-friends.info_letters":"1024",
|
|
|
|
"mstdn.kemono-friends.info_bbcode":"disabled",
|
|
|
|
"mstdn.kemono-friends.info_markdown":"disabled",
|
|
|
|
"mstdn.kemono-friends.info_home":"なわばり",
|
|
|
|
"mstdn.kemono-friends.info_local":"ますとどんちほー",
|
|
|
|
"mstdn.kemono-friends.info_notification":"ねえねえ!",
|
|
|
|
"mstdn.kemono-friends.info_public":"ジャパリパーク"
|
|
|
|
};
|
|
|
|
localStorage.setItem("instance", JSON.stringify(idata));
|
2018-01-28 23:22:43 +11:00
|
|
|
function ck() {
|
|
|
|
var domain = localStorage.getItem("domain_0");
|
|
|
|
var at = localStorage.getItem(domain + "_at");
|
2018-02-18 16:43:11 +11:00
|
|
|
//コード受信
|
|
|
|
if(location.search){
|
2018-02-26 02:32:10 +11:00
|
|
|
var m = location.search.match(/\?mode=([a-zA-Z-0-9]+)\&code=(.+)/);
|
2018-02-18 16:43:11 +11:00
|
|
|
var mode=m[1];
|
|
|
|
var codex=m[2];
|
|
|
|
if(mode=="manager" || mode=="login"){
|
|
|
|
code(codex,mode);
|
|
|
|
}else{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-01-28 23:22:43 +11:00
|
|
|
if (at) {
|
|
|
|
$("#tl").show();
|
|
|
|
parseColumn();
|
|
|
|
multi();
|
|
|
|
} else {
|
2018-03-27 13:39:35 +11:00
|
|
|
$("#tl").show();
|
|
|
|
multi();
|
2018-01-28 23:22:43 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ck();
|
|
|
|
//ログインポップアップ
|
|
|
|
function login(url) {
|
2018-03-11 01:22:59 +11:00
|
|
|
if($('#linux:checked').val()=="on"){
|
2018-02-26 02:32:10 +11:00
|
|
|
var red = "urn:ietf:wg:oauth:2.0:oob"
|
|
|
|
}else{
|
|
|
|
var red = 'thedesk://login';
|
|
|
|
}
|
|
|
|
localStorage.setItem("redirect", red);
|
2018-01-28 23:22:43 +11:00
|
|
|
var start = "https://" + url + "/api/v1/apps";
|
|
|
|
fetch(start, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'content-type': 'application/json'
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
scopes: 'read write follow',
|
|
|
|
client_name: "TheDesk(PC)",
|
2018-02-26 02:32:10 +11:00
|
|
|
redirect_uris: red,
|
2018-02-10 02:43:15 +11:00
|
|
|
website: "https://thedesk.top"
|
2018-01-28 23:22:43 +11:00
|
|
|
})
|
|
|
|
}).then(function(response) {
|
|
|
|
return response.json();
|
|
|
|
}).catch(function(error) {
|
|
|
|
todo(error);
|
|
|
|
console.error(error);
|
|
|
|
}).then(function(json) {
|
|
|
|
var auth = "https://" + url + "/oauth/authorize?client_id=" + json[
|
|
|
|
"client_id"] + "&client_secret=" + json["client_secret"] +
|
2018-03-11 01:22:59 +11:00
|
|
|
"&response_type=code&redirect_uri="+red+"&scope=read+write+follow";
|
2018-01-28 23:22:43 +11:00
|
|
|
localStorage.setItem("domain_" + acct_id, url);
|
|
|
|
localStorage.setItem("client_id", json["client_id"]);
|
|
|
|
localStorage.setItem("client_secret", json["client_secret"]);
|
|
|
|
$("#auth").show();
|
|
|
|
$("#masara").hide();
|
2018-01-31 03:43:01 +11:00
|
|
|
const {
|
|
|
|
shell
|
|
|
|
} = require('electron');
|
|
|
|
|
2018-02-18 16:43:11 +11:00
|
|
|
shell.openExternal(auth);
|
2018-03-11 01:22:59 +11:00
|
|
|
|
|
|
|
if($('#linux:checked').val()=="on"){
|
|
|
|
}else{
|
|
|
|
var electron = require("electron");
|
|
|
|
var ipc = electron.ipcRenderer;
|
|
|
|
ipc.send('quit', 'go');
|
|
|
|
}
|
|
|
|
|
2018-01-28 23:22:43 +11:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//テキストボックスにURL入れた
|
|
|
|
function instance() {
|
|
|
|
var url = $("#url").val();
|
|
|
|
login(url);
|
|
|
|
}
|
|
|
|
|
2018-02-18 16:43:11 +11:00
|
|
|
|
2018-01-28 23:22:43 +11:00
|
|
|
//コードを入れた後認証
|
2018-02-18 16:43:11 +11:00
|
|
|
function code(code,mode) {
|
2018-02-26 02:32:10 +11:00
|
|
|
var red = localStorage.getItem("redirect");
|
|
|
|
localStorage.removeItem("redirect")
|
2018-02-18 16:43:11 +11:00
|
|
|
if(!code){
|
|
|
|
var code = $("#code").val();
|
|
|
|
}
|
|
|
|
if(localStorage.getItem("domain_tmp")){
|
|
|
|
var url = localStorage.getItem("domain_tmp");
|
|
|
|
}else{
|
|
|
|
var url = localStorage.getItem("domain_" + acct_id);
|
|
|
|
}
|
2018-01-28 23:22:43 +11:00
|
|
|
var start = "https://" + url + "/oauth/token";
|
|
|
|
var id = localStorage.getItem("client_id");
|
|
|
|
var secret = localStorage.getItem("client_secret");
|
|
|
|
fetch(start, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'content-type': 'application/json'
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
grant_type: "authorization_code",
|
2018-02-26 02:32:10 +11:00
|
|
|
redirect_uri: red,
|
2018-01-28 23:22:43 +11:00
|
|
|
client_id: id,
|
|
|
|
client_secret: secret,
|
|
|
|
code: code
|
|
|
|
})
|
|
|
|
}).then(function(response) {
|
|
|
|
return response.json();
|
|
|
|
}).catch(function(error) {
|
|
|
|
todo(error);
|
|
|
|
console.error(error);
|
|
|
|
}).then(function(json) {
|
2018-02-18 16:43:11 +11:00
|
|
|
todo(json);
|
2018-01-28 23:22:43 +11:00
|
|
|
if (json["access_token"]) {
|
|
|
|
localStorage.setItem(url + "_at", json["access_token"]);
|
2018-02-18 16:43:11 +11:00
|
|
|
if(mode=="manager"){
|
|
|
|
getdataAdv(url, json["access_token"]);
|
|
|
|
}else{
|
|
|
|
getdata();
|
|
|
|
}
|
|
|
|
|
2018-01-28 23:22:43 +11:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-18 16:43:11 +11:00
|
|
|
//ユーザーデータ取得(最初)
|
2018-01-28 23:22:43 +11:00
|
|
|
function getdata() {
|
|
|
|
var acct_id = 0;
|
|
|
|
var domain = localStorage.getItem("domain_" + acct_id);
|
|
|
|
var at = localStorage.getItem(domain + "_at");
|
|
|
|
var start = "https://" + domain + "/api/v1/accounts/verify_credentials";
|
|
|
|
fetch(start, {
|
|
|
|
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) {
|
|
|
|
console.log(json);
|
|
|
|
if (json.error) {
|
|
|
|
console.error("Error:" + json.error);
|
|
|
|
Materialize.toast("エラーが発生しました。しばらく待ってから再起動してください。Error:" + json.error,
|
|
|
|
5000);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var obj = [{
|
|
|
|
at: at,
|
|
|
|
name: json["display_name"],
|
|
|
|
domain: domain,
|
|
|
|
user: json["acct"],
|
|
|
|
prof: json["avatar"]
|
|
|
|
}];
|
|
|
|
var json = JSON.stringify(obj);
|
|
|
|
console.log(obj);
|
|
|
|
localStorage.setItem("multi", json);
|
|
|
|
localStorage.setItem("name_" + acct_id, json["display_name"]);
|
|
|
|
localStorage.setItem("user_" + acct_id, json["acct"]);
|
|
|
|
localStorage.setItem("user-id_" + acct_id, json["id"]);
|
|
|
|
localStorage.setItem("prof_" + acct_id, json["avatar"]);
|
2018-02-18 16:43:11 +11:00
|
|
|
$("#masara").hide();
|
2018-01-28 23:22:43 +11:00
|
|
|
$("#auth").hide();
|
|
|
|
$("#tl").show();
|
|
|
|
parseColumn()
|
|
|
|
ckdb();
|
|
|
|
});
|
|
|
|
}
|
2018-02-18 16:43:11 +11:00
|
|
|
//ユーザーデータ取得(追加)
|
|
|
|
function getdataAdv(domain, at) {
|
|
|
|
var start = "https://" + domain + "/api/v1/accounts/verify_credentials";
|
|
|
|
fetch(start, {
|
|
|
|
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) {
|
|
|
|
console.log(json);
|
|
|
|
if (json.error) {
|
|
|
|
console.error("Error:" + json.error);
|
|
|
|
Materialize.toast("エラーが発生しました。しばらく待ってから再起動してください。Error:" + json.error,
|
|
|
|
5000);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var add = {
|
|
|
|
at: at,
|
|
|
|
name: json["display_name"],
|
|
|
|
domain: domain,
|
|
|
|
user: json["acct"],
|
|
|
|
prof: json["avatar"],
|
|
|
|
id: json["id"]
|
|
|
|
};
|
|
|
|
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, json["avatar"]);
|
|
|
|
console.log(obj);
|
|
|
|
var json = JSON.stringify(obj);
|
|
|
|
localStorage.setItem("multi", json);
|
|
|
|
location.href="index.html";
|
|
|
|
});
|
|
|
|
}
|
2018-01-28 23:22:43 +11:00
|
|
|
|
2018-03-27 13:39:35 +11:00
|
|
|
//MarkdownやBBCodeの対応、文字数制限をチェック
|
2018-02-09 03:43:11 +11:00
|
|
|
function ckdb(acct_id) {
|
2018-01-28 23:22:43 +11:00
|
|
|
var domain = localStorage.getItem("domain_" + acct_id);
|
2018-02-09 03:43:11 +11:00
|
|
|
if(domain=="kirishima.cloud"){
|
|
|
|
localStorage.setItem("kirishima", "true");
|
|
|
|
$("#ranking-btn").show();
|
|
|
|
}
|
2018-01-28 23:22:43 +11:00
|
|
|
var at = localStorage.getItem(domain + "_at");
|
|
|
|
var bbcode = domain + "_bbcode";
|
|
|
|
var letters = domain + "_letters";
|
2018-02-25 19:41:34 +11:00
|
|
|
if(localStorage.getItem("instance")){
|
|
|
|
var json=JSON.parse(localStorage.getItem("instance"));
|
|
|
|
if (json[bbcode]) {
|
|
|
|
if (json[bbcode] == "enabled") {
|
|
|
|
localStorage.setItem("bb_" + acct_id, "true");
|
|
|
|
} else {
|
|
|
|
localStorage.removeItem("bb_" + acct_id);
|
|
|
|
$("[data-activates='bbcode']").addClass("disabled");
|
|
|
|
$("[data-activates='bbcode']").prop("disabled", true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
localStorage.removeItem("bb_" + acct_id);
|
|
|
|
$("[data-activates='bbcode']").addClass("disabled");
|
|
|
|
$("[data-activates='bbcode']").addClass("disabled", true);
|
|
|
|
}
|
|
|
|
if (json[letters]) {
|
|
|
|
if($("#textarea").attr("data-length")<json[letters]){
|
|
|
|
$("#textarea").attr("data-length", json[letters]);
|
|
|
|
}
|
|
|
|
} else {}
|
|
|
|
if (json[domain + "_markdown"] == "enabled") {
|
|
|
|
localStorage.setItem("md_" + acct_id, "true");
|
|
|
|
$(".markdown").show();
|
|
|
|
}else{
|
|
|
|
localStorage.removeItem("bb_" + acct_id);
|
|
|
|
}
|
2018-03-20 15:55:25 +11:00
|
|
|
if(json[domain + "_home"]){
|
|
|
|
console.log("unique name:"+json[domain + "_home"]);
|
|
|
|
localStorage.setItem("home_" + acct_id, json[domain + "_home"]);
|
|
|
|
}
|
|
|
|
if(json[domain + "_local"]){
|
|
|
|
localStorage.setItem("local_" + acct_id, json[domain + "_local"]);
|
|
|
|
}
|
|
|
|
if(json[domain + "_public"]){
|
|
|
|
localStorage.setItem("public_" + acct_id, json[domain + "_public"]);
|
|
|
|
}
|
|
|
|
if(json[domain + "_notification"]){
|
|
|
|
localStorage.setItem("notification_" + acct_id, json[domain + "_notification"]);
|
|
|
|
}
|
2018-02-25 19:41:34 +11:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-01-28 23:22:43 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
//サポートインスタンス取得
|
|
|
|
function support() {
|
2018-03-14 05:31:31 +11:00
|
|
|
var ver=enc(localStorage.getItem("ver"));
|
|
|
|
var start = "https://dl.thedesk.top/mastodon_data.json?"+ver;
|
2018-01-28 23:22:43 +11:00
|
|
|
fetch(start, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'content-type': 'application/json'
|
|
|
|
},
|
|
|
|
//body: JSON.stringify({})
|
|
|
|
}).then(function(response) {
|
|
|
|
return response.json();
|
|
|
|
}).catch(function(error) {
|
|
|
|
todo(error);
|
|
|
|
console.error(error);
|
|
|
|
}).then(function(json) {
|
|
|
|
console.log(json);
|
|
|
|
Object.keys(json).forEach(function(key) {
|
|
|
|
var instance = json[key];
|
|
|
|
if (instance == "instance") {
|
|
|
|
templete = '<button class="btn waves-effect" onclick="login(\'' + key +
|
|
|
|
'\')">' + json[key + "_name"] + '(' + key + ')</button>';
|
|
|
|
$("#support").append(templete);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//アカウントを選択…を実装
|
|
|
|
function multi() {
|
|
|
|
var multi = localStorage.getItem("multi");
|
|
|
|
if (!multi) {
|
2018-03-27 13:39:35 +11:00
|
|
|
var obj = [];
|
2018-01-28 23:22:43 +11:00
|
|
|
var json = JSON.stringify(obj);
|
|
|
|
localStorage.setItem("multi", json);
|
|
|
|
} else {
|
|
|
|
var obj = JSON.parse(multi);
|
|
|
|
}
|
|
|
|
var templete;
|
|
|
|
var last = localStorage.getItem("last-use");
|
|
|
|
var sel;
|
2018-03-27 13:39:35 +11:00
|
|
|
console.log(obj.length)
|
|
|
|
if(obj.length<1){
|
|
|
|
$("#src-acct-sel").html('<option value="tootsearch">Tootsearch</option>');
|
|
|
|
$("#add-acct-sel").html('<option value="noauth">認証せずに見る</option>');
|
|
|
|
}else{
|
2018-01-28 23:22:43 +11:00
|
|
|
Object.keys(obj).forEach(function(key) {
|
|
|
|
var acct = obj[key];
|
|
|
|
var list = key * 1 + 1;
|
|
|
|
if (key == last) {
|
|
|
|
sel = "selected";
|
|
|
|
} else {
|
|
|
|
sel = "";
|
|
|
|
}
|
|
|
|
templete = '<option value="' + key + '" data-icon="' + acct.prof +
|
|
|
|
'" class="left circle" ' + sel + '>' + acct.user + '@' + acct.domain +
|
|
|
|
'</option>';
|
|
|
|
$(".acct-sel").append(templete);
|
2018-03-21 16:36:02 +11:00
|
|
|
|
2018-01-28 23:22:43 +11:00
|
|
|
});
|
2018-03-27 13:39:35 +11:00
|
|
|
$("#src-acct-sel").append('<option value="tootsearch">Tootsearch</option>');
|
|
|
|
$("#add-acct-sel").append('<option value="noauth">認証せずに見る</option>');
|
|
|
|
}
|
2018-03-21 16:36:02 +11:00
|
|
|
$('select').material_select('update');
|
2018-01-28 23:22:43 +11:00
|
|
|
}
|
2018-02-18 16:43:11 +11:00
|
|
|
|
2018-03-14 05:31:31 +11:00
|
|
|
//バージョンエンコ
|
|
|
|
function enc(ver){
|
|
|
|
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 , "" );
|
|
|
|
return ver;
|
|
|
|
}
|