Add: JSON parse miss error-log

This commit is contained in:
cutls 2019-11-04 01:10:06 +09:00
parent 5dfb28f2de
commit ffa4ecd673
23 changed files with 3799 additions and 3594 deletions

View File

@ -92,7 +92,8 @@ function verck(ver, jp) {
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(mess) { .then(function(mess) {
@ -144,7 +145,7 @@ function verck(ver, jp) {
return response.json(); return response.json();
}) })
.catch(function(error) { .catch(function(error) {
todo(error); todo(error);setLog(start, "JSON", error);
console.error(error); console.error(error);
}) })
.then(function(mess) { .then(function(mess) {

View File

@ -2,16 +2,16 @@
//最初に読むやつ //最初に読むやつ
//アスタルテ判定初期化 //アスタルテ判定初期化
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);
} }
//コード受信 //コード受信
@ -27,18 +27,18 @@ function ck() {
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) {
@ -46,53 +46,54 @@ function ck() {
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(JSON.stringify({ httpreq.send(
scopes: 'read write follow', JSON.stringify({
client_name: "TheDesk(PC)", scopes: "read write follow",
redirect_uris: red, client_name: "TheDesk(PC)",
website: "https://thedesk.top" redirect_uris: red,
})); 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){ setLog(start, this.status, json); } if (this.status !== 200) {
var auth = "https://" + url + "/oauth/authorize?client_id=" + json[ setLog(start, this.status, json);
"client_id"] + "&client_secret=" + json["client_secret"] + }
"&response_type=code&redirect_uri=" + red + "&scope=read+write+follow"; 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";
localStorage.setItem("domain_" + acct_id, url); localStorage.setItem("domain_" + acct_id, url);
localStorage.setItem("client_id", json["client_id"]); localStorage.setItem("client_id", json["client_id"]);
localStorage.setItem("client_secret", json["client_secret"]); localStorage.setItem("client_secret", json["client_secret"]);
$("#auth").show(); $("#auth").show();
$("#masara").hide(); $("#masara").hide();
postMessage(["openUrl", auth], "*") postMessage(["openUrl", auth], "*");
if ($('#linux:checked').val() == "on") { if ($("#linux:checked").val() == "on") {
} else { } else {
postMessage(["sendSinmpleIpc", "quit"], "*") postMessage(["sendSinmpleIpc", "quit"], "*");
} }
} }
} };
} }
//テキストボックスにURL入れた //テキストボックスにURL入れた
@ -101,11 +102,10 @@ function instance() {
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();
} }
@ -118,9 +118,9 @@ function code(code, mode) {
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",
@ -129,28 +129,31 @@ function code(code, mode) {
client_secret: secret, client_secret: secret,
code: code code: code
}) })
}).then(function (response) { })
if (!response.ok) { .then(function(response) {
response.text().then(function(text) { if (!response.ok) {
setLog(response.url, response.status, text); response.text().then(function(text) {
}); setLog(response.url, response.status, text);
} });
return response.json();
}).catch(function (error) {
todo(error);
console.error(error);
}).then(function (json) {
todo(json);
if (json["access_token"]) {
localStorage.setItem(url + "_at", json["access_token"]);
if (mode == "manager") {
getdataAdv(url, json["access_token"]);
} else {
getdata();
} }
return response.json();
} })
}); .catch(function(error) {
todo(error);
setLog(start, "JSON", error);
console.error(error);
})
.then(function(json) {
todo(json);
if (json["access_token"]) {
localStorage.setItem(url + "_at", json["access_token"]);
if (mode == "manager") {
getdataAdv(url, json["access_token"]);
} else {
getdata();
}
}
});
} }
//ユーザーデータ取得(最初) //ユーザーデータ取得(最初)
@ -160,173 +163,186 @@ function getdata() {
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
todo(error); if (!response.ok) {
console.error(error); response.text().then(function(text) {
}).then(function (json) { setLog(response.url, response.status, text);
if (json.error) { });
console.error("Error:" + json.error); }
M.toast({ html: lang.lang_fatalerroroccured + "Error:" + json.error, displayLength: 5000 }) return response.json();
return; })
} .catch(function(error) {
var avatar = json["avatar"]; todo(error);
//missingがmissingなやつ setLog(start, "JSON", error);
if (avatar == "/avatars/original/missing.png") { console.error(error);
avatar = "./img/missing.svg"; })
} .then(function(json) {
var obj = [{ if (json.error) {
at: at, console.error("Error:" + json.error);
name: json["display_name"], M.toast({ html: lang.lang_fatalerroroccured + "Error:" + json.error, displayLength: 5000 });
domain: domain, return;
user: json["acct"], }
prof: avatar, var avatar = json["avatar"];
id: json["id"], //missingがmissingなやつ
vis: json["source"]["privacy"] if (avatar == "/avatars/original/missing.png") {
}]; avatar = "./img/missing.svg";
var json = JSON.stringify(obj); }
localStorage.setItem("multi", json); var obj = [
localStorage.setItem("name_" + acct_id, json["display_name"]); {
localStorage.setItem("user_" + acct_id, json["acct"]); at: at,
localStorage.setItem("user-id_" + acct_id, json["id"]); name: json["display_name"],
localStorage.setItem("prof_" + acct_id, avatar); domain: domain,
$("#masara").hide(); user: json["acct"],
$("#auth").hide(); prof: avatar,
$("#tl").show(); id: json["id"],
parseColumn() vis: json["source"]["privacy"]
ckdb(); }
}); ];
var json = JSON.stringify(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, avatar);
$("#masara").hide();
$("#auth").hide();
$("#tl").show();
parseColumn();
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
todo(error); if (!response.ok) {
console.error(error); response.text().then(function(text) {
}).then(function (json) { setLog(response.url, response.status, text);
if (json.error) { });
console.error("Error:" + json.error); }
M.toast({ html: lang.lang_fatalerroroccured + "Error:" + json.error, displayLength: 5000 }) return response.json();
return; })
} .catch(function(error) {
var avatar = json["avatar"]; todo(error);
//missingがmissingなやつ setLog(start, "JSON", error);
if (avatar == "/avatars/original/missing.png") { console.error(error);
avatar = "../../img/missing.svg"; })
} .then(function(json) {
if (json["source"]["privacy"]) { if (json.error) {
var priv = json["source"]["privacy"]; console.error("Error:" + json.error);
} else { M.toast({ html: lang.lang_fatalerroroccured + "Error:" + json.error, displayLength: 5000 });
var priv = "public"; return;
} }
var add = { var avatar = json["avatar"];
at: at, //missingがmissingなやつ
name: json["display_name"], if (avatar == "/avatars/original/missing.png") {
domain: domain, avatar = "../../img/missing.svg";
user: json["acct"], }
prof: avatar, if (json["source"]["privacy"]) {
id: json["id"], var priv = json["source"]["privacy"];
vis: priv } else {
}; var priv = "public";
var multi = localStorage.getItem("multi"); }
var obj = JSON.parse(multi); var add = {
var target = obj.lengtth; at: at,
obj.push(add); name: json["display_name"],
localStorage.setItem("name_" + target, json["display_name"]); domain: domain,
localStorage.setItem("user_" + target, json["acct"]); user: json["acct"],
localStorage.setItem("user-id_" + target, json["id"]); prof: avatar,
localStorage.setItem("prof_" + target, avatar); id: json["id"],
var json = JSON.stringify(obj); vis: priv
localStorage.setItem("multi", json); };
location.href = "index.html"; 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);
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 + var start = "https://" + obj[target].domain + "/api/v1/accounts/verify_credentials";
"/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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
todo(error); if (!response.ok) {
console.error(error); response.text().then(function(text) {
}).then(function (json) { setLog(response.url, response.status, text);
if (json.error) { });
console.error("Error:" + json.error); }
M.toast({ html: lang.lang_fatalerroroccured + "Error:" + json.error, displayLength: 5000 }) return response.json();
return; })
} .catch(function(error) {
var avatar = json["avatar"]; todo(error);
//missingがmissingなやつ setLog(start, "JSON", error);
if (avatar == "/avatars/original/missing.png" || !avatar) { console.error(error);
avatar = "./img/missing.svg"; })
} .then(function(json) {
var ref = { if (json.error) {
at: obj[target].at, console.error("Error:" + json.error);
name: json["display_name"], M.toast({ html: lang.lang_fatalerroroccured + "Error:" + json.error, displayLength: 5000 });
domain: obj[target].domain, return;
user: json["acct"], }
prof: avatar, var avatar = json["avatar"];
id: json["id"], //missingがmissingなやつ
vis: json["source"]["privacy"] if (avatar == "/avatars/original/missing.png" || !avatar) {
}; avatar = "./img/missing.svg";
localStorage.setItem("name_" + target, json["display_name"]); }
localStorage.setItem("user_" + target, json["acct"]); var ref = {
localStorage.setItem("user-id_" + target, json["id"]); at: obj[target].at,
localStorage.setItem("prof_" + target, avatar); name: json["display_name"],
localStorage.setItem("follow_" + target, json["following_count"]); domain: obj[target].domain,
if(json["source"]["sensitive"]){ user: json["acct"],
localStorage.setItem("nsfw_" + target, "true"); prof: avatar,
}else{ id: json["id"],
localStorage.removeItem("nsfw_" + target); vis: json["source"]["privacy"]
} };
obj[target] = ref; localStorage.setItem("name_" + target, json["display_name"]);
var json = JSON.stringify(obj); localStorage.setItem("user_" + target, json["acct"]);
localStorage.setItem("multi", json); localStorage.setItem("user-id_" + target, json["id"]);
if (!loadskip) { localStorage.setItem("prof_" + target, avatar);
load(); localStorage.setItem("follow_" + target, json["following_count"]);
} 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);
if (!loadskip) {
load();
}
});
} }
//MarkdownやBBCodeの対応、文字数制限をチェック //MarkdownやBBCodeの対応、文字数制限をチェック
//絶対ストリーミングを閉じさせないマン //絶対ストリーミングを閉じさせないマン
@ -408,35 +424,35 @@ function ckdb(acct_id) {
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) {
return response.json();
}).catch(function (error) {
console.error(error);
}).then(function (json) {
if (json.error) {
console.error(json.error);
return;
} }
if (json) { })
if (json["max_toot_chars"]) { .then(function(response) {
localStorage.setItem("letters_" + acct_id, json["max_toot_chars"]); return response.json();
})
.catch(function(error) {
console.error(error);
})
.then(function(json) {
if (json.error) {
console.error(json.error);
return;
} }
if (json["urls"]["streaming_api"]) { if (json) {
localStorage.setItem("streaming_" + acct_id, json["urls"]["streaming_api"]); if (json["max_toot_chars"]) {
}else{ localStorage.setItem("letters_" + acct_id, json["max_toot_chars"]);
localStorage.removeItem("streaming_" + acct_id); }
if (json["urls"]["streaming_api"]) {
localStorage.setItem("streaming_" + acct_id, json["urls"]["streaming_api"]);
} else {
localStorage.removeItem("streaming_" + acct_id);
}
} }
} });
});
} else { } else {
} }
} }
//アカウントを選択…を実装 //アカウントを選択…を実装
@ -464,27 +480,27 @@ function multiSelector(parseC) {
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);
@ -517,18 +533,15 @@ function multiSelector(parseC) {
} else { } else {
sel = ""; sel = "";
} }
templete = '<option value="' + key + '" data-icon="' + acct.prof + templete = '<option value="' + key + '" data-icon="' + acct.prof + '" class="left circle" ' + sel + ">" + acct.user + "@" + acct.domain + "</option>";
'" class="left circle" ' + sel + '>' + acct.user + '@' + acct.domain +
'</option>';
$(".acct-sel").append(templete); $(".acct-sel").append(templete);
}); });
$("#src-acct-sel").append('<option value="tootsearch">Tootsearch</option>'); $("#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>'); $("#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>'); $("#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);
} }
} }
@ -546,23 +559,25 @@ function enc(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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
console.error(error); if (!response.ok) {
}).then(function (json) { response.text().then(function(text) {
if (json) { setLog(response.url, response.status, text);
localStorage.setItem("ticker", JSON.stringify(json)); });
} }
}); return response.json();
})
.catch(function(error) {
console.error(error);
})
.then(function(json) {
if (json) {
localStorage.setItem("ticker", JSON.stringify(json));
}
});
} }

View File

@ -86,14 +86,15 @@ function data(domain) {
}) })
.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);
console.error(error); console.error(error);
}) })
.then(function(json) { .then(function(json) {
@ -120,14 +121,15 @@ function data(domain) {
}) })
.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);
console.error(error); console.error(error);
}) })
.then(function(json) { .then(function(json) {
@ -330,7 +332,9 @@ function login(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){ setLog(start, this.status, json); } if (this.status !== 200) {
setLog(start, this.status, json);
}
localStorage.setItem("msky", "false"); 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("domain_tmp", url);
@ -357,14 +361,15 @@ function versionChecker(url) {
}) })
.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);
console.error(error); console.error(error);
}) })
.then(function(json) { .then(function(json) {
@ -395,14 +400,15 @@ function versionCompat(prefix, ver, title, real) {
}) })
.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);
console.error(error); console.error(error);
}) })
.then(function(json) { .then(function(json) {
@ -458,7 +464,9 @@ 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){ setLog(start, this.status, json); } if (this.status !== 200) {
setLog(start, this.status, json);
}
misskeyAuth(url, json.secret); misskeyAuth(url, json.secret);
} }
}; };
@ -480,7 +488,9 @@ function misskeyAuth(url, 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){ setLog(start, this.status, json); } if (this.status !== 200) {
setLog(start, this.status, json);
}
var token = json.token; var token = json.token;
$("#auth").show(); $("#auth").show();
$("#code").val(token); $("#code").val(token);
@ -530,7 +540,9 @@ function 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){ setLog(start, this.status, json); } if (this.status !== 200) {
setLog(start, this.status, json);
}
var i = sha256(json.accessToken + localStorage.getItem("mkc")); var i = sha256(json.accessToken + localStorage.getItem("mkc"));
var avatar = json["user"]["avatarUrl"]; var avatar = json["user"]["avatarUrl"];
var priv = "public"; var priv = "public";
@ -587,7 +599,9 @@ function 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){ setLog(start, this.status, json); } if (this.status !== 200) {
setLog(start, this.status, json);
}
if (json["access_token"]) { if (json["access_token"]) {
$("#auth").hide(); $("#auth").hide();
$("#add").show(); $("#add").show();
@ -609,14 +623,15 @@ function getdata(domain, 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);
console.error(error); console.error(error);
}) })
.then(function(json) { .then(function(json) {
@ -734,14 +749,15 @@ function refresh(target) {
}); });
} }
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);
console.error(error); console.error(error);
}) })
.then(function(json) { .then(function(json) {
@ -795,7 +811,9 @@ function misskeyRefresh(obj, target, 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){ setLog(start, this.status, json); } if (this.status !== 200) {
setLog(start, this.status, json);
}
var avatar = json["user"]["avatarUrl"]; var avatar = json["user"]["avatarUrl"];
var priv = "public"; var priv = "public";
var add = { var add = {
@ -921,14 +939,15 @@ input.addEventListener(
}) })
.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);
console.error(error); console.error(error);
}) })
.then(function(json) { .then(function(json) {

View File

@ -6,181 +6,186 @@ $("#emoji-next").addClass("disabled");
//絵文字ボタンのトグル //絵文字ボタンのトグル
function emojiToggle(reaction) { function emojiToggle(reaction) {
var acct_id = $("#post-acct-sel").val(); var acct_id = $("#post-acct-sel").val();
var selin = $("#textarea").prop('selectionStart'); var selin = $("#textarea").prop("selectionStart");
if (!selin) { if (!selin) {
selin = 0; selin = 0;
} }
if ($("#emoji").hasClass("hide")) { if ($("#emoji").hasClass("hide")) {
$("#emoji").removeClass("hide") $("#emoji").removeClass("hide");
$("#right-side").show() $("#right-side").show();
$("#right-side").css("width", "300px") $("#right-side").css("width", "300px");
$("#left-side").css("width", "calc(100% - 300px)") $("#left-side").css("width", "calc(100% - 300px)");
var width = localStorage.getItem("postbox-width"); var width = localStorage.getItem("postbox-width");
if (width) { if (width) {
width = width.replace("px", "") * 1 + 300 width = width.replace("px", "") * 1 + 300;
} else { } else {
width = 600 width = 600;
} }
$("#post-box").css("width", width + "px") $("#post-box").css("width", width + "px");
$("#suggest").html(""); $("#suggest").html("");
if (!localStorage.getItem("emojis_" + acct_id)) { if (!localStorage.getItem("emojis_" + acct_id)) {
var html = var html = '<button class="btn waves-effect green" style="width:100%; padding:0; margin-top:0;" onclick="emojiGet(\'true\');">' + lang.lang_emoji_get + "</button>";
'<button class="btn waves-effect green" style="width:100%; padding:0; margin-top:0;" onclick="emojiGet(\'true\');">' + lang.lang_emoji_get + '</button>';
$("#emoji-list").html(html); $("#emoji-list").html(html);
} else { } else {
emojiList('home', reaction); emojiList("home", reaction);
} }
} else { } else {
$("#poll").addClass("hide") $("#poll").addClass("hide");
$("#right-side").hide() $("#right-side").hide();
$("#right-side").css("width", "300px") $("#right-side").css("width", "300px");
$("#emoji").addClass("hide") $("#emoji").addClass("hide");
$("#suggest").html(""); $("#suggest").html("");
$("#left-side").css("width", "100%") $("#left-side").css("width", "100%");
var width = localStorage.getItem("postbox-width"); var width = localStorage.getItem("postbox-width");
if (width) { if (width) {
width = width.replace("px", "") * 1 width = width.replace("px", "") * 1;
} else { } else {
width = 300 width = 300;
} }
$("#post-box").css("width", width + "px") $("#post-box").css("width", width + "px");
} }
} }
//絵文字リスト挿入 //絵文字リスト挿入
function emojiGet(parse, started) { function emojiGet(parse, started) {
$('#emoji-list').text('Loading...'); $("#emoji-list").text("Loading...");
var acct_id = $("#post-acct-sel").val(); var acct_id = $("#post-acct-sel").val();
var domain = localStorage.getItem("domain_" + acct_id); var domain = localStorage.getItem("domain_" + acct_id);
if (localStorage.getItem("mode_" + domain) != "misskey") { if (localStorage.getItem("mode_" + domain) != "misskey") {
var start = "https://" + domain + "/api/v1/custom_emojis"; var start = "https://" + domain + "/api/v1/custom_emojis";
fetch(start, { fetch(start, {
method: 'GET', method: "GET",
headers: { headers: {
'content-type': 'application/json' "content-type": "application/json"
}, }
}).then(function (response) { })
if (!response.ok) { .then(function(response) {
response.text().then(function(text) { if (!response.ok) {
setLog(response.url, response.status, text); response.text().then(function(text) {
}); setLog(response.url, response.status, text);
} });
return response.json(); }
}).catch(function (error) { return response.json();
todo(error); })
console.error(error); .catch(function(error) {
}).then(function (json) { todo(error);
if (parse == "true") { setLog(start, "JSON", error);
$('#emoji-list').text('Parsing...'); console.error(error);
var md = { })
"categorized": {}, .then(function(json) {
"uncategorized": [] if (parse == "true") {
}; $("#emoji-list").text("Parsing...");
var if_categorized = false var md = {
Object.keys(json).forEach(function (key) { categorized: {},
var emoji = json[key]; uncategorized: []
if (emoji.visible_in_picker) { };
var listed = true var if_categorized = false;
} else { Object.keys(json).forEach(function(key) {
var listed = false var emoji = json[key];
} if (emoji.visible_in_picker) {
if (emoji.category) { var listed = true;
var cat = emoji.category } else {
if (!md["categorized"][cat]) { var listed = false;
md["categorized"][cat] = []
} }
md["categorized"][cat].push({ if (emoji.category) {
"shortcode": emoji.shortcode, var cat = emoji.category;
"url": emoji.url, if (!md["categorized"][cat]) {
"listed": listed md["categorized"][cat] = [];
}) }
if_categorized = true md["categorized"][cat].push({
} else { shortcode: emoji.shortcode,
md["uncategorized"].push({ url: emoji.url,
"shortcode": emoji.shortcode, listed: listed
"url": emoji.url, });
"listed": listed if_categorized = true;
}) } else {
} md["uncategorized"].push({
}); shortcode: emoji.shortcode,
console.log(md) url: emoji.url,
//絵文字をマストドン公式と同順にソート listed: listed
md["uncategorized"].sort(function (a, b) { });
if (a.shortcode < b.shortcode) return -1; }
if (a.shortcode > b.shortcode) return 1; });
return 0; console.log(md);
}); //絵文字をマストドン公式と同順にソート
Object.keys(md["categorized"]).forEach(function (key) { md["uncategorized"].sort(function(a, b) {
md["categorized"][key].sort(function (a, b) {
if (a.shortcode < b.shortcode) return -1; if (a.shortcode < b.shortcode) return -1;
if (a.shortcode > b.shortcode) return 1; if (a.shortcode > b.shortcode) return 1;
return 0; return 0;
}); });
}); Object.keys(md["categorized"]).forEach(function(key) {
md["categorized"][key].sort(function(a, b) {
if (a.shortcode < b.shortcode) return -1;
if (a.shortcode > b.shortcode) return 1;
return 0;
});
});
md["if_categorized"] = if_categorized md["if_categorized"] = if_categorized;
localStorage.setItem("emojis_" + acct_id, JSON.stringify(md)); localStorage.setItem("emojis_" + acct_id, JSON.stringify(md));
} else { } else {
localStorage.setItem("emojis_" + acct_id, JSON.stringify(md)); localStorage.setItem("emojis_" + acct_id, JSON.stringify(md));
} }
localStorage.setItem("emojiseek", 0); localStorage.setItem("emojiseek", 0);
if (!started) { if (!started) {
emojiList('home') emojiList("home");
} }
}); });
} else { } else {
var start = "https://" + domain + "/api/meta"; var start = "https://" + domain + "/api/meta";
fetch(start, { fetch(start, {
method: 'POST', method: "POST",
headers: { headers: {
'content-type': 'application/json' "content-type": "application/json"
},
}).then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
}).catch(function (error) {
todo(error);
console.error(error);
}).then(function (json) {
if (json.enableEmojiReaction) {
localStorage.setItem("emojiReaction_" + acct_id, "true");
} else {
localStorage.setItem("emojiReaction_" + acct_id, "disabled");
} }
var emojis = json.emojis; })
var md = {"uncategorized": []} .then(function(response) {
Object.keys(emojis).forEach(function (key) { if (!response.ok) {
var emoji = emojis[key]; response.text().then(function(text) {
md["uncategorized"].push({ setLog(response.url, response.status, text);
"shortcode": emoji.name, });
"url": emoji.url, }
"listed": true return response.json();
}) })
}); .catch(function(error) {
md["if_categorized"] = false todo(error);
if (parse == "true") { setLog(start, "JSON", error);
$('#emoji-list').text('Parsing...'); console.error(error);
//絵文字をマストドン公式と同順にソート })
md["uncategorized"].sort(function (a, b) { .then(function(json) {
if (a.shortcode < b.shortcode) return -1; if (json.enableEmojiReaction) {
if (a.shortcode > b.shortcode) return 1; localStorage.setItem("emojiReaction_" + acct_id, "true");
return 0; } else {
localStorage.setItem("emojiReaction_" + acct_id, "disabled");
}
var emojis = json.emojis;
var md = { uncategorized: [] };
Object.keys(emojis).forEach(function(key) {
var emoji = emojis[key];
md["uncategorized"].push({
shortcode: emoji.name,
url: emoji.url,
listed: true
});
}); });
localStorage.setItem("emojis_" + acct_id, JSON.stringify(md)); md["if_categorized"] = false;
} else { if (parse == "true") {
localStorage.setItem("emojis_" + acct_id, JSON.stringify(md)); $("#emoji-list").text("Parsing...");
} //絵文字をマストドン公式と同順にソート
localStorage.setItem("emojiseek", 0); md["uncategorized"].sort(function(a, b) {
if (!started) { if (a.shortcode < b.shortcode) return -1;
emojiList('home') if (a.shortcode > b.shortcode) return 1;
} return 0;
}); });
localStorage.setItem("emojis_" + acct_id, JSON.stringify(md));
} else {
localStorage.setItem("emojis_" + acct_id, JSON.stringify(md));
}
localStorage.setItem("emojiseek", 0);
if (!started) {
emojiList("home");
}
});
} }
} }
@ -189,8 +194,8 @@ function emojiList(target, reaction) {
$("#now-emoji").text(lang.lang_emoji_custom); $("#now-emoji").text(lang.lang_emoji_custom);
var acct_id = $("#post-acct-sel").val(); var acct_id = $("#post-acct-sel").val();
if (reaction && localStorage.getItem("emojiReaction_" + acct_id) != "true") { if (reaction && localStorage.getItem("emojiReaction_" + acct_id) != "true") {
console.error("Disabled") console.error("Disabled");
clear() clear();
hide(); hide();
return false; return false;
} }
@ -203,30 +208,34 @@ function emojiList(target, reaction) {
localStorage.setItem("emojiseek", start); localStorage.setItem("emojiseek", start);
} else { } else {
var start = 0; var start = 0;
localStorage.getItem("emojiseek", 0) localStorage.getItem("emojiseek", 0);
} }
var html = ''; var html = "";
var raw = JSON.parse(localStorage.getItem("emojis_" + acct_id)); var raw = JSON.parse(localStorage.getItem("emojis_" + acct_id));
console.log(raw) console.log(raw);
if (raw.if_categorized) { if (raw.if_categorized) {
var obj = [{ var obj = [
"divider": true, {
"cat": lang.lang_emoji_uncat divider: true,
}] cat: lang.lang_emoji_uncat
var cats = raw["uncategorized"] }
];
var cats = raw["uncategorized"];
obj = obj.concat(cats); obj = obj.concat(cats);
Object.keys(raw["categorized"]).forEach(function (key) { Object.keys(raw["categorized"]).forEach(function(key) {
var cats = raw["categorized"][key]; var cats = raw["categorized"][key];
obj = obj.concat([{ obj = obj.concat([
"divider": true, {
"cat": key divider: true,
}]); cat: key
}
]);
obj = obj.concat(cats); obj = obj.concat(cats);
}); });
} else { } else {
var obj = raw["uncategorized"] var obj = raw["uncategorized"];
} }
console.log(obj) console.log(obj);
var num = obj.length; var num = obj.length;
if (num < start) { if (num < start) {
@ -237,7 +246,7 @@ function emojiList(target, reaction) {
$("#emoji-sum").text(page); $("#emoji-sum").text(page);
var ct = Math.ceil(start / 126); var ct = Math.ceil(start / 126);
if (ct === 0) { if (ct === 0) {
if(num > 0){ if (num > 0) {
var ct = 1; var ct = 1;
} }
$("#emoji-before").addClass("disabled"); $("#emoji-before").addClass("disabled");
@ -254,18 +263,15 @@ function emojiList(target, reaction) {
var emoji = obj[i]; var emoji = obj[i];
if (emoji) { if (emoji) {
if (reaction) { if (reaction) {
html = html + '<a onclick="emojiReaction(\':' + emoji.shortcode + html = html + "<a onclick=\"emojiReaction(':" + emoji.shortcode + ':\')" class="pointer"><img src="' + emoji.url + '" width="20" title="' + emoji.shortcode + '"></a>';
':\')" class="pointer"><img src="' + emoji.url + '" width="20" title="' + emoji.shortcode + '"></a>';
} else { } else {
if(emoji.divider){ if (emoji.divider) {
html = html + '<p style="margin-bottom:0">'+ emoji.cat +'</p>' html = html + '<p style="margin-bottom:0">' + emoji.cat + "</p>";
}else{ } else {
if (emoji.listed) { if (emoji.listed) {
html = html + '<a onclick="emojiInsert(\':' + emoji.shortcode + html = html + "<a onclick=\"emojiInsert(':" + emoji.shortcode + ':\')" class="pointer"><img src="' + emoji.url + '" width="20" title="' + emoji.shortcode + '"></a>';
':\')" class="pointer"><img src="' + emoji.url + '" width="20" title="' + emoji.shortcode + '"></a>';
} }
} }
} }
} }
} }
@ -275,7 +281,7 @@ function emojiList(target, reaction) {
//絵文字など様々なものをテキストボックスに挿入 //絵文字など様々なものをテキストボックスに挿入
function emojiInsert(code, del) { function emojiInsert(code, del) {
var now = $("#textarea").val(); var now = $("#textarea").val();
var selin = $("#textarea").prop('selectionStart'); var selin = $("#textarea").prop("selectionStart");
if (localStorage.getItem("emoji-zero-width") == "yes") { if (localStorage.getItem("emoji-zero-width") == "yes") {
var blank = ""; var blank = "";
} else { } else {
@ -283,11 +289,11 @@ function emojiInsert(code, del) {
} }
var before = now.substr(0, selin); var before = now.substr(0, selin);
if (before.slice(-1) != " ") { if (before.slice(-1) != " ") {
before = before + blank before = before + blank;
} }
var after = now.substr(selin, now.length); var after = now.substr(selin, now.length);
if (after.slice(-1) != " ") { if (after.slice(-1) != " ") {
after = blank + after after = blank + after;
} }
newt = before + code + after; newt = before + code + after;
if (!del) { if (!del) {
@ -303,7 +309,7 @@ function emojiInsert(code, del) {
} }
//改行挿入 //改行挿入
function brInsert(code) { function brInsert(code) {
if (!$('#post-box').hasClass("appear")) { if (!$("#post-box").hasClass("appear")) {
localStorage.setItem("nohide", true); localStorage.setItem("nohide", true);
show(); show();
} }

View File

@ -118,7 +118,9 @@ function media(b64, type, no) {
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){ setLog(start, this.status, json); } if (this.status !== 200) {
setLog(start, this.status, json);
}
if (!json.id) { if (!json.id) {
todc(); todc();
$("#imgup").text(""); $("#imgup").text("");
@ -269,18 +271,19 @@ function altImage(acct_id, id) {
}) })
.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);
console.error(error); console.error(error);
}) })
.then(function(json) { .then(function(json) {
console.log(json) console.log(json);
$("[data-media=" + id + "]").attr("title", data); $("[data-media=" + id + "]").attr("title", data);
}); });
}, },
@ -288,7 +291,7 @@ function altImage(acct_id, id) {
}).then(result => { }).then(result => {
if (result.value) { if (result.value) {
Swal.fire({ Swal.fire({
title: "Complete", title: "Complete"
}); });
} }
}); });

View File

@ -1,250 +1,261 @@
//Renpost //Renpost
function renote(id, acct_id, remote) { function renote(id, acct_id, remote) {
if ($("#pub_" + id).hasClass("rted")) { if ($("#pub_" + id).hasClass("rted")) {
return false; return false;
} }
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/notes/create"; var start = "https://" + domain + "/api/notes/create";
if (localStorage.getItem("mode_" + domain) != "misskey") { if (localStorage.getItem("mode_" + domain) != "misskey") {
return false; return false;
} }
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(JSON.stringify({ i: at, renoteId: id })); httpreq.send(JSON.stringify({ i: at, renoteId: id }));
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){ setLog(start, this.status, json); } if (this.status !== 200) {
console.log(["Success: renote", json]); setLog(start, this.status, json);
$("[toot-id=" + id + "]").addClass("rted"); }
$(".rt_" + id).toggleClass("teal-text"); console.log(["Success: renote", json]);
} $("[toot-id=" + id + "]").addClass("rted");
} $(".rt_" + id).toggleClass("teal-text");
}
};
} }
//Renote //Renote
function renoteqt(id, acct_id) { function renoteqt(id, acct_id) {
localStorage.setItem("nohide", true); localStorage.setItem("nohide", true);
show(); show();
$("#reply").val("renote_" + id); $("#reply").val("renote_" + id);
$("#rec").text("Renote"); $("#rec").text("Renote");
$("#post-acct-sel").val(acct_id); $("#post-acct-sel").val(acct_id);
$("#post-acct-sel").prop("disabled", true); $("#post-acct-sel").prop("disabled", true);
$('select').formSelect(); $("select").formSelect();
$("#textarea").attr("placeholder", lang.lang_misskeyparse_qt); $("#textarea").attr("placeholder", lang.lang_misskeyparse_qt);
$("#textarea").focus(); $("#textarea").focus();
} }
//Reply //Reply
function misskeyreply(id, acct_id) { function misskeyreply(id, acct_id) {
localStorage.setItem("nohide", true); localStorage.setItem("nohide", true);
show(); show();
$("#reply").val(id); $("#reply").val(id);
$("#rec").text("Renote"); $("#rec").text("Renote");
$("#post-acct-sel").val(acct_id); $("#post-acct-sel").val(acct_id);
$("#post-acct-sel").prop("disabled", true); $("#post-acct-sel").prop("disabled", true);
$('select').formSelect(); $("select").formSelect();
$("#textarea").attr("placeholder", lang.lang_misskeyparse_qt); $("#textarea").attr("placeholder", lang.lang_misskeyparse_qt);
$("#textarea").focus(); $("#textarea").focus();
} }
//Reaction //Reaction
function reactiontoggle(id, acct_id, tlid) { function reactiontoggle(id, acct_id, tlid) {
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/notes/show"; var start = "https://" + domain + "/api/notes/show";
if (localStorage.getItem("mode_" + domain) != "misskey") { if (localStorage.getItem("mode_" + domain) != "misskey") {
return false; return false;
} }
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(JSON.stringify({ i: at, noteId: id })); httpreq.send(JSON.stringify({ i: at, noteId: id }));
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){ setLog(start, this.status, json); } if (this.status !== 200) {
console.log(["Success: reaction", json]); setLog(start, this.status, json);
if (json.reactions) { }
var reactions = ["like", "love", "laugh", "hmm", "surprise", "congrats", "angry", "confused", "pudding", "rip"]; console.log(["Success: reaction", json]);
for (var i = 0; i < reactions.length; i++) { if (json.reactions) {
if (json.reactions[reactions[i]]) { var reactions = ["like", "love", "laugh", "hmm", "surprise", "congrats", "angry", "confused", "pudding", "rip"];
$("#pub_" + id + " .re-" + reactions[i] + "ct").text(json.reactions[reactions[i]]) for (var i = 0; i < reactions.length; i++) {
$("#pub_" + id + " .re-" + reactions[i]).removeClass("hide") if (json.reactions[reactions[i]]) {
} else { $("#pub_" + id + " .re-" + reactions[i] + "ct").text(json.reactions[reactions[i]]);
$("#pub_" + id + " .re-" + reactions[i] + "ct").text(0) $("#pub_" + id + " .re-" + reactions[i]).removeClass("hide");
if ($("#pub_" + id + " .reactions").hasClass("fullreact")) { } else {
$("#pub_" + id + " .re-" + reactions[i]).addClass("hide") $("#pub_" + id + " .re-" + reactions[i] + "ct").text(0);
} else { if ($("#pub_" + id + " .reactions").hasClass("fullreact")) {
$("#pub_" + id + " .re-" + reactions[i]).removeClass("hide") $("#pub_" + id + " .re-" + reactions[i]).addClass("hide");
} } else {
$("#pub_" + id + " .re-" + reactions[i] + "ct").text(json.reactions[reactions[i]]) $("#pub_" + id + " .re-" + reactions[i]).removeClass("hide");
} }
} $("#pub_" + id + " .re-" + reactions[i] + "ct").text(json.reactions[reactions[i]]);
$("#pub_" + id + " .reactions").removeClass("hide"); }
$("#pub_" + id + " .reactions").toggleClass("fullreact") }
} else { $("#pub_" + id + " .reactions").removeClass("hide");
if ($("#pub_" + id + " .reactions").hasClass("fullreact")) { $("#pub_" + id + " .reactions").toggleClass("fullreact");
$("#pub_" + id + " .reactions").addClass("hide") } else {
$("#pub_" + id + " .reactions").removeClass("fullreact") if ($("#pub_" + id + " .reactions").hasClass("fullreact")) {
} else { $("#pub_" + id + " .reactions").addClass("hide");
$("#pub_" + id + " .reactions").removeClass("hide"); $("#pub_" + id + " .reactions").removeClass("fullreact");
$("#pub_" + id + " .reaction").removeClass("hide"); } else {
$("#pub_" + id + " .reactions").addClass("fullreact"); $("#pub_" + id + " .reactions").removeClass("hide");
} $("#pub_" + id + " .reaction").removeClass("hide");
} $("#pub_" + id + " .reactions").addClass("fullreact");
} }
} }
$("#pub_" + id + " .freeReact").toggleClass("hide"); }
};
$("#pub_" + id + " .freeReact").toggleClass("hide");
} }
//reactioncustom //reactioncustom
function reactioncustom(acct_id, id) { function reactioncustom(acct_id, id) {
$("#reply").val(id); $("#reply").val(id);
$("#unreact").hide(); $("#unreact").hide();
$("#addreact").removeClass("hide"); $("#addreact").removeClass("hide");
$("#post-acct-sel").val(acct_id); $("#post-acct-sel").val(acct_id);
$('select').formSelect(); $("select").formSelect();
localStorage.setItem("nohide", true); localStorage.setItem("nohide", true);
show() show();
emojiToggle(true) emojiToggle(true);
$("#left-side").hide(); $("#left-side").hide();
$("#default-emoji").hide(); $("#default-emoji").hide();
} }
function reactRefresh(acct_id, id) { function reactRefresh(acct_id, id) {
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/notes/show"; var start = "https://" + domain + "/api/notes/show";
var req = {}; var req = {};
req.i = at; req.i = at;
req.noteId = id; req.noteId = id;
var i = { var i = {
method: "POST", method: "POST",
body: JSON.stringify(req), body: JSON.stringify(req)
} };
fetch(start, i, fetch(start, i)
).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) { })
todo(error); .catch(function(error) {
console.error(error); todo(error);
}).then(function (json) { setLog(start, "JSON", error);
if (!json) { console.error(error);
return false; })
} .then(function(json) {
var poll = ""; if (!json) {
if (json.error) { return false;
$("[toot-id=" + id + "]").hide(); }
$("[toot-id=" + id + "]").remove(); var poll = "";
} else { if (json.error) {
reactRefreshCore(json) $("[toot-id=" + id + "]").hide();
} $("[toot-id=" + id + "]").remove();
}); } else {
reactRefreshCore(json);
}
});
} }
function reactRefreshCore(json) { function reactRefreshCore(json) {
var id = json.id; var id = json.id;
if (json.reactions) { if (json.reactions) {
$("#pub_" + id + " .reactions").removeClass("hide") $("#pub_" + id + " .reactions").removeClass("hide");
var regExp = new RegExp(":", "g"); var regExp = new RegExp(":", "g");
Object.keys(json.reactions).forEach(function (keye) { Object.keys(json.reactions).forEach(function(keye) {
keyeClass = keye.replace(regExp, ''); keyeClass = keye.replace(regExp, "");
if (json.reactions[keye]) { if (json.reactions[keye]) {
$("#pub_" + id + " .re-" + keyeClass + "ct").text(json.reactions[keye]) $("#pub_" + id + " .re-" + keyeClass + "ct").text(json.reactions[keye]);
$("#pub_" + id + " .re-" + keyeClass).removeClass("hide") $("#pub_" + id + " .re-" + keyeClass).removeClass("hide");
} else { } else {
$("#pub_" + id + " .re-" + keyeClass + "ct").text(0) $("#pub_" + id + " .re-" + keyeClass + "ct").text(0);
if ($("#pub_" + id + " .reactions").hasClass("fullreact")) { if ($("#pub_" + id + " .reactions").hasClass("fullreact")) {
$("#pub_" + id + " .re-" + keyeClass).addClass("hide") $("#pub_" + id + " .re-" + keyeClass).addClass("hide");
} }
$("#pub_" + id + " .re-" + keyeClass + "ct").text(json.reactions[keye]) $("#pub_" + id + " .re-" + keyeClass + "ct").text(json.reactions[keye]);
} }
}); });
} }
} }
function emojiReaction(emoji) { function emojiReaction(emoji) {
var acct_id = $("#post-acct-sel").val(); var acct_id = $("#post-acct-sel").val();
var id = $("#reply").val(); var id = $("#reply").val();
reaction(emoji, id, acct_id, null) reaction(emoji, id, acct_id, null);
clear(); clear();
hide(); hide();
} }
function reaction(mode, id, acct_id, tlid) { function reaction(mode, id, acct_id, tlid) {
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");
if ($(".fav_" + id).hasClass("yellow-text")) { if ($(".fav_" + id).hasClass("yellow-text")) {
var flag = "delete"; var flag = "delete";
} else { } else {
var flag = "create"; var flag = "create";
} }
var start = "https://" + domain + "/api/notes/reactions/" + flag; var start = "https://" + domain + "/api/notes/reactions/" + flag;
if (localStorage.getItem("mode_" + domain) != "misskey") { if (localStorage.getItem("mode_" + domain) != "misskey") {
return false; return false;
} }
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(JSON.stringify({ i: at, noteId: id, reaction: mode })); httpreq.send(JSON.stringify({ i: at, noteId: id, reaction: mode }));
httpreq.onreadystatechange = function () { httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) { if (httpreq.readyState === 4) {
if(this.status!==200){ setLog(start, this.status, this.response); } if (this.status !== 200) {
$(".fav_" + id).toggleClass("yellow-text"); setLog(start, this.status, this.response);
} }
} $(".fav_" + id).toggleClass("yellow-text");
}
};
} }
//Vote //Vote
function vote(acct_id, id, to) { function vote(acct_id, id, to) {
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/notes/polls/vote"; var start = "https://" + domain + "/api/notes/polls/vote";
if (localStorage.getItem("mode_" + domain) != "misskey") { if (localStorage.getItem("mode_" + domain) != "misskey") {
return false; return false;
} }
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(JSON.stringify({ i: at, noteId: id, choice: to })); httpreq.send(JSON.stringify({ i: at, noteId: id, choice: to }));
httpreq.onreadystatechange = function () { httpreq.onreadystatechange = function() {
voterefresh(acct_id, id) voterefresh(acct_id, id);
} };
} }
function voterefresh(acct_id, id) { function voterefresh(acct_id, id) {
var httpreqd = new XMLHttpRequest(); var httpreqd = new XMLHttpRequest();
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/notes/show"; var start = "https://" + domain + "/api/notes/show";
httpreqd.open('POST', start, true); httpreqd.open("POST", start, true);
httpreqd.setRequestHeader('Content-Type', 'application/json'); httpreqd.setRequestHeader("Content-Type", "application/json");
httpreqd.responseType = 'json'; httpreqd.responseType = "json";
httpreqd.send(JSON.stringify({ i: at, noteId: id })); httpreqd.send(JSON.stringify({ i: at, noteId: id }));
httpreqd.onreadystatechange = function () { httpreqd.onreadystatechange = function() {
if (httpreqd.readyState == 4) { if (httpreqd.readyState == 4) {
var json = httpreqd.response; var json = httpreqd.response;
if(this.status!==200){ setLog(start, this.status, json); } if (this.status !== 200) {
if (!json) { setLog(start, this.status, json);
return false; }
} if (!json) {
var poll = ""; return false;
if (json.poll) { }
var choices = json.poll.choices; var poll = "";
Object.keys(choices).forEach(function (keyc) { if (json.poll) {
var choice = choices[keyc]; var choices = json.poll.choices;
if (choice.isVoted) { Object.keys(choices).forEach(function(keyc) {
var myvote = twemoji.parse("✅"); var choice = choices[keyc];
} else { if (choice.isVoted) {
var myvote = ""; var myvote = twemoji.parse("✅");
} } else {
poll = poll + '<div class="pointer vote" onclick="vote(\'' + acct_id + '\',\'' + json.id + '\',' + choice.id + ')">' + escapeHTML(choice.text) + '(' + choice.votes + '' + myvote + ')</div>'; var myvote = "";
}); }
$(".vote_" + json.id).html(poll) poll = poll + '<div class="pointer vote" onclick="vote(\'' + acct_id + "','" + json.id + "'," + choice.id + ')">' + escapeHTML(choice.text) + "(" + choice.votes + "" + myvote + ")</div>";
} });
} $(".vote_" + json.id).html(poll);
} }
}
};
} }

View File

@ -6,38 +6,35 @@ function additional(acct_id, tlid) {
$("#timeline-container .mention").addClass("parsed"); $("#timeline-container .mention").addClass("parsed");
$("#timeline-container .hashtag, #timeline-container [rel=tag]").each(function (i, elem) { $("#timeline-container .hashtag, #timeline-container [rel=tag]").each(function(i, elem) {
var tags = $(this).attr("href").match( var tags = $(this)
/https?:\/\/([-a-zA-Z0-9@.]+)\/tags\/([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/ .attr("href")
); .match(/https?:\/\/([-a-zA-Z0-9@.]+)\/tags\/([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/);
if(tags){ if (tags) {
var tagThis = tags[2] var tagThis = tags[2];
}else{ } else {
var tagThis = $(this).attr("data-tag") var tagThis = $(this).attr("data-tag");
} }
if(tagThis){ if (tagThis) {
$(this).attr("onclick", 'tagShow(\'' + tagThis + '\')'); $(this).attr("onclick", "tagShow('" + tagThis + "')");
$(this).attr("href", "#"); $(this).attr("href", "#");
} }
}); });
//トゥートサムネ //トゥートサムネ
$("#timeline_" + tlid + " .toot a:not(.parsed)").each(function (i, elem) { $("#timeline_" + tlid + " .toot a:not(.parsed)").each(function(i, elem) {
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 card = localStorage.getItem("card_" + tlid); var card = localStorage.getItem("card_" + tlid);
var text = $(this).attr('href'); var text = $(this).attr("href");
if (text) { if (text) {
if (text.indexOf("twimg.com") === -1) { if (text.indexOf("twimg.com") === -1) {
var urls = text.match( var urls = text.match(/https?:\/\/([-a-zA-Z0-9@.]+)\/media\/([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/);
/https?:\/\/([-a-zA-Z0-9@.]+)\/media\/([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/
);
} }
} else { } else {
text = "" text = "";
var urls = [] var urls = [];
} }
//トゥートのURLぽかったら //トゥートのURLぽかったら
@ -50,50 +47,55 @@ function additional(acct_id, tlid) {
if (urls) { if (urls) {
$(this).remove(); $(this).remove();
} else if (!card) { } else if (!card) {
var id = $(this).parents('.cvo').attr("toot-id"); var id = $(this)
.parents(".cvo")
.attr("toot-id");
if (localStorage.getItem("mode_" + domain) == "misskey") { if (localStorage.getItem("mode_" + domain) == "misskey") {
var start = "https://" + domain + "/url?url=" + text; var start = "https://" + domain + "/url?url=" + text;
fetch(start, { fetch(start, {
method: 'GET', method: "GET",
headers: { headers: {
'content-type': 'application/json' "content-type": "application/json"
},
//body: JSON.stringify({})
}).then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
}).catch(function (error) {
todo(error);
console.error(error);
}).then(function (json) {
if (json.title) {
$("[toot-id=" + id + "] .additional").html(
"<span class=\"gray\">URL" + lang.lang_cards_check + ":<br>Title:" + escapeHTML(json.title) + "<br>" +
escapeHTML(json.description) + "</span>");
$("[toot-id=" + id + "] a:not(.parsed)").addClass("parsed");
$("[toot-id=" + id + "]").addClass("parsed");
} }
}); //body: JSON.stringify({})
})
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
})
.catch(function(error) {
todo(error);
setLog(start, "JSON", error);
console.error(error);
})
.then(function(json) {
if (json.title) {
$("[toot-id=" + id + "] .additional").html('<span class="gray">URL' + lang.lang_cards_check + ":<br>Title:" + escapeHTML(json.title) + "<br>" + escapeHTML(json.description) + "</span>");
$("[toot-id=" + id + "] a:not(.parsed)").addClass("parsed");
$("[toot-id=" + id + "]").addClass("parsed");
}
});
} }
} else { } else {
$(this).attr("title", text); $(this).attr("title", text);
} }
}); });
$("i.unparsed").each(function (i, elem) { $("i.unparsed").each(function(i, elem) {
var dem = $(this).text(); var dem = $(this).text();
var dom = $(this); var dom = $(this);
var start = "./js/emoji/emoji-map.json"; var start = "./js/emoji/emoji-map.json";
var xmlHttpRequest = new XMLHttpRequest(); var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.onreadystatechange = function () { xmlHttpRequest.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) { if (this.readyState === 4 && this.status === 200) {
if (this.response) { if (this.response) {
var json = this.response; var json = this.response;
if(this.status!==200){ setLog(start, this.status, this.response); } if (this.status !== 200) {
setLog(start, this.status, this.response);
}
var emojis = json.emojis; var emojis = json.emojis;
for (i = 0; i < emojis.length; i++) { for (i = 0; i < emojis.length; i++) {
var emojie = emojis[i]; var emojie = emojis[i];
@ -109,19 +111,24 @@ function additional(acct_id, tlid) {
} }
} }
} }
} };
xmlHttpRequest.open('GET', start, true); xmlHttpRequest.open("GET", start, true);
xmlHttpRequest.responseType = 'json'; xmlHttpRequest.responseType = "json";
xmlHttpRequest.send(null); xmlHttpRequest.send(null);
}); });
$("#timeline_" + tlid + " .toot:not(:has(a:not(.add-show,.parsed)))").each(function (i, elem) { $("#timeline_" + tlid + " .toot:not(:has(a:not(.add-show,.parsed)))").each(function(i, elem) {
$(this).parent().find(".add-show").hide(); $(this)
.parent()
.find(".add-show")
.hide();
}); });
//Markdownイメージビューワー //Markdownイメージビューワー
$("#timeline_" + tlid + " .toot a:not(.img-parsed):has(img)").each(function (i, elem) { $("#timeline_" + tlid + " .toot a:not(.img-parsed):has(img)").each(function(i, elem) {
var ilink = $(this).attr("href"); var ilink = $(this).attr("href");
var id = $(this).parents('.cvo').attr("toot-id"); var id = $(this)
.parents(".cvo")
.attr("toot-id");
$(this).attr("href", "#"); $(this).attr("href", "#");
$(this).attr("onclick", "imgv('" + id + "','" + i + "')"); $(this).attr("onclick", "imgv('" + id + "','" + i + "')");
$(this).attr("data-type", "image"); $(this).attr("data-type", "image");
@ -134,97 +141,97 @@ function additional(acct_id, tlid) {
function additionalIndv(tlid, acct_id, id) { function additionalIndv(tlid, acct_id, id) {
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 text = $("[toot-id=" + id + "] .toot a").attr('href'); var text = $("[toot-id=" + id + "] .toot a").attr("href");
var urls = text.match( var urls = text.match(/https?:\/\/([-a-zA-Z0-9@.]+)\/media\/([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/);
/https?:\/\/([-a-zA-Z0-9@.]+)\/media\/([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/
);
if (urls) { if (urls) {
$("[toot-id=" + id + "] .toot a").remove(); $("[toot-id=" + id + "] .toot a").remove();
} else { } else {
if (localStorage.getItem("mode_" + domain) == "misskey") { if (localStorage.getItem("mode_" + domain) == "misskey") {
var start = "https://" + domain + "/url?url=" + text; var start = "https://" + domain + "/url?url=" + text;
fetch(start, { fetch(start, {
method: 'GET', method: "GET",
headers: { headers: {
'content-type': 'application/json' "content-type": "application/json"
},
//body: JSON.stringify({})
}).then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
}).catch(function (error) {
todo(error);
console.error(error);
}).then(function (json) {
if (json.title) {
$("[toot-id=" + id + "] .additional").html(
"<span class=\"gray\">URL" + lang.lang_cards_check + ":<br>Title:" + escapeHTML(json.title) + "<br>" +
escapeHTML(json.description) + "</span>");
$("[toot-id=" + id + "] a:not(.parsed)").addClass("parsed");
$("[toot-id=" + id + "]").addClass("parsed");
} }
}); //body: JSON.stringify({})
})
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
})
.catch(function(error) {
todo(error);
setLog(start, "JSON", error);
console.error(error);
})
.then(function(json) {
if (json.title) {
$("[toot-id=" + id + "] .additional").html('<span class="gray">URL' + lang.lang_cards_check + ":<br>Title:" + escapeHTML(json.title) + "<br>" + escapeHTML(json.description) + "</span>");
$("[toot-id=" + id + "] a:not(.parsed)").addClass("parsed");
$("[toot-id=" + id + "]").addClass("parsed");
}
});
} else { } else {
var id = $("[toot-id=" + id + "] .toot a").parents('.cvo').attr("toot-id"); var id = $("[toot-id=" + id + "] .toot a")
.parents(".cvo")
.attr("toot-id");
var start = "https://" + domain + "/api/v1/statuses/" + id; var start = "https://" + domain + "/api/v1/statuses/" + id;
fetch(start, { fetch(start, {
method: 'GET', method: "GET",
headers: { headers: {
'content-type': 'application/json', "content-type": "application/json",
'Authorization': 'Bearer ' + at Authorization: "Bearer " + at
}, }
//body: JSON.stringify({}) //body: JSON.stringify({})
}).then(function (response) { })
if (!response.ok) { .then(function(response) {
response.text().then(function(text) { if (!response.ok) {
setLog(response.url, response.status, text); response.text().then(function(text) {
}); setLog(response.url, response.status, text);
} });
return response.json();
}).catch(function (error) {
todo(error);
console.error(error);
}).then(function (json) {
json = json.card;
//このリンク鳥やんけ、ってとき
if (json.provider_name == "Twitter") {
if (json.image) {
var twiImg = '<br><img src="' + json.image + '" style="max-width:100%" onclick="imgv(\'twi_' + id + '\', 0, \'twitter\');" id="twi_' + id + '-image-0" data-url="' + json.image + '" data-type="image">';
} else {
var twiImg = '';
} }
$("[toot-id=" + id + "] .additional").html( return response.json();
'<div class="twitter-tweet"><b>' + escapeHTML(json.author_name) + '</b><br>' + escapeHTML(json.description) + twiImg + '</div>'); })
} else if (json.provider_name == "pixiv") { .catch(function(error) {
if (json.image) { todo(error);
var pxvImg = '<br><img src="' + json.image + '" style="max-width:100%" onclick="imgv(\'pixiv_' + id + '\', 0, \'pixiv\');" id="pixiv_' + id + '-image-0" data-url="' + json.embed_url + '" data-type="image">'; setLog(start, "JSON", error);
console.error(error);
})
.then(function(json) {
json = json.card;
//このリンク鳥やんけ、ってとき
if (json.provider_name == "Twitter") {
if (json.image) {
var twiImg = '<br><img src="' + json.image + '" style="max-width:100%" onclick="imgv(\'twi_' + id + "', 0, 'twitter');\" id=\"twi_" + id + '-image-0" data-url="' + json.image + '" data-type="image">';
} else {
var twiImg = "";
}
$("[toot-id=" + id + "] .additional").html('<div class="twitter-tweet"><b>' + escapeHTML(json.author_name) + "</b><br>" + escapeHTML(json.description) + twiImg + "</div>");
} else if (json.provider_name == "pixiv") {
if (json.image) {
var pxvImg = '<br><img src="' + json.image + '" style="max-width:100%" onclick="imgv(\'pixiv_' + id + "', 0, 'pixiv');\" id=\"pixiv_" + id + '-image-0" data-url="' + json.embed_url + '" data-type="image">';
} else {
var pxvImg = "";
}
$("[toot-id=" + id + "] .additional").html('<div class="pixiv-post"><b><a href="' + json.author_url + '" target="_blank">' + escapeHTML(json.author_name) + "</a></b><br>" + escapeHTML(json.title) + pxvImg + "</div>");
} else { } else {
var pxvImg = ''; if (json.title) {
$("[toot-id=" + id + "] .additional").html('<span class="gray">URL' + lang.lang_cards_check + ":<br>Title:" + escapeHTML(json.title) + "<br>" + escapeHTML(json.description) + "</span>");
}
if (json.html) {
$("[toot-id=" + id + "] .additional").html(json.html + '<i class="material-icons sml pointer" onclick="pip(\'' + id + '\')" title="' + lang.lang_cards_pip + '">picture_in_picture_alt</i>');
}
} }
$("[toot-id=" + id + "] .additional").html(
'<div class="pixiv-post"><b><a href="' + json.author_url + '" target="_blank">' + escapeHTML(json.author_name) + '</a></b><br>' + escapeHTML(json.title) + pxvImg + '</div>');
} else {
if (json.title) { if (json.title) {
$("[toot-id=" + id + "] .additional").html( $("[toot-id=" + id + "] a:not(.parsed)").addClass("parsed");
"<span class=\"gray\">URL" + lang.lang_cards_check + ":<br>Title:" + escapeHTML(json.title) + "<br>" + $("[toot-id=" + id + "]").addClass("parsed");
escapeHTML(json.description) + "</span>");
} }
if (json.html) { });
$("[toot-id=" + id + "] .additional").html(json.html + '<i class="material-icons sml pointer" onclick="pip(\'' + id + '\')" title="' + lang.lang_cards_pip + '">picture_in_picture_alt</i>');
}
}
if (json.title) {
$("[toot-id=" + id + "] a:not(.parsed)").addClass("parsed");
$("[toot-id=" + id + "]").addClass("parsed");
}
});
} }
} }
} }
@ -234,11 +241,11 @@ function cardToggle(tlid) {
if (!card) { if (!card) {
localStorage.setItem("card_" + tlid, "true"); localStorage.setItem("card_" + tlid, "true");
$("#sta-card-" + tlid).text("Off"); $("#sta-card-" + tlid).text("Off");
$("#sta-card-" + tlid).css("color", 'red'); $("#sta-card-" + tlid).css("color", "red");
} else { } else {
localStorage.removeItem("card_" + tlid); localStorage.removeItem("card_" + tlid);
$("#sta-card-" + tlid).text("On"); $("#sta-card-" + tlid).text("On");
$("#sta-card-" + tlid).css("color", '#009688'); $("#sta-card-" + tlid).css("color", "#009688");
} }
} }
//各TL上方のLink[On/Off]をチェック //各TL上方のLink[On/Off]をチェック
@ -246,15 +253,15 @@ function cardCheck(tlid) {
var card = localStorage.getItem("card_" + tlid); var card = localStorage.getItem("card_" + tlid);
if (!card) { if (!card) {
$("#sta-card-" + tlid).text("On"); $("#sta-card-" + tlid).text("On");
$("#sta-card-" + tlid).css("color", '#009688'); $("#sta-card-" + tlid).css("color", "#009688");
} else { } else {
$("#sta-card-" + tlid).text("Off"); $("#sta-card-" + tlid).text("Off");
$("#sta-card-" + tlid).css("color", 'red'); $("#sta-card-" + tlid).css("color", "red");
} }
} }
function mov(id, tlid, type) { function mov(id, tlid, type) {
var click = false var click = false;
if (tlid == "notf") { if (tlid == "notf") {
var tlide = "[data-notf=" + acct_id + "]"; var tlide = "[data-notf=" + acct_id + "]";
} else if (tlid == "user") { } else if (tlid == "user") {
@ -274,21 +281,20 @@ function mov(id, tlid, type) {
} else { } else {
mouseover = "hide"; mouseover = "hide";
} }
click=true click = true;
} else if (mouseover == "no") { } else if (mouseover == "no") {
mouseover = ""; mouseover = "";
} }
if (mouseover == "hide") { if (mouseover == "hide") {
if(click){ if (click) {
$(tlide + " [toot-id=" + id + "]").toggleClass("hide-actions") $(tlide + " [toot-id=" + id + "]").toggleClass("hide-actions");
}else{ } else {
$(tlide + " [toot-id=" + id + "]").removeClass("hide-actions") $(tlide + " [toot-id=" + id + "]").removeClass("hide-actions");
} }
//$(tlide + " [toot-id=" + id + "] .area-vis").toggleClass("hide") //$(tlide + " [toot-id=" + id + "] .area-vis").toggleClass("hide")
//$(tlide + " [toot-id=" + id + "] .area-actions").toggleClass("hide") //$(tlide + " [toot-id=" + id + "] .area-actions").toggleClass("hide")
//$(tlide + " [toot-id=" + id + "] .area-side").toggleClass("hide") //$(tlide + " [toot-id=" + id + "] .area-side").toggleClass("hide")
} }
} }
@ -304,10 +310,9 @@ function resetmv(type) {
mouseover = "hide"; mouseover = "hide";
} }
if (mouseover == "hide") { if (mouseover == "hide") {
$(".cvo").addClass("hide-actions") $(".cvo").addClass("hide-actions");
//$(".area-vis").addClass("hide"); //$(".area-vis").addClass("hide");
//$(".area-actions").addClass("hide"); //$(".area-actions").addClass("hide");
//$(".area-side").addClass("hide"); //$(".area-side").addClass("hide");
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,74 +1,76 @@
//ディレクトリ //ディレクトリ
//ディレクトリトグル //ディレクトリトグル
function dirMenu() { function dirMenu() {
$("#dir-contents").html(""); $("#dir-contents").html("");
directory(); directory();
$("#left-menu div").removeClass("active"); $("#left-menu div").removeClass("active");
$("#dirMenu").addClass("active"); $("#dirMenu").addClass("active");
$(".menu-content").addClass("hide"); $(".menu-content").addClass("hide");
$("#dir-box").removeClass("hide"); $("#dir-box").removeClass("hide");
} }
function dirselCk() { function dirselCk() {
var acct = $("#dir-acct-sel").val(); var acct = $("#dir-acct-sel").val();
if (acct == "noauth") { if (acct == "noauth") {
$("#dirNoAuth").removeClass("hide"); $("#dirNoAuth").removeClass("hide");
} else { } else {
$("#dirNoAuth").addClass("hide"); $("#dirNoAuth").addClass("hide");
directory(); directory();
} }
} }
function directory(isMore) { function directory(isMore) {
var order = $("[name=sort]:checked").val() var order = $("[name=sort]:checked").val();
if (!order) { if (!order) {
order = "active" order = "active";
} }
var local_only = $("#local_only:checked").val() var local_only = $("#local_only:checked").val();
if (local_only) { if (local_only) {
local_only = "true" local_only = "true";
} else { } else {
local_only = "false" local_only = "false";
} }
var acct_id = $("#dir-acct-sel").val(); var acct_id = $("#dir-acct-sel").val();
if (acct_id == "noauth") { if (acct_id == "noauth") {
var domain = $("#dirNoAuth-url").val(); var domain = $("#dirNoAuth-url").val();
var at = ""; var at = "";
} else { } else {
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");
} }
if (isMore) { if (isMore) {
var addOffset = $("#dir-contents .cvo").length var addOffset = $("#dir-contents .cvo").length;
} else { } else {
var addOffset = 0 var addOffset = 0;
$("#dir-contents").html(""); $("#dir-contents").html("");
} }
var start = "https://" + domain + "/api/v1/directory?order=" + order + "&local=" + local_only + "&offset=" + addOffset var start = "https://" + domain + "/api/v1/directory?order=" + order + "&local=" + local_only + "&offset=" + addOffset;
console.log(start) console.log(start);
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
//todo(error); if (!response.ok) {
console.error(error); response.text().then(function(text) {
}).then(function (json) { setLog(response.url, response.status, text);
if (json) { });
$("#moreDir").removeClass("disabled") }
var html = userparse(json, null, acct_id, "dir", null) return response.json();
$("#dir-contents").append(html) })
jQuery("time.timeago").timeago(); .catch(function(error) {
} else { setLog(start, "JSON", error);
$("#moreDir").addClass("disabled") console.error(error);
} })
.then(function(json) {
}); if (json) {
$("#moreDir").removeClass("disabled");
var html = userparse(json, null, acct_id, "dir", null);
$("#dir-contents").append(html);
jQuery("time.timeago").timeago();
} else {
$("#moreDir").addClass("disabled");
}
});
} }

View File

@ -1,36 +1,38 @@
//DM(Conv) TL //DM(Conv) TL
function dm(acct_id, tlid, type, delc, voice) { function dm(acct_id, tlid, type, delc, voice) {
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/conversations"; var start = "https://" + domain + "/api/v1/conversations";
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
todo(error); if (!response.ok) {
console.error(error); response.text().then(function(text) {
}).then(function (json) { setLog(response.url, response.status, text);
var templete = '<div id="convList' + tlid + '">' + dmListParse(json, type, acct_id, tlid, "", mute) + '</div>'; });
localStorage.setItem("lastobj_" + tlid, json[0].id) }
$("#timeline_" + tlid).html(templete); return response.json();
additional(acct_id, tlid); })
jQuery("time.timeago").timeago(); .catch(function(error) {
todc(); todo(error);
//reload(type, '', acct_id, tlid, data, mute, delc,voice); setLog(start, "JSON", error);
$(window).scrollTop(0); console.error(error);
}); })
.then(function(json) {
var templete = '<div id="convList' + tlid + '">' + dmListParse(json, type, acct_id, tlid, "", mute) + "</div>";
localStorage.setItem("lastobj_" + tlid, json[0].id);
$("#timeline_" + tlid).html(templete);
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
todc();
//reload(type, '', acct_id, tlid, data, mute, delc,voice);
$(window).scrollTop(0);
});
} }
function dmmore(tlid) { function dmmore(tlid) {
var multi = localStorage.getItem("column"); var multi = localStorage.getItem("column");
@ -38,44 +40,50 @@ function dmmore(tlid) {
var acct_id = obj[tlid].domain; var acct_id = obj[tlid].domain;
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 sid = $("#timeline_" + tlid + " .cvo").last().attr("unique-id"); var sid = $("#timeline_" + tlid + " .cvo")
.last()
.attr("unique-id");
var start = "https://" + domain + "/api/v1/conversations?max_id=" + sid; var start = "https://" + domain + "/api/v1/conversations?max_id=" + sid;
var type = "dm"; var type = "dm";
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json();
}).catch(function (error) {
todo(error);
console.error(error);
}).then(function (json) {
var templete = '<div id="convList' + tlid + '">' + dmListParse(json, type, acct_id, tlid, "", mute) + '</div>';
$("#timeline_" + tlid).append(templete);
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
moreloading = false;
}) })
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
})
.catch(function(error) {
todo(error);
setLog(start, "JSON", error);
console.error(error);
})
.then(function(json) {
var templete = '<div id="convList' + tlid + '">' + dmListParse(json, type, acct_id, tlid, "", mute) + "</div>";
$("#timeline_" + tlid).append(templete);
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
moreloading = false;
});
} }
//DMオブジェクトパーサー(トゥート) //DMオブジェクトパーサー(トゥート)
function dmListParse(obj, mix, acct_id, tlid, popup, mutefilter) { function dmListParse(obj, mix, acct_id, tlid, popup, mutefilter) {
var templete = ''; var templete = "";
if (obj[0]) { if (obj[0]) {
localStorage.setItem("lastunix_" + tlid, date(obj[0].created_at, 'unix')); localStorage.setItem("lastunix_" + tlid, date(obj[0].created_at, "unix"));
} }
var actb = localStorage.getItem("action_btns"); var actb = localStorage.getItem("action_btns");
var actb = 're,rt,fav,qt,del,pin,red'; var actb = "re,rt,fav,qt,del,pin,red";
if (actb) { if (actb) {
var actb = actb.split(','); var actb = actb.split(",");
var disp = {}; var disp = {};
for (var k = 0; k < actb.length; k++) { for (var k = 0; k < actb.length; k++) {
if (k < 4) { if (k < 4) {
@ -208,7 +216,7 @@ function dmListParse(obj, mix, acct_id, tlid, popup, mutefilter) {
} }
var local = []; var local = [];
var times = []; var times = [];
Object.keys(obj).forEach(function (key) { Object.keys(obj).forEach(function(key) {
var conv_id = obj[key].id; var conv_id = obj[key].id;
var toot = obj[key].last_status; var toot = obj[key].last_status;
var dis_name = escapeHTML(toot.account.display_name); var dis_name = escapeHTML(toot.account.display_name);
@ -219,14 +227,12 @@ function dmListParse(obj, mix, acct_id, tlid, popup, mutefilter) {
} }
//絵文字があれば //絵文字があれば
if (actemojick) { if (actemojick) {
Object.keys(toot.account.emojis).forEach(function (key5) { Object.keys(toot.account.emojis).forEach(function(key5) {
var emoji = toot.account.emojis[key5]; var emoji = toot.account.emojis[key5];
var shortcode = emoji.shortcode; var shortcode = emoji.shortcode;
var emoji_url = '<img src="' + emoji.url + var emoji_url = '<img src="' + emoji.url + '" class="emoji-img" data-emoji="' + shortcode + '" alt=" :' + shortcode + ': ">';
'" class="emoji-img" data-emoji="' + shortcode + '" alt=" :' + shortcode + ': ">';
var regExp = new RegExp(":" + shortcode + ":", "g"); var regExp = new RegExp(":" + shortcode + ":", "g");
dis_name = dis_name.replace(regExp, emoji_url); dis_name = dis_name.replace(regExp, emoji_url);
}); });
} }
var noticeavatar = ""; var noticeavatar = "";
@ -242,7 +248,7 @@ function dmListParse(obj, mix, acct_id, tlid, popup, mutefilter) {
var fullname = toot.account.acct + "@" + domain; var fullname = toot.account.acct + "@" + domain;
} }
if (useremp) { if (useremp) {
Object.keys(useremp).forEach(function (key10) { Object.keys(useremp).forEach(function(key10) {
var user = useremp[key10]; var user = useremp[key10];
if (user == fullname) { if (user == fullname) {
boostback = "emphasized"; boostback = "emphasized";
@ -257,19 +263,19 @@ function dmListParse(obj, mix, acct_id, tlid, popup, mutefilter) {
var locked = ""; var locked = "";
} }
if (!toot.application) { if (!toot.application) {
var via = ''; var via = "";
viashow = "hide"; viashow = "hide";
} else { } else {
var via = escapeHTML(toot.application.name); var via = escapeHTML(toot.application.name);
//強調チェック //強調チェック
Object.keys(emp).forEach(function (key6) { Object.keys(emp).forEach(function(key6) {
var cli = emp[key6]; var cli = emp[key6];
if (cli == via) { if (cli == via) {
boostback = "emphasized"; boostback = "emphasized";
} }
}); });
//ミュートチェック //ミュートチェック
Object.keys(mute).forEach(function (key7) { Object.keys(mute).forEach(function(key7) {
var cli = mute[key7]; var cli = mute[key7];
if (cli == via) { if (cli == via) {
boostback = "hide"; boostback = "hide";
@ -284,20 +290,20 @@ function dmListParse(obj, mix, acct_id, tlid, popup, mutefilter) {
var spoil = escapeHTML(toot.spoiler_text); var spoil = escapeHTML(toot.spoiler_text);
var spoiler = "cw cw_hide_" + toot.id; var spoiler = "cw cw_hide_" + toot.id;
var api_spoil = "gray"; var api_spoil = "gray";
var spoiler_show = '<a href="#" onclick="cw_show(\'' + toot.id + var spoiler_show = '<a href="#" onclick="cw_show(\'' + toot.id + '\')" class="nex parsed">' + lang.lang_parse_cwshow + "</a><br>";
'\')" class="nex parsed">' + lang.lang_parse_cwshow + '</a><br>';
} else { } else {
var ct1 = toot.content.split('</p>').length + toot.content.split('<br />').length - 2; var ct1 = toot.content.split("</p>").length + toot.content.split("<br />").length - 2;
var ct2 = toot.content.split('</p>').length + toot.content.split('<br>').length - 2; var ct2 = toot.content.split("</p>").length + toot.content.split("<br>").length - 2;
if (ct1 > ct2) { var ct = ct1; } else { var ct = ct2; } if (ct1 > ct2) {
var ct = ct1;
} else {
var ct = ct2;
}
if ((sent < ct && $.mb_strlen($.strip_tags(toot.content)) > 5) || ($.strip_tags(toot.content).length > ltr && $.mb_strlen($.strip_tags(toot.content)) > 5)) { if ((sent < ct && $.mb_strlen($.strip_tags(toot.content)) > 5) || ($.strip_tags(toot.content).length > ltr && $.mb_strlen($.strip_tags(toot.content)) > 5)) {
var content = '<span class="gray">' + lang.lang_parse_fulltext + '</span><br>' + toot.content var content = '<span class="gray">' + lang.lang_parse_fulltext + "</span><br>" + toot.content;
var spoil = '<span class="cw-long-' + toot.id + '">' + $.mb_substr($.strip_tags( var spoil = '<span class="cw-long-' + toot.id + '">' + $.mb_substr($.strip_tags(toot.content), 0, 100) + '</span><span class="gray">' + lang.lang_parse_autofold + "</span>";
toot.content), 0, 100) +
'</span><span class="gray">' + lang.lang_parse_autofold + '</span>';
var spoiler = "cw cw_hide_" + toot.id; var spoiler = "cw cw_hide_" + toot.id;
var spoiler_show = '<a href="#" onclick="cw_show(\'' + toot.id + var spoiler_show = '<a href="#" onclick="cw_show(\'' + toot.id + '\')" class="nex parsed">' + lang.lang_parse_more + "</a><br>";
'\')" class="nex parsed">' + lang.lang_parse_more + '</a><br>';
} else { } else {
var content = toot.content; var content = toot.content;
var spoil = escapeHTML(toot.spoiler_text); var spoil = escapeHTML(toot.spoiler_text);
@ -305,14 +311,13 @@ function dmListParse(obj, mix, acct_id, tlid, popup, mutefilter) {
var spoiler_show = ""; var spoiler_show = "";
} }
} }
var urls = $.strip_tags(content).replace(/\n/g, " ").match( var urls = $.strip_tags(content)
/https?:\/\/([-a-zA-Z0-9@.]+)\/?(?!.*((media|tags)|mentions)).*([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)?/ .replace(/\n/g, " ")
); .match(/https?:\/\/([-a-zA-Z0-9@.]+)\/?(?!.*((media|tags)|mentions)).*([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)?/);
if (urls) { if (urls) {
var analyze = '<a onclick="additionalIndv(\'' + tlid + '\',' + acct_id + var analyze = "<a onclick=\"additionalIndv('" + tlid + "'," + acct_id + ",'" + id + '\')" class="add-show pointer">' + lang.lang_parse_url + "</a><br>";
',\'' + id + '\')" class="add-show pointer">' + lang.lang_parse_url + '</a><br>';
} else { } else {
var analyze = ''; var analyze = "";
} }
var viewer = ""; var viewer = "";
var hasmedia = ""; var hasmedia = "";
@ -324,11 +329,10 @@ function dmListParse(obj, mix, acct_id, tlid, popup, mutefilter) {
} }
//絵文字があれば //絵文字があれば
if (emojick) { if (emojick) {
Object.keys(toot.emojis).forEach(function (key5) { Object.keys(toot.emojis).forEach(function(key5) {
var emoji = toot.emojis[key5]; var emoji = toot.emojis[key5];
var shortcode = emoji.shortcode; var shortcode = emoji.shortcode;
var emoji_url = '<img src="' + emoji.url + var emoji_url = '<img src="' + emoji.url + '" class="emoji-img" data-emoji="' + shortcode + '" alt=" :' + shortcode + ': ">';
'" class="emoji-img" data-emoji="' + shortcode + '" alt=" :' + shortcode + ': ">';
var regExp = new RegExp(":" + shortcode + ":", "g"); var regExp = new RegExp(":" + shortcode + ":", "g");
content = content.replace(regExp, emoji_url); content = content.replace(regExp, emoji_url);
spoil = spoil.replace(regExp, emoji_url); spoil = spoil.replace(regExp, emoji_url);
@ -342,11 +346,10 @@ function dmListParse(obj, mix, acct_id, tlid, popup, mutefilter) {
} }
//絵文字があれば //絵文字があれば
if (nicoemojick) { if (nicoemojick) {
Object.keys(toot.profile_emojis).forEach(function (keynico) { Object.keys(toot.profile_emojis).forEach(function(keynico) {
var emoji = toot.profile_emojis[keynico]; var emoji = toot.profile_emojis[keynico];
var shortcode = emoji.shortcode; var shortcode = emoji.shortcode;
var emoji_url = '<img src="' + emoji.url + var emoji_url = '<img src="' + emoji.url + '" class="emoji-img" data-emoji="' + shortcode + '" alt=" :' + shortcode + ': ">';
'" class="emoji-img" data-emoji="' + shortcode + '" alt=" :' + shortcode + ': ">';
var regExp = new RegExp(":" + shortcode + ":", "g"); var regExp = new RegExp(":" + shortcode + ":", "g");
content = content.replace(regExp, emoji_url); content = content.replace(regExp, emoji_url);
spoil = spoil.replace(regExp, emoji_url); spoil = spoil.replace(regExp, emoji_url);
@ -366,21 +369,17 @@ function dmListParse(obj, mix, acct_id, tlid, popup, mutefilter) {
if (mediack) { if (mediack) {
hasmedia = "hasmedia"; hasmedia = "hasmedia";
var cwdt = 100 / toot.media_attachments.length; var cwdt = 100 / toot.media_attachments.length;
Object.keys(toot.media_attachments).forEach(function (key2) { Object.keys(toot.media_attachments).forEach(function(key2) {
var media = toot.media_attachments[key2]; var media = toot.media_attachments[key2];
var purl = media.preview_url; var purl = media.preview_url;
media_ids = media_ids + media.id + ","; media_ids = media_ids + media.id + ",";
var url = media.url; var url = media.url;
if (toot.sensitive && nsfw) { if (toot.sensitive && nsfw) {
var sense = "sensitive" var sense = "sensitive";
} else { } else {
var sense = "" var sense = "";
} }
viewer = viewer + '<a onclick="imgv(\'' + id + '\',\'' + key2 + '\',\'' + viewer = viewer + "<a onclick=\"imgv('" + id + "','" + key2 + "','" + acct_id + '\')" id="' + id + "-image-" + key2 + '" data-url="' + url + '" data-type="' + media.type + '" class="img-parsed"><img src="' + purl + '" class="' + sense + ' toot-img pointer" style="width:' + cwdt + "%; height:" + imh + 'px;"></a></span>';
acct_id + '\')" id="' + id + '-image-' + key2 + '" data-url="' + url +
'" data-type="' + media.type + '" class="img-parsed"><img src="' +
purl + '" class="' + sense +
' toot-img pointer" style="width:' + cwdt + '%; height:' + imh + 'px;"></a></span>';
}); });
media_ids = media_ids.slice(0, -1); media_ids = media_ids.slice(0, -1);
} else { } else {
@ -392,24 +391,21 @@ function dmListParse(obj, mix, acct_id, tlid, popup, mutefilter) {
//メンションであれば //メンションであれば
if (menck) { if (menck) {
mentions = ""; mentions = "";
Object.keys(toot.mentions).forEach(function (key3) { Object.keys(toot.mentions).forEach(function(key3) {
var mention = toot.mentions[key3]; var mention = toot.mentions[key3];
mentions = mentions + '<a onclick="udg(\'' + mention.id + '\',' + mentions = mentions + "<a onclick=\"udg('" + mention.id + "'," + acct_id + ')" class="pointer">@' + mention.acct + "</a> ";
acct_id + ')" class="pointer">@' + mention.acct + '</a> ';
}); });
mentions = '<div style="float:right">' + mentions + '</div>'; mentions = '<div style="float:right">' + mentions + "</div>";
} }
var tagck = toot.tags[0]; var tagck = toot.tags[0];
var tags = ""; var tags = "";
//タグであれば //タグであれば
if (tagck) { if (tagck) {
Object.keys(toot.tags).forEach(function (key4) { Object.keys(toot.tags).forEach(function(key4) {
var tag = toot.tags[key4]; var tag = toot.tags[key4];
tags = tags + '<span class="hide" data-tag="' + tag.name + '">#' + tag.name + ':<a onclick="tl(\'tag\',\'' + tag.name + '\',' + acct_id + tags = tags + '<span class="hide" data-tag="' + tag.name + '">#' + tag.name + ":<a onclick=\"tl('tag','" + tag.name + "'," + acct_id + ',\'add\')" class="pointer" title="' + lang.lang_parse_tagTL.replace("{{tag}}", "#" + tag.name) + '">TL</a> <a onclick="brInsert(\'#' + tag.name + '\')" class="pointer" title="' + lang.lang_parse_tagtoot.replace("{{tag}}", "#" + tag.name) + '">Toot</a> ' + "<a onclick=\"tagPin('" + tag.name + '\')" class="pointer" title="' + lang.lang_parse_tagpin.replace("{{tag}}", "#" + tag.name) + '">Pin</a></span> ';
',\'add\')" class="pointer" title="' + lang.lang_parse_tagTL.replace("{{tag}}", '#' + tag.name) + '">TL</a> <a onclick="brInsert(\'#' + tag.name + '\')" class="pointer" title="' + lang.lang_parse_tagtoot.replace("{{tag}}", '#' + tag.name) + '">Toot</a> ' +
'<a onclick="tagPin(\'' + tag.name + '\')" class="pointer" title="' + lang.lang_parse_tagpin.replace("{{tag}}", '#' + tag.name) + '">Pin</a></span> ';
}); });
tags = '<div style="float:right">' + tags + '</div>'; tags = '<div style="float:right">' + tags + "</div>";
} }
//アニメ再生 //アニメ再生
if (gif == "yes") { if (gif == "yes") {
@ -419,13 +415,13 @@ function dmListParse(obj, mix, acct_id, tlid, popup, mutefilter) {
} }
//ワードミュート //ワードミュート
if (wordmute) { if (wordmute) {
Object.keys(wordmute).forEach(function (key8) { Object.keys(wordmute).forEach(function(key8) {
var worde = wordmute[key8]; var worde = wordmute[key8];
if (worde) { if (worde) {
if (worde.tag) { if (worde.tag) {
var word = worde.tag; var word = worde.tag;
} else { } else {
var word = worde var word = worde;
} }
var regExp = new RegExp(word, "g"); var regExp = new RegExp(word, "g");
if ($.strip_tags(content).match(regExp)) { if ($.strip_tags(content).match(regExp)) {
@ -436,7 +432,7 @@ function dmListParse(obj, mix, acct_id, tlid, popup, mutefilter) {
} }
//ワード強調 //ワード強調
if (wordemp) { if (wordemp) {
Object.keys(wordemp).forEach(function (key9) { Object.keys(wordemp).forEach(function(key9) {
var word = wordemp[key9]; var word = wordemp[key9];
if (word) { if (word) {
var word = word.tag; var word = word.tag;
@ -465,23 +461,21 @@ function dmListParse(obj, mix, acct_id, tlid, popup, mutefilter) {
if (cards.image) { if (cards.image) {
var twiImg = '<br><img src="' + cards.image + '">'; var twiImg = '<br><img src="' + cards.image + '">';
} else { } else {
var twiImg = ''; var twiImg = "";
} }
analyze = '<blockquote class="twitter-tweet"><b>' + escapeHTML(cards.author_name) + '</b><br>' + escapeHTML(cards.description) + twiImg + '</blockquote>'; analyze = '<blockquote class="twitter-tweet"><b>' + escapeHTML(cards.author_name) + "</b><br>" + escapeHTML(cards.description) + twiImg + "</blockquote>";
} }
if (cards.title) { if (cards.title) {
analyze = "<span class=\"gray\">URL" + lang.lang_cards_check + ":<br>Title:" + escapeHTML(cards.title) + "<br>" + analyze = '<span class="gray">URL' + lang.lang_cards_check + ":<br>Title:" + escapeHTML(cards.title) + "<br>" + escapeHTML(cards.description) + "</span>";
escapeHTML(cards.description) + "</span>";
} }
if (cards.html) { if (cards.html) {
analyze = cards.html + '<i class="material-icons" onclick="pip(' + id + ')" title="' + lang.lang_cards_pip + '">picture_in_picture_alt</i>'; analyze = cards.html + '<i class="material-icons" onclick="pip(' + id + ')" title="' + lang.lang_cards_pip + '">picture_in_picture_alt</i>';
} }
} }
//Ticker //Ticker
var tickerdom = ""; var tickerdom = "";
if (ticker) { if (ticker) {
var tickerdata = localStorage.getItem("ticker") var tickerdata = localStorage.getItem("ticker");
if (tickerdata) { if (tickerdata) {
var tickerdata = JSON.parse(tickerdata); var tickerdata = JSON.parse(tickerdata);
@ -492,41 +486,13 @@ function dmListParse(obj, mix, acct_id, tlid, popup, mutefilter) {
for (var i = 0; i < tickerdata.length; i++) { for (var i = 0; i < tickerdata.length; i++) {
var value = tickerdata[i]; var value = tickerdata[i];
if (value.domain == thisdomain) { if (value.domain == thisdomain) {
var tickerdom = '<div style="background:linear-gradient(to left,transparent, ' + value.bg + ' 96%) !important; color:' + value.text + ';width:100%; height:0.9rem; font-size:0.8rem;"><img src="' + value.image + '" style="height:100%;"><span style="position:relative; top:-0.2rem;"> ' + escapeHTML(value.name) + '</span></div>'; var tickerdom = '<div style="background:linear-gradient(to left,transparent, ' + value.bg + " 96%) !important; color:" + value.text + ';width:100%; height:0.9rem; font-size:0.8rem;"><img src="' + value.image + '" style="height:100%;"><span style="position:relative; top:-0.2rem;"> ' + escapeHTML(value.name) + "</span></div>";
break; break;
} }
} }
} }
} }
templete = templete + '<div id="pub_' + toot.id + '" class="cvo ' + templete = templete + '<div id="pub_' + toot.id + '" class="cvo ' + boostback + " " + fav_app + " " + hasmedia + '" toot-id="' + id + '" unique-id="' + uniqueid + '" data-medias="' + media_ids + ' " unixtime="' + date(obj[key].created_at, "unix") + '" ' + if_notf + ' onclick="dmStatus()">' + '<div class="area-notice"><span class="gray sharesta">' + notice + home + "</span></div>" + '<div class="area-icon"><a onclick="udg(\'' + toot.account.id + "'," + acct_id + ');" user="' + toot.account.acct + '" class="udg">' + '<img src="' + avatar + '" width="40" class="prof-img" user="' + toot.account.acct + '"></a>' + noticeavatar + "</div>" + '<div class="area-display_name"><div class="flex-name"><span class="user">' + dis_name + '</span><span class="sml gray" style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis; cursor:text;"> @' + toot.account.acct + locked + "</span></div>" + '<div class="flex-time"><span class="cbadge cbadge-hover pointer waves-effect" onclick="tootUriCopy(\'' + toot.url + '\');" title="' + date(toot.created_at, "absolute") + "(" + lang.lang_parse_clickcopyurl + ')"><i class="far fa-clock-o"></i>' + date(toot.created_at, datetype) + "</span>" + "</div></div>" + '<div class="area-toot">' + tickerdom + '<span class="' + api_spoil + " cw_text_" + toot.id + '"><span class="cw_text">' + spoil + "</span>" + spoiler_show + '</span><span class="toot ' + spoiler + '">' + content + "</span>" + "" + viewer + "" + "<br><a onclick=\"details('" + toot.id + "'," + acct_id + ",'" + tlid + "','dm')\" class=\"pointer waves-effect\">" + lang.lang_parse_thread + "</a></div>" + '<div class="area-vis"></div>' + "</div></div>";
boostback + ' ' + fav_app +
' ' + hasmedia + '" toot-id="' + id + '" unique-id="' + uniqueid + '" data-medias="' + media_ids + ' " unixtime="' + date(obj[
key].created_at, 'unix') + '" ' + if_notf + ' onclick="dmStatus()">' +
'<div class="area-notice"><span class="gray sharesta">' + notice + home +
'</span></div>' +
'<div class="area-icon"><a onclick="udg(\'' + toot.account.id +
'\',' + acct_id + ');" user="' + toot.account.acct + '" class="udg">' +
'<img src="' + avatar +
'" width="40" class="prof-img" user="' + toot.account.acct +
'"></a>' + noticeavatar + '</div>' +
'<div class="area-display_name"><div class="flex-name"><span class="user">' +
dis_name +
'</span><span class="sml gray" style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis; cursor:text;"> @' +
toot.account.acct + locked + '</span></div>' +
'<div class="flex-time"><span class="cbadge cbadge-hover pointer waves-effect" onclick="tootUriCopy(\'' +
toot.url + '\');" title="' + date(toot.created_at, 'absolute') +
'(' + lang.lang_parse_clickcopyurl + ')"><i class="far fa-clock-o"></i>' +
date(toot.created_at, datetype) + '</span>' +
'</div></div>' +
'<div class="area-toot">' + tickerdom + '<span class="' +
api_spoil + ' cw_text_' + toot.id + '"><span class="cw_text">' + spoil + "</span>" + spoiler_show +
'</span><span class="toot ' + spoiler + '">' + content +
'</span>' +
'' + viewer + '' +
'<br><a onclick="details(\'' + toot.id + '\',' + acct_id +
',\'' + tlid + '\',\'dm\')" class="pointer waves-effect">' + lang.lang_parse_thread + '</a></div>' +
'<div class="area-vis"></div>' +
'</div></div>';
}); });
return templete; return templete;
} }

View File

@ -5,13 +5,13 @@ function mediaToggle(tlid) {
if (media) { if (media) {
localStorage.removeItem("media_" + tlid); localStorage.removeItem("media_" + tlid);
$("#sta-media-" + tlid).text("Off"); $("#sta-media-" + tlid).text("Off");
$("#sta-media-" + tlid).css("color", 'red'); $("#sta-media-" + tlid).css("color", "red");
$("#timeline_" + tlid).removeClass("media-filter") $("#timeline_" + tlid).removeClass("media-filter");
} else { } else {
localStorage.setItem("media_" + tlid, "true"); localStorage.setItem("media_" + tlid, "true");
$("#sta-media-" + tlid).text("On"); $("#sta-media-" + tlid).text("On");
$("#sta-media-" + tlid).css("color", '#009688'); $("#sta-media-" + tlid).css("color", "#009688");
$("#timeline_" + tlid).addClass("media-filter") $("#timeline_" + tlid).addClass("media-filter");
} }
} }
//各TL上方のBT[BTOnly/BTExc/Off] //各TL上方のBT[BTOnly/BTExc/Off]
@ -20,21 +20,21 @@ function ebtToggle(tlid) {
if (ebt == "true") { if (ebt == "true") {
localStorage.setItem("ebt_" + tlid, "but"); localStorage.setItem("ebt_" + tlid, "but");
$("#sta-bt-" + tlid).text("BT Only"); $("#sta-bt-" + tlid).text("BT Only");
$("#sta-bt-" + tlid).css("color", '#ff9800'); $("#sta-bt-" + tlid).css("color", "#ff9800");
$("#timeline_" + tlid).addClass("except-bt-filter") $("#timeline_" + tlid).addClass("except-bt-filter");
$("#timeline_" + tlid).removeClass("bt-filter") $("#timeline_" + tlid).removeClass("bt-filter");
} else if (ebt == "but") { } else if (ebt == "but") {
localStorage.removeItem("ebt_" + tlid); localStorage.removeItem("ebt_" + tlid);
$("#sta-bt-" + tlid).text("Off"); $("#sta-bt-" + tlid).text("Off");
$("#sta-bt-" + tlid).css("color", 'red'); $("#sta-bt-" + tlid).css("color", "red");
$("#timeline_" + tlid).removeClass("bt-filter") $("#timeline_" + tlid).removeClass("bt-filter");
$("#timeline_" + tlid).removeClass("except-bt-filter") $("#timeline_" + tlid).removeClass("except-bt-filter");
} else { } else {
localStorage.setItem("ebt_" + tlid, "true"); localStorage.setItem("ebt_" + tlid, "true");
$("#sta-bt-" + tlid).text("BT Ex"); $("#sta-bt-" + tlid).text("BT Ex");
$("#sta-bt-" + tlid).css("color", '#009688'); $("#sta-bt-" + tlid).css("color", "#009688");
$("#timeline_" + tlid).addClass("bt-filter") $("#timeline_" + tlid).addClass("bt-filter");
$("#timeline_" + tlid).removeClass("except-bt-filter") $("#timeline_" + tlid).removeClass("except-bt-filter");
} }
} }
//各TL上方のMedia[On/Off]をチェック //各TL上方のMedia[On/Off]をチェック
@ -42,12 +42,12 @@ function mediaCheck(tlid) {
var media = localStorage.getItem("media_" + tlid); var media = localStorage.getItem("media_" + tlid);
if (media) { if (media) {
$("#sta-media-" + tlid).text("On"); $("#sta-media-" + tlid).text("On");
$("#sta-media-" + tlid).css("color", '#009688'); $("#sta-media-" + tlid).css("color", "#009688");
$("#timeline_" + tlid).addClass("media-filter") $("#timeline_" + tlid).addClass("media-filter");
} else { } else {
$("#sta-media-" + tlid).text("Off"); $("#sta-media-" + tlid).text("Off");
$("#sta-media-" + tlid).css("color", 'red'); $("#sta-media-" + tlid).css("color", "red");
$("#timeline_" + tlid).removeClass("media-filter") $("#timeline_" + tlid).removeClass("media-filter");
} }
} }
//各TL上方のBT[On/Off]をチェック //各TL上方のBT[On/Off]をチェック
@ -55,19 +55,19 @@ function ebtCheck(tlid) {
var ebt = localStorage.getItem("ebt_" + tlid); var ebt = localStorage.getItem("ebt_" + tlid);
if (ebt == "true") { if (ebt == "true") {
$("#sta-bt-" + tlid).text("BT Ex"); $("#sta-bt-" + tlid).text("BT Ex");
$("#sta-bt-" + tlid).css("color", '#009688'); $("#sta-bt-" + tlid).css("color", "#009688");
$("#timeline_" + tlid).addClass("bt-filter") $("#timeline_" + tlid).addClass("bt-filter");
$("#timeline_" + tlid).removeClass("except-bt-filter") $("#timeline_" + tlid).removeClass("except-bt-filter");
} else if (ebt == "but") { } else if (ebt == "but") {
$("#sta-bt-" + tlid).text("BT Only"); $("#sta-bt-" + tlid).text("BT Only");
$("#sta-bt-" + tlid).css("color", '#ff9800'); $("#sta-bt-" + tlid).css("color", "#ff9800");
$("#timeline_" + tlid).addClass("except-bt-filter") $("#timeline_" + tlid).addClass("except-bt-filter");
$("#timeline_" + tlid).removeClass("bt-filter") $("#timeline_" + tlid).removeClass("bt-filter");
} else { } else {
$("#sta-bt-" + tlid).text("Off"); $("#sta-bt-" + tlid).text("Off");
$("#sta-bt-" + tlid).css("color", 'red'); $("#sta-bt-" + tlid).css("color", "red");
$("#timeline_" + tlid).removeClass("bt-filter") $("#timeline_" + tlid).removeClass("bt-filter");
$("#timeline_" + tlid).removeClass("except-bt-filter") $("#timeline_" + tlid).removeClass("except-bt-filter");
} }
} }
/* 削除追跡*/ /* 削除追跡*/
@ -76,12 +76,12 @@ function catchToggle(tlid) {
if (catchck) { if (catchck) {
localStorage.removeItem("catch_" + tlid); localStorage.removeItem("catch_" + tlid);
$("#sta-del-" + tlid).text("Off"); $("#sta-del-" + tlid).text("Off");
$("#sta-del-" + tlid).css("color", 'red'); $("#sta-del-" + tlid).css("color", "red");
parseColumn(tlid); parseColumn(tlid);
} else { } else {
localStorage.setItem("catch_" + tlid, "true"); localStorage.setItem("catch_" + tlid, "true");
$("#sta-del-" + tlid).text("On"); $("#sta-del-" + tlid).text("On");
$("#sta-del-" + tlid).css("color", '#009688'); $("#sta-del-" + tlid).css("color", "#009688");
parseColumn(tlid); parseColumn(tlid);
} }
} }
@ -89,16 +89,15 @@ function catchCheck(tlid) {
var catchck = localStorage.getItem("catch_" + tlid); var catchck = localStorage.getItem("catch_" + tlid);
if (catchck) { if (catchck) {
$("#sta-del-" + tlid).text("On"); $("#sta-del-" + tlid).text("On");
$("#sta-del-" + tlid).css("color", '#009688'); $("#sta-del-" + tlid).css("color", "#009688");
} else { } else {
$("#sta-del-" + tlid).text("Off"); $("#sta-del-" + tlid).text("Off");
$("#sta-del-" + tlid).css("color", 'red'); $("#sta-del-" + tlid).css("color", "red");
} }
} }
function delreset(tlid) { function delreset(tlid) {
$("[tlid=" + tlid + "] .by_delcatch").hide(); $("[tlid=" + tlid + "] .by_delcatch").hide();
$("[tlid=" + tlid + "] .by_delcatch").remove(); $("[tlid=" + tlid + "] .by_delcatch").remove();
} }
/*ワードフィルター機能*/ /*ワードフィルター機能*/
function filterMenu() { function filterMenu() {
@ -109,50 +108,52 @@ function filterMenu() {
} }
function filter() { function filter() {
$("#filtered-words").html(""); $("#filtered-words").html("");
$("#filter-edit-id").val("") $("#filter-edit-id").val("");
var acct_id = $("#filter-acct-sel").val(); var acct_id = $("#filter-acct-sel").val();
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/filters" var start = "https://" + domain + "/api/v1/filters";
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
todo(error); if (!response.ok) {
console.error(error); response.text().then(function(text) {
}).then(function (json) { setLog(response.url, response.status, text);
if (json) { });
var filters = "";
Object.keys(json).forEach(function (key) {
var filterword = json[key];
var context = filterword.context.join(',');
filters = filters + escapeHTML(filterword.phrase) + '<span class="sml">(for ' + context + ')</span>:<a onclick="filterEdit(\'' + filterword.id + '\',\'' + acct_id +
'\')" class="pointer">' + lang.lang_edit + '</a>/<a onclick="filterDel(' + filterword.id + ',' + acct_id +
')" class="pointer">' + lang.lang_del + '</a><br> ';
});
if (filters == "") {
filters = lang.lang_filter_nodata + "<br>";
} }
$("#filtered-words").html(filters); return response.json();
} else { })
$("#filtered-words").html(lang_filter_nodata); .catch(function(error) {
} todo(error);
}); setLog(start, "JSON", error);
console.error(error);
})
.then(function(json) {
if (json) {
var filters = "";
Object.keys(json).forEach(function(key) {
var filterword = json[key];
var context = filterword.context.join(",");
filters = filters + escapeHTML(filterword.phrase) + '<span class="sml">(for ' + context + ")</span>:<a onclick=\"filterEdit('" + filterword.id + "','" + acct_id + '\')" class="pointer">' + lang.lang_edit + '</a>/<a onclick="filterDel(' + filterword.id + "," + acct_id + ')" class="pointer">' + lang.lang_del + "</a><br> ";
});
if (filters == "") {
filters = lang.lang_filter_nodata + "<br>";
}
$("#filtered-words").html(filters);
} else {
$("#filtered-words").html(lang_filter_nodata);
}
});
} }
function filterTime(day, hour, min) { function filterTime(day, hour, min) {
$("#days_filter").val(day) $("#days_filter").val(day);
$("#hours_filter").val(hour) $("#hours_filter").val(hour);
$("#mins_filter").val(min) $("#mins_filter").val(min);
} }
function makeNewFilter() { function makeNewFilter() {
var acct_id = $("#filter-acct-sel").val(); var acct_id = $("#filter-acct-sel").val();
@ -171,7 +172,7 @@ function makeNewFilter() {
cont.push("thread"); cont.push("thread");
} }
if (!cont.length) { if (!cont.length) {
$("#filtered-words").html('Error:' + lang.lang_filter_errordegree); $("#filtered-words").html("Error:" + lang.lang_filter_errordegree);
} }
var exc = $("#except_filter:checked").val(); var exc = $("#except_filter:checked").val();
var who = $("#wholeword_filter:checked").val(); var who = $("#wholeword_filter:checked").val();
@ -183,30 +184,34 @@ function makeNewFilter() {
var at = localStorage.getItem("acct_" + acct_id + "_at"); var at = localStorage.getItem("acct_" + acct_id + "_at");
if ($("#filter-edit-id").val()) { if ($("#filter-edit-id").val()) {
var start = "https://" + domain + "/api/v1/filters/" + $("#filter-edit-id").val(); var start = "https://" + domain + "/api/v1/filters/" + $("#filter-edit-id").val();
var method = "PUT" var method = "PUT";
} else { } else {
var start = "https://" + domain + "/api/v1/filters" var start = "https://" + domain + "/api/v1/filters";
var method = "POST" var method = "POST";
} }
var httpreq = new XMLHttpRequest(); var httpreq = new XMLHttpRequest();
httpreq.open(method, start, true); httpreq.open(method, start, true);
httpreq.setRequestHeader('Content-Type', 'application/json'); httpreq.setRequestHeader("Content-Type", "application/json");
httpreq.setRequestHeader('Authorization', 'Bearer ' + at); httpreq.setRequestHeader("Authorization", "Bearer " + at);
httpreq.responseType = "json"; httpreq.responseType = "json";
httpreq.send(JSON.stringify({ httpreq.send(
phrase: phr, JSON.stringify({
context: cont, phrase: phr,
irreversible: exc, context: cont,
whole_word: who, irreversible: exc,
expires_in: time whole_word: who,
})); expires_in: time
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){ setLog(start, this.status, this.response); } if (this.status !== 200) {
setLog(start, this.status, this.response);
}
filter(); filter();
filterUpdate(acct_id) filterUpdate(acct_id);
$("#filter-add-word").val(""); $("#filter-add-word").val("");
$("#home_filter").prop("checked", false); $("#home_filter").prop("checked", false);
$("#local_filter").prop("checked", false); $("#local_filter").prop("checked", false);
@ -218,9 +223,9 @@ function makeNewFilter() {
$("#hours_filter").val("0"); $("#hours_filter").val("0");
$("#mins_filter").val("0"); $("#mins_filter").val("0");
$("#add-filter-btn").text(lang.lang_add); $("#add-filter-btn").text(lang.lang_add);
$("#filter-edit-id").val("") $("#filter-edit-id").val("");
} }
} };
} }
function filterEdit(id, acct_id) { function filterEdit(id, acct_id) {
$("#filter-add-word").val(""); $("#filter-add-word").val("");
@ -237,48 +242,52 @@ function filterEdit(id, acct_id) {
$("#filter-edit-id").val(id); $("#filter-edit-id").val(id);
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/filters/" + id var start = "https://" + domain + "/api/v1/filters/" + id;
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
todo(error); if (!response.ok) {
console.error(error); response.text().then(function(text) {
}).then(function (json) { setLog(response.url, response.status, text);
if (json) { });
var now = new Date();
now = now.getTime();
var now = Math.floor(now / 1000);
$("#filter-add-word").val(json.phrase);
Object.keys(json.context).forEach(function (key) {
var context = json.context[key];
$("[value=" + context + "]").prop("checked", true);
});
if (json.irreversible) {
$("#except_filter").prop("checked", true);
} }
if (json.whole_word) { return response.json();
$("#wholeword_filter").prop("checked", true); })
.catch(function(error) {
todo(error);
setLog(start, "JSON", error);
console.error(error);
})
.then(function(json) {
if (json) {
var now = new Date();
now = now.getTime();
var now = Math.floor(now / 1000);
$("#filter-add-word").val(json.phrase);
Object.keys(json.context).forEach(function(key) {
var context = json.context[key];
$("[value=" + context + "]").prop("checked", true);
});
if (json.irreversible) {
$("#except_filter").prop("checked", true);
}
if (json.whole_word) {
$("#wholeword_filter").prop("checked", true);
}
var expires = date(json.expires_at, "unix") - now;
var mins = Math.floor(expires / 60) % 60;
var hours = Math.floor(expires / 3600) % 24;
var days = Math.floor(expires / 3600 / 24);
$("#days_filter").val(days);
$("#hours_filter").val(hours);
$("#mins_filter").val(mins);
} }
var expires = date(json.expires_at, 'unix') - now; });
var mins = Math.floor(expires / 60) % 60;
var hours = Math.floor(expires / 3600) % 24;
var days = Math.floor(expires / 3600 / 24);
$("#days_filter").val(days);
$("#hours_filter").val(hours);
$("#mins_filter").val(mins);
}
});
} }
function filterDel(id, acct_id) { function filterDel(id, acct_id) {
var domain = localStorage.getItem("domain_" + acct_id); var domain = localStorage.getItem("domain_" + acct_id);
@ -286,43 +295,49 @@ function filterDel(id, acct_id) {
var start = "https://" + domain + "/api/v1/filters/" + id; var start = "https://" + domain + "/api/v1/filters/" + id;
var httpreq = new XMLHttpRequest(); var httpreq = new XMLHttpRequest();
httpreq.open("DELETE", start, true); httpreq.open("DELETE", start, true);
httpreq.setRequestHeader('Content-Type', 'application/json'); httpreq.setRequestHeader("Content-Type", "application/json");
httpreq.setRequestHeader('Authorization', 'Bearer ' + at); httpreq.setRequestHeader("Authorization", "Bearer " + at);
httpreq.responseType = "json"; httpreq.responseType = "json";
httpreq.send(); httpreq.send();
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){ setLog(start, this.status, this.response); } if (this.status !== 200) {
setLog(start, this.status, this.response);
}
filter(); filter();
filterUpdate(acct_id) filterUpdate(acct_id);
} }
} };
} }
function getFilter(acct_id) { function getFilter(acct_id) {
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");
if (localStorage.getItem("mode_" + domain) != "misskey") { if (localStorage.getItem("mode_" + domain) != "misskey") {
var start = "https://" + domain + "/api/v1/filters" var start = "https://" + domain + "/api/v1/filters";
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) { })
if (!response.ok) { .then(function(response) {
response.text().then(function(text) { if (!response.ok) {
setLog(response.url, response.status, text); response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
})
.catch(function(error) {
todo(error);
setLog(start, "JSON", error);
console.error(error);
})
.then(function(json) {
localStorage.setItem("filter_" + acct_id, JSON.stringify(json));
}); });
}
return response.json();
}).catch(function (error) {
todo(error);
console.error(error);
}).then(function (json) {
localStorage.setItem("filter_" + acct_id, JSON.stringify(json));
});
} else { } else {
localStorage.setItem("filter_" + acct_id, JSON.stringify({})); localStorage.setItem("filter_" + acct_id, JSON.stringify({}));
} }
@ -339,7 +354,7 @@ function getFilterType(json, type) {
type = "notifi"; type = "notifi";
} }
var mutedfilters = []; var mutedfilters = [];
Object.keys(json).forEach(function (key) { Object.keys(json).forEach(function(key) {
var filterword = json[key]; var filterword = json[key];
var phrases = filterword.phrase; var phrases = filterword.phrase;
if (filterword.context.join(",").indexOf(type) !== -1) { if (filterword.context.join(",").indexOf(type) !== -1) {
@ -351,32 +366,34 @@ function getFilterType(json, type) {
function filterUpdate(acct_id) { function filterUpdate(acct_id) {
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/filters" var start = "https://" + domain + "/api/v1/filters";
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
todo(error); if (!response.ok) {
console.error(error); response.text().then(function(text) {
}).then(function (json) { setLog(response.url, response.status, text);
localStorage.setItem("filter_" + acct_id, JSON.stringify(json)); });
filterUpdateInternal(json, "home"); }
filterUpdateInternal(json, "local"); return response.json();
filterUpdateInternal(json, "notf"); })
filterUpdateInternal(json, "pub"); .catch(function(error) {
}); todo(error);
setLog(start, "JSON", error);
console.error(error);
})
.then(function(json) {
localStorage.setItem("filter_" + acct_id, JSON.stringify(json));
filterUpdateInternal(json, "home");
filterUpdateInternal(json, "local");
filterUpdateInternal(json, "notf");
filterUpdateInternal(json, "pub");
});
} }
function filterUpdateInternal(json, type) { function filterUpdateInternal(json, type) {
var home = getFilterType(json, type); var home = getFilterType(json, type);
@ -386,11 +403,13 @@ function filterUpdateInternal(json, type) {
home = home.concat(wordmute); home = home.concat(wordmute);
} }
if (home) { if (home) {
$("[data-acct=" + acct_id + "] [data-type=" + type + "] .cvo").each(function (i, elem) { $("[data-acct=" + acct_id + "] [data-type=" + type + "] .cvo").each(function(i, elem) {
var id = $(elem).attr("toot-id"); var id = $(elem).attr("toot-id");
$("[toot-id=" + id + "]").removeClass("hide"); $("[toot-id=" + id + "]").removeClass("hide");
var text = $(elem).find('.toot').html(); var text = $(elem)
Object.keys(home).forEach(function (key8) { .find(".toot")
.html();
Object.keys(home).forEach(function(key8) {
var word = home[key8]; var word = home[key8];
var regExp = new RegExp(word.replace(/[.*+?^=!:${}()|[\]\/\\]/g, "\\$&"), "g"); var regExp = new RegExp(word.replace(/[.*+?^=!:${}()|[\]\/\\]/g, "\\$&"), "g");
if ($.strip_tags(text).match(regExp)) { if ($.strip_tags(text).match(regExp)) {
@ -408,41 +427,41 @@ function filterUpdateInternal(json, type) {
*/ */
//通知フィルター //通知フィルター
function exclude(key) { function exclude(key) {
localStorage.setItem("exclude-" + key, "") localStorage.setItem("exclude-" + key, "");
var excludetxt = localStorage.getItem("exclude-" + key); var excludetxt = localStorage.getItem("exclude-" + key);
if ($('#exc-reply-' + key + ':checked').val()) { if ($("#exc-reply-" + key + ":checked").val()) {
excludetxt = "?exclude_types[]=mention" excludetxt = "?exclude_types[]=mention";
} }
if ($('#exc-fav-' + key + ':checked').val()) { if ($("#exc-fav-" + key + ":checked").val()) {
if (excludetxt || excludetxt !="") { if (excludetxt || excludetxt != "") {
excludetxt = excludetxt + "&exclude_types[]=favourite" excludetxt = excludetxt + "&exclude_types[]=favourite";
} else { } else {
excludetxt = "?exclude_types[]=favourite" excludetxt = "?exclude_types[]=favourite";
} }
} }
if ($('#exc-bt-' + key + ':checked').val()) { if ($("#exc-bt-" + key + ":checked").val()) {
if (excludetxt || excludetxt !="") { if (excludetxt || excludetxt != "") {
excludetxt = excludetxt + "&exclude_types[]=reblog" excludetxt = excludetxt + "&exclude_types[]=reblog";
} else { } else {
excludetxt = "?exclude_types[]=reblog" excludetxt = "?exclude_types[]=reblog";
} }
} }
if ($('#exc-follow-' + key + ':checked').val()) { if ($("#exc-follow-" + key + ":checked").val()) {
if (excludetxt || excludetxt !="") { if (excludetxt || excludetxt != "") {
excludetxt = excludetxt + "&exclude_types[]=follow" excludetxt = excludetxt + "&exclude_types[]=follow";
} else { } else {
excludetxt = "?exclude_types[]=follow" excludetxt = "?exclude_types[]=follow";
} }
} }
if ($('#exc-poll-' + key + ':checked').val()) { if ($("#exc-poll-" + key + ":checked").val()) {
if (excludetxt || excludetxt !="") { if (excludetxt || excludetxt != "") {
excludetxt = excludetxt + "&exclude_types[]=poll" excludetxt = excludetxt + "&exclude_types[]=poll";
} else { } else {
excludetxt = "?exclude_types[]=poll" excludetxt = "?exclude_types[]=poll";
} }
} else { } else {
} }
localStorage.setItem("exclude-" + key, excludetxt) localStorage.setItem("exclude-" + key, excludetxt);
parseColumn(key); parseColumn(key);
} }
function excludeCk(key, target) { function excludeCk(key, target) {
@ -451,30 +470,30 @@ function excludeCk(key, target) {
return ""; return "";
} }
if (~exc.indexOf(target)) { if (~exc.indexOf(target)) {
return "checked" return "checked";
} else { } else {
return ""; return "";
} }
} }
function checkNotfFilter(tlid){ function checkNotfFilter(tlid) {
var excludetxt = localStorage.getItem("exclude-" + tlid); var excludetxt = localStorage.getItem("exclude-" + tlid);
if(!excludetxt || excludetxt != ""){ if (!excludetxt || excludetxt != "") {
return true; return true;
}else{ } else {
return false; return false;
} }
} }
function resetNotfFilter(tlid){ function resetNotfFilter(tlid) {
localStorage.setItem("exclude-" + tlid, "") localStorage.setItem("exclude-" + tlid, "");
parseColumn(tlid); parseColumn(tlid);
} }
function notfFilter(id,tlid,acct_id){ function notfFilter(id, tlid, acct_id) {
var excludetxt = localStorage.getItem("exclude-" + tlid); var excludetxt = localStorage.getItem("exclude-" + tlid);
if (excludetxt || excludetxt !="") { if (excludetxt || excludetxt != "") {
excludetxt = excludetxt + "&account_id="+id excludetxt = excludetxt + "&account_id=" + id;
} else { } else {
excludetxt = "?account_id="+id excludetxt = "?account_id=" + id;
} }
localStorage.setItem("exclude-" + tlid, excludetxt) localStorage.setItem("exclude-" + tlid, excludetxt);
parseColumn(tlid); parseColumn(tlid);
} }

View File

@ -3,78 +3,82 @@ function listMenu() {
$("#listMenu").addClass("active"); $("#listMenu").addClass("active");
$(".menu-content").addClass("hide"); $(".menu-content").addClass("hide");
$("#list-box").removeClass("hide"); $("#list-box").removeClass("hide");
$('ul.tabs').tabs('select_tab', 'src-sta'); $("ul.tabs").tabs("select_tab", "src-sta");
$("#src-contents").html(""); $("#src-contents").html("");
} }
function list() { function list() {
$("#lists-user").html(""); $("#lists-user").html("");
var acct_id = $("#list-acct-sel").val(); var acct_id = $("#list-acct-sel").val();
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");
if (localStorage.getItem("mode_" + domain) == "misskey") { if (localStorage.getItem("mode_" + domain) == "misskey") {
var start = "https://" + domain + "/api/users/lists/list" var start = "https://" + domain + "/api/users/lists/list";
fetch(start, { fetch(start, {
method: 'POST', method: "POST",
body: JSON.stringify({ body: JSON.stringify({
i: at i: at
}), })
}).then(function (response) { })
if (!response.ok) { .then(function(response) {
response.text().then(function(text) { if (!response.ok) {
setLog(response.url, response.status, text); response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
})
.catch(function(error) {
todo(error);
setLog(start, "JSON", error);
console.error(error);
})
.then(function(json) {
if (json) {
var lists = "";
Object.keys(json).forEach(function(key) {
var list = json[key];
lists = lists + escapeHTML(list.title) + ":<a onclick=\"listShow('" + list.id + "','" + escapeHTML(list.title) + "','" + acct_id + '\')" class="pointer">' + lang.lang_list_show + "</a><br>";
});
$("#lists").html(lists);
} else {
$("#lists").html(lang.lang_list_nodata);
}
}); });
}
return response.json();
}).catch(function (error) {
todo(error);
console.error(error);
}).then(function (json) {
if (json) {
var lists = "";
Object.keys(json).forEach(function (key) {
var list = json[key];
lists = lists + escapeHTML(list.title) + ':<a onclick="listShow(\'' + list.id + '\',\'' + escapeHTML(list.title) + '\',\'' + acct_id +
'\')" class="pointer">' + lang.lang_list_show + '</a><br>';
});
$("#lists").html(lists);
} else {
$("#lists").html(lang.lang_list_nodata);
}
});
} else { } else {
var start = "https://" + domain + "/api/v1/lists" var start = "https://" + domain + "/api/v1/lists";
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
}).catch(function (error) {
todo(error);
console.error(error);
}).then(function (json) {
if (json) {
var lists = "";
Object.keys(json).forEach(function (key) {
var list = json[key];
lists = lists + escapeHTML(list.title) + ':<a onclick="listShow(\'' + list.id + '\',\'' + escapeHTML(list.title) + '\',\'' + acct_id +
'\')" class="pointer">' + lang.lang_list_show + '</a>/<a onclick="listUser(\'' + list.id + '\',' + acct_id +
')" class="pointer">' + lang.lang_list_users + '</a><br>';
});
$("#lists").html(lists);
} else {
$("#lists").html(lang.lang_list_nodata);
} }
}); })
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
})
.catch(function(error) {
todo(error);
setLog(start, "JSON", error);
console.error(error);
})
.then(function(json) {
if (json) {
var lists = "";
Object.keys(json).forEach(function(key) {
var list = json[key];
lists = lists + escapeHTML(list.title) + ":<a onclick=\"listShow('" + list.id + "','" + escapeHTML(list.title) + "','" + acct_id + '\')" class="pointer">' + lang.lang_list_show + "</a>/<a onclick=\"listUser('" + list.id + "'," + acct_id + ')" class="pointer">' + lang.lang_list_users + "</a><br>";
});
$("#lists").html(lists);
} else {
$("#lists").html(lang.lang_list_nodata);
}
});
} }
} }
function makeNewList() { function makeNewList() {
@ -83,176 +87,196 @@ function makeNewList() {
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");
if (localStorage.getItem("mode_" + domain) != "misskey") { if (localStorage.getItem("mode_" + domain) != "misskey") {
var start = "https://" + domain + "/api/v1/lists" var start = "https://" + domain + "/api/v1/lists";
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.setRequestHeader('Authorization', 'Bearer ' + at); httpreq.setRequestHeader("Authorization", "Bearer " + at);
httpreq.responseType = "json"; httpreq.responseType = "json";
httpreq.send(JSON.stringify({ httpreq.send(
title: text JSON.stringify({
})); title: text
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){ setLog(start, this.status, this.response); } if (this.status !== 200) {
setLog(start, this.status, this.response);
}
list(); list();
$("#list-add").val("") $("#list-add").val("");
} }
} };
} else { } else {
var start = "https://" + domain + "/api/users/lists/create" var start = "https://" + domain + "/api/users/lists/create";
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(JSON.stringify({ httpreq.send(
i: at, JSON.stringify({
title: text i: at,
})); title: text
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){ setLog(start, this.status, this.response); } if (this.status !== 200) {
setLog(start, this.status, this.response);
}
list(); list();
$("#list-add").val("") $("#list-add").val("");
} }
} };
} }
} }
function listShow(id, title, acct_id) { function listShow(id, title, acct_id) {
localStorage.setItem("list_" + id + "_" + acct_id, title); localStorage.setItem("list_" + id + "_" + acct_id, title);
tl('list', id, acct_id, 'add'); tl("list", id, acct_id, "add");
} }
function listUser(id, acct_id) { function listUser(id, acct_id) {
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/lists/" + id + "/accounts" var start = "https://" + domain + "/api/v1/lists/" + id + "/accounts";
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
todo(error); if (!response.ok) {
console.error(error); response.text().then(function(text) {
}).then(function (json) { setLog(response.url, response.status, text);
if (json) { });
var lists = "";
var templete = userparse(json, '', acct_id);
if (!json[0]) {
templete = lang.lang_list_nouser;
} }
$("#lists-user").html(templete); return response.json();
jQuery("time.timeago").timeago(); })
} else { .catch(function(error) {
$("#lists-user").html(lang.lang_list_nouser); todo(error);
} setLog(start, "JSON", error);
}); console.error(error);
})
.then(function(json) {
if (json) {
var lists = "";
var templete = userparse(json, "", acct_id);
if (!json[0]) {
templete = lang.lang_list_nouser;
}
$("#lists-user").html(templete);
jQuery("time.timeago").timeago();
} else {
$("#lists-user").html(lang.lang_list_nouser);
}
});
} }
function hisList(user, acct_id) { function hisList(user, acct_id) {
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");
if (localStorage.getItem("mode_" + domain) != "misskey") { if (localStorage.getItem("mode_" + domain) != "misskey") {
var start = "https://" + domain + "/api/v1/lists" var start = "https://" + domain + "/api/v1/lists";
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
}).catch(function (error) {
todo(error);
console.error(error);
}).then(function (json) {
if (json) {
var lists = lang.lang_list_add + "<br>";
Object.keys(json).forEach(function (key) {
var list = json[key];
lists = lists + '<a onclick="listAdd(\'' + list.id + '\',\'' + user + '\',\'' + acct_id +
'\')" class="pointer">' + escapeHTML(list.title) + '</a><br> ';
});
$("#his-lists-a").html(lists);
} else {
$("#his-lists-a").html(lang.lang_list_nodata);
} }
}); })
var start = "https://" + domain + "/api/v1/accounts/" + user + "/lists" .then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
})
.catch(function(error) {
todo(error);
setLog(start, "JSON", error);
console.error(error);
})
.then(function(json) {
if (json) {
var lists = lang.lang_list_add + "<br>";
Object.keys(json).forEach(function(key) {
var list = json[key];
lists = lists + "<a onclick=\"listAdd('" + list.id + "','" + user + "','" + acct_id + '\')" class="pointer">' + escapeHTML(list.title) + "</a><br> ";
});
$("#his-lists-a").html(lists);
} else {
$("#his-lists-a").html(lang.lang_list_nodata);
}
});
var start = "https://" + domain + "/api/v1/accounts/" + user + "/lists";
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
}).catch(function (error) {
todo(error);
console.error(error);
}).then(function (json) {
if (json) {
var lists = lang.lang_list_remove + "<br>";
Object.keys(json).forEach(function (key) {
var list = json[key];
lists = lists + '<a onclick="listRemove(\'' + list.id + '\',\'' + user + '\',\'' + acct_id +
'\')" class="pointer">' + escapeHTML(list.title) + '</a><br> ';
});
$("#his-lists-b").html(lists);
} else {
$("#his-lists-b").html(lang.lang_list_nodata);
} }
}); })
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
})
.catch(function(error) {
todo(error);
setLog(start, "JSON", error);
console.error(error);
})
.then(function(json) {
if (json) {
var lists = lang.lang_list_remove + "<br>";
Object.keys(json).forEach(function(key) {
var list = json[key];
lists = lists + "<a onclick=\"listRemove('" + list.id + "','" + user + "','" + acct_id + '\')" class="pointer">' + escapeHTML(list.title) + "</a><br> ";
});
$("#his-lists-b").html(lists);
} else {
$("#his-lists-b").html(lang.lang_list_nodata);
}
});
} else { } else {
var start = "https://" + domain + "/api/users/lists/list" var start = "https://" + domain + "/api/users/lists/list";
fetch(start, { fetch(start, {
method: 'POST', method: "POST",
body: JSON.stringify({ body: JSON.stringify({
i: at i: at
}), })
}).then(function (response) { })
if (!response.ok) { .then(function(response) {
response.text().then(function(text) { if (!response.ok) {
setLog(response.url, response.status, text); response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
})
.catch(function(error) {
todo(error);
setLog(start, "JSON", error);
console.error(error);
})
.then(function(json) {
if (json) {
var lists = "";
Object.keys(json).forEach(function(key) {
var list = json[key];
lists = lists + list.title + ":<a onclick=\"listShow('" + list.id + "','" + escapeHTML(list.title) + "','" + acct_id + '\')" class="pointer">' + lang.lang_list_show + "</a>/<a onclick=\"listAdd('" + list.id + "','" + user + "','" + acct_id + '\')" class="pointer">' + lang.lang_list_add + lang.lang_list_add_misskey + "</a><br>";
});
$("#his-lists-a").html(lists);
} else {
$("#his-lists-a").html(lang.lang_list_nodata);
}
}); });
}
return response.json();
}).catch(function (error) {
todo(error);
console.error(error);
}).then(function (json) {
if (json) {
var lists = "";
Object.keys(json).forEach(function (key) {
var list = json[key];
lists = lists + list.title + ':<a onclick="listShow(\'' + list.id + '\',\'' + escapeHTML(list.title) + '\',\'' + acct_id +
'\')" class="pointer">' + lang.lang_list_show + '</a>/<a onclick="listAdd(\'' + list.id + '\',\'' + user + '\',\'' + acct_id +
'\')" class="pointer">' + lang.lang_list_add + lang.lang_list_add_misskey + '</a><br>';
});
$("#his-lists-a").html(lists);
} else {
$("#his-lists-a").html(lang.lang_list_nodata);
}
});
$("#his-lists-b").html(""); $("#his-lists-b").html("");
} }
} }
@ -260,61 +284,65 @@ function listAdd(id, user, acct_id) {
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");
if (localStorage.getItem("mode_" + domain) == "misskey") { if (localStorage.getItem("mode_" + domain) == "misskey") {
var start = "https://" + domain + "/api/users/lists/push" var start = "https://" + domain + "/api/users/lists/push";
var i = { var i = {
i: at, i: at,
listId: id, listId: id,
userId: user userId: user
} };
} else { } else {
var start = "https://" + domain + "/api/v1/lists/" + id + "/accounts" var start = "https://" + domain + "/api/v1/lists/" + id + "/accounts";
var i = { var i = {
account_ids: [user] account_ids: [user]
} };
} }
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.setRequestHeader('Authorization', 'Bearer ' + at); httpreq.setRequestHeader("Authorization", "Bearer " + at);
httpreq.responseType = "json"; httpreq.responseType = "json";
httpreq.send(JSON.stringify(i)); httpreq.send(JSON.stringify(i));
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){ setLog(start, this.status, this.response); } if (this.status !== 200) {
hisList(user, acct_id) setLog(start, this.status, this.response);
}
hisList(user, acct_id);
} }
} };
} }
function listRemove(id, user, acct_id) { function listRemove(id, user, acct_id) {
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");
if (localStorage.getItem("mode_" + domain) == "misskey") { if (localStorage.getItem("mode_" + domain) == "misskey") {
var start = "https://" + domain + "/api/users/lists/push" var start = "https://" + domain + "/api/users/lists/push";
var method = 'POST' var method = "POST";
var i = { var i = {
i: at, i: at,
listId: id, listId: id,
userId: user userId: user
} };
} else { } else {
var start = "https://" + domain + "/api/v1/lists/" + id + "/accounts" var start = "https://" + domain + "/api/v1/lists/" + id + "/accounts";
var method = 'DELETE' var method = "DELETE";
var i = { var i = {
account_ids: [user] account_ids: [user]
} };
} }
var httpreq = new XMLHttpRequest(); var httpreq = new XMLHttpRequest();
httpreq.open(method, start, true); httpreq.open(method, start, true);
httpreq.setRequestHeader('Content-Type', 'application/json'); httpreq.setRequestHeader("Content-Type", "application/json");
httpreq.setRequestHeader('Authorization', 'Bearer ' + at); httpreq.setRequestHeader("Authorization", "Bearer " + at);
httpreq.responseType = "json"; httpreq.responseType = "json";
httpreq.send(JSON.stringify(i)); httpreq.send(JSON.stringify(i));
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){ setLog(start, this.status, this.response); } if (this.status !== 200) {
hisList(user, acct_id) setLog(start, this.status, this.response);
}
hisList(user, acct_id);
} }
} };
} }

View File

@ -1,6 +1,6 @@
//Integrated TL //Integrated TL
function mixtl(acct_id, tlid, type, delc, voice) { function mixtl(acct_id, tlid, type, delc, voice) {
localStorage.removeItem("morelock") localStorage.removeItem("morelock");
localStorage.setItem("now", type); localStorage.setItem("now", type);
todo("Integrated TL Loading...(Local)"); todo("Integrated TL Loading...(Local)");
//まずLocal //まずLocal
@ -8,110 +8,114 @@ function mixtl(acct_id, tlid, type, delc, voice) {
var at = localStorage.getItem("acct_" + acct_id + "_at"); var at = localStorage.getItem("acct_" + acct_id + "_at");
var start = "https://" + domain + "/api/v1/timelines/public?local=true"; var start = "https://" + domain + "/api/v1/timelines/public?local=true";
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
todo(error);
console.error(error);
}).then(function (jsonL) {
var start = "https://" + domain + "/api/v1/timelines/home";
fetch(start, {
method: 'GET',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer ' + at
},
}).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);
console.error(error); console.error(error);
}).then(function (jsonH) { })
var homearr = []; .then(function(jsonL) {
var timeline = jsonL.concat(jsonH); var start = "https://" + domain + "/api/v1/timelines/home";
timeline.sort(function (a, b) { fetch(start, {
if (date(a.created_at, "unix") >= date(b.created_at, "unix")) return -1; method: "GET",
if (date(a.created_at, "unix") < date(b.created_at, "unix")) return 1; headers: {
return 0; "content-type": "application/json",
}); Authorization: "Bearer " + at
if (type == "integrated") { }
timeline.splice(20); })
} .then(function(response) {
var templete = ""; if (!response.ok) {
if (localStorage.getItem("filter_" + acct_id) != "undefined") { response.text().then(function(text) {
var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), "mix"); setLog(response.url, response.status, text);
} else { });
var mute = []; }
} return response.json();
Object.keys(timeline).forEach(function (key) { })
var pkey = key * 1 + 1; .catch(function(error) {
if (pkey < timeline.length) { todo(error);
if (date(timeline[key].created_at, "unix") != date(timeline[pkey].created_at, "unix")) { setLog(start, "JSON", error);
if (type == "integrated") { console.error(error);
templete = templete + parse([timeline[key]], '', acct_id, tlid, "", mute, "mix"); })
} else if (type == "plus") { .then(function(jsonH) {
if (timeline[key].account.acct == timeline[key].account.username) { var homearr = [];
templete = templete + parse([timeline[key]], '', acct_id, tlid, "", mute, "plus"); var timeline = jsonL.concat(jsonH);
timeline.sort(function(a, b) {
if (date(a.created_at, "unix") >= date(b.created_at, "unix")) return -1;
if (date(a.created_at, "unix") < date(b.created_at, "unix")) return 1;
return 0;
});
if (type == "integrated") {
timeline.splice(20);
}
var templete = "";
if (localStorage.getItem("filter_" + acct_id) != "undefined") {
var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), "mix");
} else {
var mute = [];
}
Object.keys(timeline).forEach(function(key) {
var pkey = key * 1 + 1;
if (pkey < timeline.length) {
if (date(timeline[key].created_at, "unix") != date(timeline[pkey].created_at, "unix")) {
if (type == "integrated") {
templete = templete + parse([timeline[key]], "", acct_id, tlid, "", mute, "mix");
} else if (type == "plus") {
if (timeline[key].account.acct == timeline[key].account.username) {
templete = templete + parse([timeline[key]], "", acct_id, tlid, "", mute, "plus");
}
}
} }
} }
} });
} $("#landing_" + tlid).hide();
$("#timeline_" + tlid).html(templete);
}); mixre(acct_id, tlid, type, mute, delc, voice);
$("#landing_" + tlid).hide(); additional(acct_id, tlid);
$("#timeline_" + tlid).html(templete); jQuery("time.timeago").timeago();
mixre(acct_id, tlid, type, mute, delc, voice); todc();
additional(acct_id, tlid); });
jQuery("time.timeago").timeago();
todc();
}); });
});
} }
//Streamingに接続 //Streamingに接続
function mixre(acct_id, tlid, TLtype, mute, delc, voice, mode) { function mixre(acct_id, tlid, TLtype, mute, delc, voice, mode) {
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");
if (localStorage.getItem("streaming_" + acct_id)) { if (localStorage.getItem("streaming_" + acct_id)) {
var wss = localStorage.getItem("streaming_" + acct_id) var wss = localStorage.getItem("streaming_" + acct_id);
} else { } else {
var wss = "wss://" + domain var wss = "wss://" + domain;
} }
var startHome = wss + var startHome = wss + "/api/v1/streaming/?stream=user&access_token=" + at;
"/api/v1/streaming/?stream=user&access_token=" + at; var startLocal = wss + "/api/v1/streaming/?stream=public:local&access_token=" + at;
var startLocal = wss +
"/api/v1/streaming/?stream=public:local&access_token=" + at;
var wshid = websocketHome.length; var wshid = websocketHome.length;
var wslid = websocketLocal.length; var wslid = websocketLocal.length;
websocketHome[wshid] = new WebSocket(startHome); websocketHome[wshid] = new WebSocket(startHome);
websocketLocal[wslid] = new WebSocket(startLocal); websocketLocal[wslid] = new WebSocket(startLocal);
websocketHome[wshid].onopen = function (mess) { websocketHome[wshid].onopen = function(mess) {
localStorage.setItem("wssH_" + tlid, wshid); localStorage.setItem("wssH_" + tlid, wshid);
console.table({ "tlid": tlid, "type": "Connect Streaming API(Integrated:Home)", "domain": domain, "message": mess }) console.table({ tlid: tlid, type: "Connect Streaming API(Integrated:Home)", domain: domain, message: mess });
$("#notice_icon_" + tlid).removeClass("red-text"); $("#notice_icon_" + tlid).removeClass("red-text");
} };
websocketLocal[wslid].onopen = function (mess) { websocketLocal[wslid].onopen = function(mess) {
localStorage.setItem("wssL_" + tlid, wslid); localStorage.setItem("wssL_" + tlid, wslid);
console.table({ "tlid": tlid, "type": "Connect Streaming API(Integrated:Local)", "domain": domain, "message": mess }) console.table({ tlid: tlid, type: "Connect Streaming API(Integrated:Local)", domain: domain, message: mess });
$("#notice_icon_" + tlid).removeClass("red-text"); $("#notice_icon_" + tlid).removeClass("red-text");
} };
websocketLocal[wslid].onmessage = function (mess) { websocketLocal[wslid].onmessage = function(mess) {
console.log(["Receive Streaming API:(Integrated:Local)", obj]); console.log(["Receive Streaming API:(Integrated:Local)", obj]);
var obj = JSON.parse(JSON.parse(mess.data).payload); var obj = JSON.parse(JSON.parse(mess.data).payload);
@ -124,19 +128,18 @@ function mixre(acct_id, tlid, TLtype, mute, delc, voice, mode) {
$("[toot-id=" + JSON.parse(mess.data).payload + "]").hide(); $("[toot-id=" + JSON.parse(mess.data).payload + "]").hide();
$("[toot-id=" + JSON.parse(mess.data).payload + "]").remove(); $("[toot-id=" + JSON.parse(mess.data).payload + "]").remove();
} }
} else if (type == "update") { } else if (type == "update") {
var templete = parse([obj], '', acct_id, tlid, "", mute); var templete = parse([obj], "", acct_id, tlid, "", mute);
if ($("#timeline_" + tlid + " [toot-id=" + obj.id + "]").length < 1) { if ($("#timeline_" + tlid + " [toot-id=" + obj.id + "]").length < 1) {
if (voice) { if (voice) {
say(obj.content) say(obj.content);
} }
var templete = parse([obj], type, acct_id, tlid, "", mute, "mix"); var templete = parse([obj], type, acct_id, tlid, "", mute, "mix");
var pool = localStorage.getItem("pool_" + tlid); var pool = localStorage.getItem("pool_" + tlid);
if (pool) { if (pool) {
pool = templete + pool; pool = templete + pool;
} else { } else {
pool = templete pool = templete;
} }
localStorage.setItem("pool_" + tlid, pool); localStorage.setItem("pool_" + tlid, pool);
@ -147,18 +150,17 @@ function mixre(acct_id, tlid, TLtype, mute, delc, voice, mode) {
} else { } else {
todo("二重取得発生中"); todo("二重取得発生中");
} }
} }
} };
websocketHome[wshid].onmessage = function (mess) { websocketHome[wshid].onmessage = function(mess) {
console.log(["Receive Streaming API:(Integrated:Home)", obj]); console.log(["Receive Streaming API:(Integrated:Home)", obj]);
var obj = JSON.parse(JSON.parse(mess.data).payload); var obj = JSON.parse(JSON.parse(mess.data).payload);
var type = JSON.parse(mess.data).event; var type = JSON.parse(mess.data).event;
if (type == "delete") { if (type == "delete") {
if (del > 10) { if (del > 10) {
reconnector(tlid, type, acct_id, data) reconnector(tlid, type, acct_id, data);
} else { } else {
localStorage.setItem("delete", del * 1 + 1) localStorage.setItem("delete", del * 1 + 1);
} }
if (delc == "true") { if (delc == "true") {
$("[toot-id=" + JSON.parse(mess.data).payload + "]").addClass("emphasized"); $("[toot-id=" + JSON.parse(mess.data).payload + "]").addClass("emphasized");
@ -170,24 +172,24 @@ function mixre(acct_id, tlid, TLtype, mute, delc, voice, mode) {
} else if (type == "update") { } else if (type == "update") {
localStorage.removeItem("delete"); localStorage.removeItem("delete");
if (TLtype == "integrated") { if (TLtype == "integrated") {
var templete = parse([obj], '', acct_id, tlid); var templete = parse([obj], "", acct_id, tlid);
} else if (TLtype == "plus") { } else if (TLtype == "plus") {
if (obj.account.acct == obj.account.username) { if (obj.account.acct == obj.account.username) {
var templete = parse([obj], '', acct_id, tlid, "", mute, "mix"); var templete = parse([obj], "", acct_id, tlid, "", mute, "mix");
} else { } else {
var templete = ""; var templete = "";
} }
} }
if ($("#timeline_" + tlid + " [toot-id=" + obj.id + "]").length < 1) { if ($("#timeline_" + tlid + " [toot-id=" + obj.id + "]").length < 1) {
if (voice) { if (voice) {
say(obj.content) say(obj.content);
} }
var templete = parse([obj], type, acct_id, tlid, "", mute, "mix"); var templete = parse([obj], type, acct_id, tlid, "", mute, "mix");
var pool = localStorage.getItem("pool_" + tlid); var pool = localStorage.getItem("pool_" + tlid);
if (pool) { if (pool) {
pool = templete + pool; pool = templete + pool;
} else { } else {
pool = templete pool = templete;
} }
localStorage.setItem("pool_" + tlid, pool); localStorage.setItem("pool_" + tlid, pool);
@ -199,13 +201,13 @@ function mixre(acct_id, tlid, TLtype, mute, delc, voice, mode) {
todo("二重取得発生中"); todo("二重取得発生中");
} }
} }
} };
websocketLocal[wslid].onerror = function (error) { websocketLocal[wslid].onerror = function(error) {
console.error('WebSocketLocal Error') console.error("WebSocketLocal Error");
console.error(error); console.error(error);
if (mode == "error") { if (mode == "error") {
$("#notice_icon_" + tlid).addClass("red-text"); $("#notice_icon_" + tlid).addClass("red-text");
todo('WebSocket Error ' + error); todo("WebSocket Error " + error);
} else { } else {
var errorct = localStorage.getItem("wserror_" + tlid) * 1 + 1; var errorct = localStorage.getItem("wserror_" + tlid) * 1 + 1;
localStorage.setItem("wserror_" + tlid, errorct); localStorage.setItem("wserror_" + tlid, errorct);
@ -214,11 +216,11 @@ function mixre(acct_id, tlid, TLtype, mute, delc, voice, mode) {
} }
} }
}; };
websocketLocal[wslid].onclose = function () { websocketLocal[wslid].onclose = function() {
console.warn('WebSocketLocal Closing:' + tlid); console.warn("WebSocketLocal Closing:" + tlid);
if (mode == "error") { if (mode == "error") {
$("#notice_icon_" + tlid).addClass("red-text"); $("#notice_icon_" + tlid).addClass("red-text");
todo('WebSocket Closed'); todo("WebSocket Closed");
} else { } else {
var errorct = localStorage.getItem("wserror_" + tlid) * 1 + 1; var errorct = localStorage.getItem("wserror_" + tlid) * 1 + 1;
localStorage.setItem("wserror_" + tlid, errorct); localStorage.setItem("wserror_" + tlid, errorct);
@ -227,11 +229,11 @@ function mixre(acct_id, tlid, TLtype, mute, delc, voice, mode) {
} }
} }
}; };
websocketHome[wshid].onerror = function (error) { websocketHome[wshid].onerror = function(error) {
console.error(['WebSocketHome Error', error]) console.error(["WebSocketHome Error", error]);
if (mode == "error") { if (mode == "error") {
$("#notice_icon_" + tlid).addClass("red-text"); $("#notice_icon_" + tlid).addClass("red-text");
todo('WebSocket Error ' + error); todo("WebSocket Error " + error);
} else { } else {
var errorct = localStorage.getItem("wserror_" + tlid) * 1 + 1; var errorct = localStorage.getItem("wserror_" + tlid) * 1 + 1;
localStorage.setItem("wserror_" + tlid, errorct); localStorage.setItem("wserror_" + tlid, errorct);
@ -240,11 +242,11 @@ function mixre(acct_id, tlid, TLtype, mute, delc, voice, mode) {
} }
} }
}; };
websocketHome[wshid].onclose = function () { websocketHome[wshid].onclose = function() {
console.warn('WebSocketHome Closing:' + tlid); console.warn("WebSocketHome Closing:" + tlid);
if (mode == "error") { if (mode == "error") {
$("#notice_icon_" + tlid).addClass("red-text"); $("#notice_icon_" + tlid).addClass("red-text");
todo('WebSocket Closed'); todo("WebSocket Closed");
} else { } else {
var errorct = localStorage.getItem("wserror_" + tlid) * 1 + 1; var errorct = localStorage.getItem("wserror_" + tlid) * 1 + 1;
localStorage.setItem("wserror_" + tlid, errorct); localStorage.setItem("wserror_" + tlid, errorct);
@ -252,9 +254,7 @@ function mixre(acct_id, tlid, TLtype, mute, delc, voice, mode) {
reconnector(tlid, TLtype, acct_id, "", "error"); reconnector(tlid, TLtype, acct_id, "", "error");
} }
} }
}; };
} }
//ある程度のスクロールで発火 //ある程度のスクロールで発火
@ -266,82 +266,88 @@ function mixmore(tlid, type) {
todo("Integrated TL MoreLoading...(Local)"); todo("Integrated TL MoreLoading...(Local)");
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 sid = $("#timeline_" + tlid + " .cvo").last().attr("unique-id"); var sid = $("#timeline_" + tlid + " .cvo")
.last()
.attr("unique-id");
var start = "https://" + domain + "/api/v1/timelines/public?local=true&max_id=" + sid; var start = "https://" + domain + "/api/v1/timelines/public?local=true&max_id=" + sid;
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
todo(error);
console.error(error);
}).then(function (jsonL) {
var start = "https://" + domain + "/api/v1/timelines/home?max_id=" + sid;
fetch(start, {
method: 'GET',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer ' + at
},
}).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);
console.error(error); console.error(error);
}).then(function (jsonH) { })
var homearr = []; .then(function(jsonL) {
var timeline = jsonL.concat(jsonH); var start = "https://" + domain + "/api/v1/timelines/home?max_id=" + sid;
timeline.sort(function (a, b) { fetch(start, {
if (date(a.created_at, "unix") > date(b.created_at, "unix")) return -1; method: "GET",
if (date(a.created_at, "unix") < date(b.created_at, "unix")) return 1; headers: {
return 0; "content-type": "application/json",
}); Authorization: "Bearer " + at
timeline.splice(20); }
var templete = ""; })
Object.keys(timeline).forEach(function (key) { .then(function(response) {
var pkey = key * 1 + 1; if (!response.ok) {
if (pkey < 20) { response.text().then(function(text) {
if (date(timeline[key].created_at, "unix") != date(timeline[pkey].created_at, "unix")) { setLog(response.url, response.status, text);
if (localStorage.getItem("filter_" + acct_id) != "undefined") { });
var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), "mix"); }
} else { return response.json();
var mute = []; })
} .catch(function(error) {
if (type == "integrated") { todo(error);
templete = templete + parse([timeline[key]], '', acct_id, tlid, "", mute, "mix"); setLog(start, "JSON", error);
} else if (type == "plus") { console.error(error);
if (timeline[key].account.acct == timeline[key].account.username) { })
templete = templete + parse([timeline[key]], '', acct_id, tlid, "", mute, "mix"); .then(function(jsonH) {
var homearr = [];
var timeline = jsonL.concat(jsonH);
timeline.sort(function(a, b) {
if (date(a.created_at, "unix") > date(b.created_at, "unix")) return -1;
if (date(a.created_at, "unix") < date(b.created_at, "unix")) return 1;
return 0;
});
timeline.splice(20);
var templete = "";
Object.keys(timeline).forEach(function(key) {
var pkey = key * 1 + 1;
if (pkey < 20) {
if (date(timeline[key].created_at, "unix") != date(timeline[pkey].created_at, "unix")) {
if (localStorage.getItem("filter_" + acct_id) != "undefined") {
var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), "mix");
} else {
var mute = [];
}
if (type == "integrated") {
templete = templete + parse([timeline[key]], "", acct_id, tlid, "", mute, "mix");
} else if (type == "plus") {
if (timeline[key].account.acct == timeline[key].account.username) {
templete = templete + parse([timeline[key]], "", acct_id, tlid, "", mute, "mix");
}
}
} }
} }
} });
}
}); $("#timeline_" + tlid).append(templete);
additional(acct_id, tlid);
$("#timeline_" + tlid).append(templete); jQuery("time.timeago").timeago();
additional(acct_id, tlid); moreloading = false;
jQuery("time.timeago").timeago(); todc();
moreloading = false; });
todc();
}); });
});
} }

View File

@ -2,9 +2,9 @@
//取得+Streaming接続 //取得+Streaming接続
function notf(acct_id, tlid, sys) { function notf(acct_id, tlid, sys) {
if (sys == "direct") { if (sys == "direct") {
notfColumn(acct_id, tlid, sys) notfColumn(acct_id, tlid, sys);
} else { } else {
notfCommon(acct_id, tlid, sys) notfCommon(acct_id, tlid, sys);
} }
} }
function notfColumn(acct_id, tlid, sys) { function notfColumn(acct_id, tlid, sys) {
@ -20,7 +20,7 @@ function notfColumn(acct_id, tlid, sys) {
var misskey = true; var misskey = true;
var start = "https://" + domain + "/api/i/notifications"; var start = "https://" + domain + "/api/i/notifications";
httpreq.open("POST", start, true); httpreq.open("POST", start, true);
httpreq.setRequestHeader('Content-Type', 'application/json'); httpreq.setRequestHeader("Content-Type", "application/json");
var body = JSON.stringify({ var body = JSON.stringify({
i: at i: at
}); });
@ -33,26 +33,28 @@ function notfColumn(acct_id, tlid, sys) {
} }
var start = "https://" + domain + "/api/v1/notifications" + exc; var start = "https://" + domain + "/api/v1/notifications" + exc;
httpreq.open("GET", start, true); httpreq.open("GET", start, true);
httpreq.setRequestHeader('Content-Type', 'application/json'); httpreq.setRequestHeader("Content-Type", "application/json");
httpreq.setRequestHeader('Authorization', 'Bearer ' + at); httpreq.setRequestHeader("Authorization", "Bearer " + at);
var body = ""; var body = "";
} }
httpreq.responseType = "json"; httpreq.responseType = "json";
httpreq.send(body); httpreq.send(body);
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){ setLog(start, this.status, this.response); } if (this.status !== 200) {
setLog(start, this.status, this.response);
}
var max_id = httpreq.getResponseHeader("link"); var max_id = httpreq.getResponseHeader("link");
if (max_id) { if (max_id) {
max_id = max_id.match(/[?&]{1}max_id=([0-9]+)/)[1] max_id = max_id.match(/[?&]{1}max_id=([0-9]+)/)[1];
} }
if (json[0]) { if (json[0]) {
var templete = ""; var templete = "";
var lastnotf = localStorage.getItem("lastnotf_" + acct_id); var lastnotf = localStorage.getItem("lastnotf_" + acct_id);
localStorage.setItem("lastnotf_" + acct_id, json[0].id); localStorage.setItem("lastnotf_" + acct_id, json[0].id);
Object.keys(json).forEach(function (key) { Object.keys(json).forEach(function(key) {
var obj = json[key]; var obj = json[key];
if (lastnotf == obj.id && key > 0 && native == "yes") { if (lastnotf == obj.id && key > 0 && native == "yes") {
var ct = key; var ct = key;
@ -64,8 +66,7 @@ function notfColumn(acct_id, tlid, sys) {
body: ct + lang.lang_notf_new, body: ct + lang.lang_notf_new,
icon: localStorage.getItem("prof_" + acct_id) icon: localStorage.getItem("prof_" + acct_id)
}; };
var n = new Notification('TheDesk:' + domain, options); var n = new Notification("TheDesk:" + domain, options);
} }
if (localStorage.getItem("filter_" + acct_id) != "undefined") { if (localStorage.getItem("filter_" + acct_id) != "undefined") {
var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), "notif"); var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), "notif");
@ -74,17 +75,16 @@ function notfColumn(acct_id, tlid, sys) {
} }
if (obj.type != "follow") { if (obj.type != "follow") {
if (misskey) { if (misskey) {
templete = templete + misskeyParse([obj], 'notf', acct_id, tlid, -1, mute); templete = templete + misskeyParse([obj], "notf", acct_id, tlid, -1, mute);
} else { } else {
templete = templete + parse([obj], 'notf', acct_id, tlid, -1, mute); templete = templete + parse([obj], "notf", acct_id, tlid, -1, mute);
} }
} else { } else {
if (misskey) { if (misskey) {
templete = templete + misskeyUserparse([obj], 'notf', acct_id, tlid, -1, mute); templete = templete + misskeyUserparse([obj], "notf", acct_id, tlid, -1, mute);
} else { } else {
templete = templete + userparse([obj.account], 'notf', acct_id, tlid, -1); templete = templete + userparse([obj.account], "notf", acct_id, tlid, -1);
} }
} }
}); });
templete = templete + '<div class="hide notif-marker" data-maxid="' + max_id + '"></div>'; templete = templete + '<div class="hide notif-marker" data-maxid="' + max_id + '"></div>';
@ -99,26 +99,23 @@ function notfColumn(acct_id, tlid, sys) {
if (markers == "yes") { if (markers == "yes") {
markers = true; markers = true;
} else { } else {
markers = false markers = false;
} }
if (markers) { if (markers) {
getMarker(tlid, "notf", acct_id) getMarker(tlid, "notf", acct_id);
} }
} }
} };
if (!misskey) { if (!misskey) {
if (localStorage.getItem("streaming_" + acct_id)) { if (localStorage.getItem("streaming_" + acct_id)) {
var wss = localStorage.getItem("streaming_" + acct_id) var wss = localStorage.getItem("streaming_" + acct_id);
} else { } else {
var wss = "wss://" + domain var wss = "wss://" + domain;
} }
var start = wss + "/api/v1/streaming/?stream=user&access_token=" + var start = wss + "/api/v1/streaming/?stream=user&access_token=" + at;
at;
} else { } else {
var start = "wss://" + domain + "/?i=" + var start = "wss://" + domain + "/?i=" + at;
at;
} }
} }
function notfCommon(acct_id, tlid, sys) { function notfCommon(acct_id, tlid, sys) {
todo("Notifications Loading..."); todo("Notifications Loading...");
@ -132,104 +129,103 @@ function notfCommon(acct_id, tlid, sys) {
var misskey = true; var misskey = true;
var start = "https://" + domain + "/api/i/notifications"; var start = "https://" + domain + "/api/i/notifications";
var i = { var i = {
method: 'POST', method: "POST",
headers: { headers: {
'content-type': 'application/json', "content-type": "application/json"
}, },
body: JSON.stringify({ body: JSON.stringify({
i: at i: at
}) })
} };
} else { } else {
var misskey = false; var misskey = false;
var start = "https://" + domain + "/api/v1/notifications"; var start = "https://" + domain + "/api/v1/notifications";
var i = { var i = {
method: 'GET', method: "GET",
headers: { headers: {
'content-type': 'application/json', "content-type": "application/json",
'Authorization': 'Bearer ' + at Authorization: "Bearer " + at
}, }
} };
} }
fetch(start, i).then(function (response) { fetch(start, i)
console.log("header to get param:" + response.headers.get('link')); .then(function(response) {
if (!response.ok) { console.log("header to get param:" + response.headers.get("link"));
response.text().then(function(text) { if (!response.ok) {
setLog(response.url, response.status, text); response.text().then(function(text) {
}); setLog(response.url, response.status, text);
} });
return response.json(); }
}).catch(function (error) { return response.json();
todo(error); })
console.error(error); .catch(function(error) {
}).then(function (json) { todo(error);
if (json[0]) { setLog(start, "JSON", error);
var templete = ""; console.error(error);
var lastnotf = localStorage.getItem("lastnotf_" + acct_id); })
localStorage.setItem("lastnotf_" + acct_id, json[0].id); .then(function(json) {
Object.keys(json).forEach(function (key) { if (json[0]) {
var obj = json[key]; var templete = "";
if (lastnotf == obj.id && key > 0 && native == "yes") { var lastnotf = localStorage.getItem("lastnotf_" + acct_id);
var ct = key; localStorage.setItem("lastnotf_" + acct_id, json[0].id);
if (key > 14) { Object.keys(json).forEach(function(key) {
ct = "15+"; var obj = json[key];
if (lastnotf == obj.id && key > 0 && native == "yes") {
var ct = key;
if (key > 14) {
ct = "15+";
}
var os = localStorage.getItem("platform");
var options = {
body: ct + lang.lang_notf_new,
icon: localStorage.getItem("prof_" + acct_id)
};
var n = new Notification("TheDesk:" + domain, options);
} }
var os = localStorage.getItem("platform"); if (localStorage.getItem("filter_" + acct_id) != "undefined") {
var options = { var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), "notif");
body: ct + lang.lang_notf_new,
icon: localStorage.getItem("prof_" + acct_id)
};
var n = new Notification('TheDesk:' + domain, options);
}
if (localStorage.getItem("filter_" + acct_id) != "undefined") {
var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), "notif");
} else {
var mute = [];
}
if (obj.type != "follow") {
if (misskey) {
templete = templete + misskeyParse([obj], 'notf', acct_id, 'notf', -1, mute);
} else { } else {
templete = templete + parse([obj], 'notf', acct_id, 'notf', -1, mute); var mute = [];
} }
} else { if (obj.type != "follow") {
if (misskey) { if (misskey) {
templete = templete + misskeyUserparse([obj], 'notf', acct_id, 'notf', -1, mute); templete = templete + misskeyParse([obj], "notf", acct_id, "notf", -1, mute);
} else {
templete = templete + parse([obj], "notf", acct_id, "notf", -1, mute);
}
} else { } else {
templete = templete + userparse([obj.account], 'notf', acct_id, 'notf', -1); if (misskey) {
templete = templete + misskeyUserparse([obj], "notf", acct_id, "notf", -1, mute);
} else {
templete = templete + userparse([obj.account], "notf", acct_id, "notf", -1);
}
} }
});
} $("div[data-notf=" + acct_id + "]").html(templete);
}); $("#landing_" + tlid).hide();
$("div[data-notf=" + acct_id + "]").html(templete); jQuery("time.timeago").timeago();
$("#landing_" + tlid).hide(); }
jQuery("time.timeago").timeago(); $("#notf-box").addClass("fetched");
} todc();
$("#notf-box").addClass("fetched"); notfWS(misskey, acct_id, tlid, domain, at);
todc(); });
notfWS(misskey, acct_id, tlid, domain, at)
});
} }
function notfWS(misskey, acct_id, tlid, domain, at) { function notfWS(misskey, acct_id, tlid, domain, at) {
if (!misskey) { if (!misskey) {
if (localStorage.getItem("streaming_" + acct_id)) { if (localStorage.getItem("streaming_" + acct_id)) {
var wss = localStorage.getItem("streaming_" + acct_id) var wss = localStorage.getItem("streaming_" + acct_id);
} else { } else {
var wss = "wss://" + domain var wss = "wss://" + domain;
} }
var start = wss + "/api/v1/streaming/?stream=user&access_token=" + var start = wss + "/api/v1/streaming/?stream=user&access_token=" + at;
at;
var wsid = websocketNotf.length; var wsid = websocketNotf.length;
websocketNotf[acct_id] = new WebSocket(start); websocketNotf[acct_id] = new WebSocket(start);
websocketNotf[acct_id].onopen = function (mess) { websocketNotf[acct_id].onopen = function(mess) {
console.table({ "acct_id": acct_id, "type": "Connect Streaming API(Notf)", "domain": domain, "message": [mess] }) console.table({ acct_id: acct_id, type: "Connect Streaming API(Notf)", domain: domain, message: [mess] });
$("i[data-notf=" + acct_id + "]").removeClass("red-text"); $("i[data-notf=" + acct_id + "]").removeClass("red-text");
};
} websocketNotf[acct_id].onmessage = function(mess) {
websocketNotf[acct_id].onmessage = function (mess) {
//console.log(["Receive Streaming API(Notf):" + acct_id + "(" + domain + ")", JSON.parse(JSON.parse(mess.data).payload)]); //console.log(["Receive Streaming API(Notf):" + acct_id + "(" + domain + ")", JSON.parse(JSON.parse(mess.data).payload)]);
var popup = localStorage.getItem("popup"); var popup = localStorage.getItem("popup");
if (!popup) { if (!popup) {
@ -243,9 +239,9 @@ function notfWS(misskey, acct_id, tlid, domain, at) {
if (!$("#unread_" + tlid + " .material-icons").hasClass("teal-text")) { if (!$("#unread_" + tlid + " .material-icons").hasClass("teal-text")) {
//markers show中はダメ //markers show中はダメ
if (obj.type != "follow") { if (obj.type != "follow") {
templete = parse([obj], 'notf', acct_id, 'notf', popup); templete = parse([obj], "notf", acct_id, "notf", popup);
} else { } else {
templete = userparse([obj], 'notf', acct_id, 'notf', popup); templete = userparse([obj], "notf", acct_id, "notf", popup);
} }
if (!$("div[data-notfIndv=" + acct_id + "_" + obj.id + "]").length) { if (!$("div[data-notfIndv=" + acct_id + "_" + obj.id + "]").length) {
$("div[data-notf=" + acct_id + "]").prepend(templete); $("div[data-notf=" + acct_id + "]").prepend(templete);
@ -257,30 +253,28 @@ function notfWS(misskey, acct_id, tlid, domain, at) {
$("[toot-id=" + obj + "]").hide(); $("[toot-id=" + obj + "]").hide();
$("[toot-id=" + obj + "]").remove(); $("[toot-id=" + obj + "]").remove();
} }
}
websocketNotf[acct_id].onerror = function (error) {
console.error('WebSocket Error ' + error);
errorct++;
console.log(errorct)
if (errorct < 3) {
notfWS(misskey, acct_id, tlid, domain, at)
}
}; };
websocketNotf[acct_id].onclose = function (error) { websocketNotf[acct_id].onerror = function(error) {
console.error('WebSocket Close ' + error); console.error("WebSocket Error " + error);
errorct++; errorct++;
console.log(errorct) console.log(errorct);
if (errorct < 3) { if (errorct < 3) {
notfWS(misskey, acct_id, tlid, domain, at) notfWS(misskey, acct_id, tlid, domain, at);
}
};
websocketNotf[acct_id].onclose = function(error) {
console.error("WebSocket Close " + error);
errorct++;
console.log(errorct);
if (errorct < 3) {
notfWS(misskey, acct_id, tlid, domain, at);
} }
}; };
} }
} }
//一定のスクロールで発火 //一定のスクロールで発火
function notfmore(tlid) { function notfmore(tlid) {
console.log({ "status": "kicked", "status": moreloading }); console.log({ status: "kicked", status: moreloading });
var multi = localStorage.getItem("column"); var multi = localStorage.getItem("column");
var obj = JSON.parse(multi); var obj = JSON.parse(multi);
var acct_id = obj[tlid].domain; var acct_id = obj[tlid].domain;
@ -289,7 +283,9 @@ function notfmore(tlid) {
} else { } else {
var data; var data;
} }
var sid = $("#timeline_" + tlid + " .notif-marker").last().attr("data-maxid"); var sid = $("#timeline_" + tlid + " .notif-marker")
.last()
.attr("data-maxid");
var at = localStorage.getItem("acct_" + acct_id + "_at"); var at = localStorage.getItem("acct_" + acct_id + "_at");
var domain = localStorage.getItem("domain_" + acct_id); var domain = localStorage.getItem("domain_" + acct_id);
if (sid && !moreloading) { if (sid && !moreloading) {
@ -299,7 +295,7 @@ function notfmore(tlid) {
var misskey = true; var misskey = true;
var start = "https://" + domain + "/api/i/notifications"; var start = "https://" + domain + "/api/i/notifications";
httpreq.open(POST, start, true); httpreq.open(POST, start, true);
httpreq.setRequestHeader('Content-Type', 'application/json'); httpreq.setRequestHeader("Content-Type", "application/json");
var body = JSON.stringify({ var body = JSON.stringify({
i: at, i: at,
untilID: sid untilID: sid
@ -313,24 +309,26 @@ function notfmore(tlid) {
} }
var start = "https://" + domain + "/api/v1/notifications" + exc; var start = "https://" + domain + "/api/v1/notifications" + exc;
httpreq.open("GET", start, true); httpreq.open("GET", start, true);
httpreq.setRequestHeader('Content-Type', 'application/json'); httpreq.setRequestHeader("Content-Type", "application/json");
httpreq.setRequestHeader('Authorization', 'Bearer ' + at); httpreq.setRequestHeader("Authorization", "Bearer " + at);
var body = ""; var body = "";
} }
httpreq.responseType = "json"; httpreq.responseType = "json";
httpreq.send(body); httpreq.send(body);
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){ setLog(start, this.status, this.response); } if (this.status !== 200) {
setLog(start, this.status, this.response);
}
console.log(["More notifications on " + tlid, json]); console.log(["More notifications on " + tlid, json]);
var max_id = httpreq.getResponseHeader("link").match(/[?&]{1}max_id=([0-9]+)/)[1]; var max_id = httpreq.getResponseHeader("link").match(/[?&]{1}max_id=([0-9]+)/)[1];
if (json[0]) { if (json[0]) {
var templete = ""; var templete = "";
var lastnotf = localStorage.getItem("lastnotf_" + acct_id); var lastnotf = localStorage.getItem("lastnotf_" + acct_id);
localStorage.setItem("lastnotf_" + acct_id, json[0].id); localStorage.setItem("lastnotf_" + acct_id, json[0].id);
Object.keys(json).forEach(function (key) { Object.keys(json).forEach(function(key) {
var obj = json[key]; var obj = json[key];
if (localStorage.getItem("filter_" + acct_id) != "undefined") { if (localStorage.getItem("filter_" + acct_id) != "undefined") {
var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), "notif"); var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), "notif");
@ -339,17 +337,16 @@ function notfmore(tlid) {
} }
if (obj.type != "follow") { if (obj.type != "follow") {
if (misskey) { if (misskey) {
templete = templete + misskeyParse([obj], 'notf', acct_id, 'notf', -1, mute); templete = templete + misskeyParse([obj], "notf", acct_id, "notf", -1, mute);
} else { } else {
templete = templete + parse([obj], 'notf', acct_id, 'notf', -1, mute); templete = templete + parse([obj], "notf", acct_id, "notf", -1, mute);
} }
} else { } else {
if (misskey) { if (misskey) {
templete = templete + misskeyUserparse([obj], 'notf', acct_id, 'notf', -1, mute); templete = templete + misskeyUserparse([obj], "notf", acct_id, "notf", -1, mute);
} else { } else {
templete = templete + userparse([obj.account], 'notf', acct_id, 'notf', -1); templete = templete + userparse([obj.account], "notf", acct_id, "notf", -1);
} }
} }
}); });
moreloading = false; moreloading = false;
@ -361,49 +358,55 @@ function notfmore(tlid) {
$("#notf-box").addClass("fetched"); $("#notf-box").addClass("fetched");
todc(); todc();
} }
} };
} }
} }
//通知トグルボタン //通知トグルボタン
function notfToggle(acct, tlid) { function notfToggle(acct, tlid) {
if ($("#notf-box_" + tlid).hasClass("column-hide")) { if ($("#notf-box_" + tlid).hasClass("column-hide")) {
$("#notf-box_" + tlid).css("display", "block") $("#notf-box_" + tlid).css("display", "block");
$("#notf-box_" + tlid).animate({ $("#notf-box_" + tlid).animate(
'height': '400px' {
}, { height: "400px"
'duration': 300, },
'complete': function () { {
$("#notf-box_" + tlid).css("overflow-y", "scroll") duration: 300,
$("#notf-box_" + tlid).removeClass("column-hide") complete: function() {
$("#notf-box_" + tlid).css("overflow-y", "scroll");
$("#notf-box_" + tlid).removeClass("column-hide");
}
} }
}); );
} else { } else {
$("#notf-box_" + tlid).css("overflow-y", "hidden") $("#notf-box_" + tlid).css("overflow-y", "hidden");
$("#notf-box_" + tlid).animate({ $("#notf-box_" + tlid).animate(
'height': '0' {
}, { height: "0"
'duration': 300, },
'complete': function () { {
$("#notf-box_" + tlid).addClass("column-hide") duration: 300,
$("#notf-box_" + tlid).css("display", "none") complete: function() {
$("#notf-box_" + tlid).addClass("column-hide");
$("#notf-box_" + tlid).css("display", "none");
}
} }
}); );
} }
notfCanceler(acct) notfCanceler(acct);
} }
function notfCanceler(acct) { function notfCanceler(acct) {
$(".notf-reply_" + acct).text(0); $(".notf-reply_" + acct).text(0);
localStorage.removeItem("notf-reply_" + acct) localStorage.removeItem("notf-reply_" + acct);
$(".notf-reply_" + acct).addClass("hide"); $(".notf-reply_" + acct).addClass("hide");
$(".notf-fav_" + acct).text(0); $(".notf-fav_" + acct).text(0);
localStorage.removeItem("notf-fav_" + acct) localStorage.removeItem("notf-fav_" + acct);
$(".notf-fav_" + acct).addClass("hide"); $(".notf-fav_" + acct).addClass("hide");
$(".notf-bt_" + acct).text(0); $(".notf-bt_" + acct).text(0);
localStorage.removeItem("notf-bt_" + acct) localStorage.removeItem("notf-bt_" + acct);
$(".notf-bt_" + acct).addClass("hide"); $(".notf-bt_" + acct).addClass("hide");
$(".notf-follow_" + acct).text(0); $(".notf-follow_" + acct).text(0);
localStorage.removeItem("notf-follow_" + acct) localStorage.removeItem("notf-follow_" + acct);
$(".notf-follow_" + acct).addClass("hide"); $(".notf-follow_" + acct).addClass("hide");
$(".notf-icon_" + acct).removeClass("red-text"); $(".notf-icon_" + acct).removeClass("red-text");
} }
@ -411,9 +414,9 @@ function allNotfRead() {
var multi = localStorage.getItem("multi"); var multi = localStorage.getItem("multi");
if (multi) { if (multi) {
var obj = JSON.parse(multi); var obj = JSON.parse(multi);
Object.keys(obj).forEach(function (key) { Object.keys(obj).forEach(function(key) {
notfCanceler(key) notfCanceler(key);
}); });
} }
} }
allNotfRead() allNotfRead();

View File

@ -1,119 +1,123 @@
//Integrated TL //Integrated TL
function mixtl(acct_id, tlid) { function mixtl(acct_id, tlid) {
var type = "mix"; var type = "mix";
localStorage.removeItem("morelock") localStorage.removeItem("morelock");
localStorage.setItem("now", type); localStorage.setItem("now", type);
todo("Integrated TL Loading...(Local)"); todo("Integrated TL Loading...(Local)");
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");
//まずLocal //まずLocal
var start = "https://" + domain + "/api/v1/timelines/public?local=true"; var start = "https://" + domain + "/api/v1/timelines/public?local=true";
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function(error) { .then(function(response) {
todo(error);
console.error(error);
}).then(function(json) {
//パースして描画
var templete = parse(json, 'mix', acct_id, tlid);
$("#timeline_" + tlid).html(templete[0]);
jQuery("time.timeago").timeago();
$(window).scrollTop(0);
var locals = templete[1];
var times = templete[2];
todo("Integrated TL Loading...(Home)");
//Home
var start = "https://" + domain + "/api/v1/timelines/home";
fetch(start, {
method: 'GET',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer ' + at
},
}).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();
}).catch(function(error) {
todo(error);
console.error(error);
}).then(function(obj) {
//ホームのオブジェクトをUnix時間で走査
if (!$("[toot-id=" + obj[0].id + "]").length) {
$("#timeline_" + tlid + " .cvo").first().before(parse([obj[0]], 'home',
acct_id));
//delete obj[0];
}
//Localが遅すぎてHomeの全てより過去の場合
var unixL=date(json[0].created_at,"unix");
var unixH=date(obj[obj.length-1].created_at,"unix");
//console.log(unixH+"vs"+unixL)
if(unixH < unixL){
Object.keys(obj).forEach(function(key) {
var skey = obj.length - key - 1;
var toot = obj[key];
console.log(toot);
var id = toot.id;
if ($("#timeline_" + tlid + " [toot-id=" + toot.id + "]").length < 1) {
//console.log(toot.id);
var tarunix = date(toot.created_at, 'unix');
var beforekey2;
var key2;
//console.log(locals)
//ホームのオブジェクトに対してLocalのオブジェクトを時間走査
Object.keys(times).forEach(function(key2) {
if (times[key2] < tarunix) {
var local = json[key2].id;
//console.log($.strip_tags(toot.content));
html = parse(
[toot], 'home', acct_id, tlid);
$("#timeline_" + tlid + " [toot-id=" + local + "]").before(html);
//console.log("#timeline_" + tlid + " [toot-id=" + local + "]");
tarunix = 0;
}
}); });
} }
}); return response.json();
}else{ })
html = parse( .catch(function(error) {
obj, 'home', acct_id, tlid); todo(error);
$("#timeline_" + tlid).html(html); setLog(start, "JSON", error);
} console.error(error);
todc(); })
mixre(acct_id, tlid); .then(function(json) {
additional(acct_id, tlid); //パースして描画
var templete = parse(json, "mix", acct_id, tlid);
$("#timeline_" + tlid).html(templete[0]);
jQuery("time.timeago").timeago(); jQuery("time.timeago").timeago();
$(window).scrollTop(0);
var locals = templete[1];
var times = templete[2];
todo("Integrated TL Loading...(Home)");
//Home
var start = "https://" + domain + "/api/v1/timelines/home";
fetch(start, {
method: "GET",
headers: {
"content-type": "application/json",
Authorization: "Bearer " + at
}
})
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
})
.catch(function(error) {
todo(error);
setLog(start, "JSON", error);
console.error(error);
})
.then(function(obj) {
//ホームのオブジェクトをUnix時間で走査
if (!$("[toot-id=" + obj[0].id + "]").length) {
$("#timeline_" + tlid + " .cvo")
.first()
.before(parse([obj[0]], "home", acct_id));
//delete obj[0];
}
//Localが遅すぎてHomeの全てより過去の場合
var unixL = date(json[0].created_at, "unix");
var unixH = date(obj[obj.length - 1].created_at, "unix");
//console.log(unixH+"vs"+unixL)
if (unixH < unixL) {
Object.keys(obj).forEach(function(key) {
var skey = obj.length - key - 1;
var toot = obj[key];
console.log(toot);
var id = toot.id;
if ($("#timeline_" + tlid + " [toot-id=" + toot.id + "]").length < 1) {
//console.log(toot.id);
var tarunix = date(toot.created_at, "unix");
var beforekey2;
var key2;
//console.log(locals)
//ホームのオブジェクトに対してLocalのオブジェクトを時間走査
Object.keys(times).forEach(function(key2) {
if (times[key2] < tarunix) {
var local = json[key2].id;
//console.log($.strip_tags(toot.content));
html = parse([toot], "home", acct_id, tlid);
$("#timeline_" + tlid + " [toot-id=" + local + "]").before(html);
//console.log("#timeline_" + tlid + " [toot-id=" + local + "]");
tarunix = 0;
}
});
}
});
} else {
html = parse(obj, "home", acct_id, tlid);
$("#timeline_" + tlid).html(html);
}
todc();
mixre(acct_id, tlid);
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
});
}); });
});
} }
//Streamingに接続 //Streamingに接続
function mixre(acct_id, tlid) { function mixre(acct_id, tlid) {
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 type = "mix"; var type = "mix";
localStorage.setItem("now", type); localStorage.setItem("now", type);
var startHome = "wss://" + domain + var startHome = "wss://" + domain + "/api/v1/streaming/?stream=user&access_token=" + at;
"/api/v1/streaming/?stream=user&access_token=" + at;
var startLocal = "wss://" + domain + var startLocal = "wss://" + domain + "/api/v1/streaming/?stream=public:local&access_token=" + at;
"/api/v1/streaming/?stream=public:local&access_token=" + at;
var wshid = websocketHome.length; var wshid = websocketHome.length;
var wslid = websocketLocal.length; var wslid = websocketLocal.length;
websocketHome[wshid] = new WebSocket(startHome); websocketHome[wshid] = new WebSocket(startHome);
@ -121,11 +125,11 @@ function mixre(acct_id, tlid) {
websocketHome[wshid].onopen = function(mess) { websocketHome[wshid].onopen = function(mess) {
console.log("Connect Streaming API(Home)"); console.log("Connect Streaming API(Home)");
$("#notice_icon_" + tlid).removeClass("red-text"); $("#notice_icon_" + tlid).removeClass("red-text");
} };
websocketLocal[wslid].onopen = function(mess) { websocketLocal[wslid].onopen = function(mess) {
console.log("Connect Streaming API(Local)"); console.log("Connect Streaming API(Local)");
$("#notice_icon_" + tlid).removeClass("red-text"); $("#notice_icon_" + tlid).removeClass("red-text");
} };
websocketLocal[wslid].onmessage = function(mess) { websocketLocal[wslid].onmessage = function(mess) {
console.log("Receive Streaming API:"); console.log("Receive Streaming API:");
@ -136,20 +140,20 @@ function mixre(acct_id, tlid) {
$("[toot-id=" + JSON.parse(mess.data).payload + "]").hide(); $("[toot-id=" + JSON.parse(mess.data).payload + "]").hide();
$("[toot-id=" + JSON.parse(mess.data).payload + "]").remove(); $("[toot-id=" + JSON.parse(mess.data).payload + "]").remove();
} else if (type == "update") { } else if (type == "update") {
var templete = parse([obj], '', acct_id, tlid); var templete = parse([obj], "", acct_id, tlid);
var pool = localStorage.getItem("pool_" + tlid); var pool = localStorage.getItem("pool_" + tlid);
if (pool) { if (pool) {
pool = templete + pool; pool = templete + pool;
} else { } else {
pool = templete pool = templete;
} }
localStorage.setItem("pool_" + tlid, pool); localStorage.setItem("pool_" + tlid, pool);
scrollck(); scrollck();
additional(acct_id, tlid); additional(acct_id, tlid);
jQuery("time.timeago").timeago(); jQuery("time.timeago").timeago();
todc(); todc();
} }
} };
websocketHome[wshid].onmessage = function(mess) { websocketHome[wshid].onmessage = function(mess) {
console.log("Receive Streaming API:(Home)"); console.log("Receive Streaming API:(Home)");
@ -160,13 +164,13 @@ function mixre(acct_id, tlid) {
$("[toot-id=" + JSON.parse(mess.data).payload + "]").hide(); $("[toot-id=" + JSON.parse(mess.data).payload + "]").hide();
$("[toot-id=" + JSON.parse(mess.data).payload + "]").remove(); $("[toot-id=" + JSON.parse(mess.data).payload + "]").remove();
} else if (type == "update") { } else if (type == "update") {
var templete = parse([obj], '', acct_id, tlid); var templete = parse([obj], "", acct_id, tlid);
if (obj.visibility != "public" || obj.account.acct != obj.account.username) { if (obj.visibility != "public" || obj.account.acct != obj.account.username) {
var pool = localStorage.getItem("pool_" + tlid); var pool = localStorage.getItem("pool_" + tlid);
if (pool) { if (pool) {
pool = templete + pool; pool = templete + pool;
} else { } else {
pool = templete pool = templete;
} }
localStorage.setItem("pool_" + tlid, pool); localStorage.setItem("pool_" + tlid, pool);
scrollck(); scrollck();
@ -174,12 +178,12 @@ function mixre(acct_id, tlid) {
jQuery("time.timeago").timeago(); jQuery("time.timeago").timeago();
} }
} }
} };
websocketLocal[wslid].onerror = function(error) { websocketLocal[wslid].onerror = function(error) {
console.error('WebSocket Error ' + error); console.error("WebSocket Error " + error);
}; };
websocketHome[wshid].onerror = function(error) { websocketHome[wshid].onerror = function(error) {
console.error('WebSocket Error ' + error); console.error("WebSocket Error " + error);
}; };
} }
@ -190,80 +194,87 @@ function mixmore(tlid) {
var acct_id = obj[tlid].domain; var acct_id = obj[tlid].domain;
todo("Integrated TL MoreLoading...(Local)"); todo("Integrated TL MoreLoading...(Local)");
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 sid = $("#timeline_" + tlid + " .cvo").last().attr("toot-id"); var sid = $("#timeline_" + tlid + " .cvo")
var len = $("#timeline_" + tlid + " .cvo").length .last()
var start = "https://" + domain + .attr("toot-id");
"/api/v1/timelines/public?local=true&max_id=" + sid; var len = $("#timeline_" + tlid + " .cvo").length;
console.log(start); var start = "https://" + domain + "/api/v1/timelines/public?local=true&max_id=" + sid;
console.log(start);
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function(error) { .then(function(response) {
todo(error);
console.error(error);
}).then(function(json) {
var templete = parse(json, 'mix', acct_id, tlid);
$("#timeline_" + tlid).append(templete[0]);
var locals = templete[1];
todo("Integrated TL MoreLoading...(Home)");
console.log(sid);
var start = "https://" + domain + "/api/v1/timelines/home?max_id=" + sid;
fetch(start, {
method: 'GET',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer ' + at
},
}).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) { })
todo(error); .catch(function(error) {
console.error(error); todo(error);
}).then(function(obj) { setLog(start, "JSON", error);
if ($("[toot-id=" + obj[0].id + "]").length < 1) { console.error(error);
$("#timeline_" + tlid + " .cvo").eq(len).before(parse([obj[0]], 'home', })
acct_id)+'<div class="divider"></div>'); .then(function(json) {
//delete obj[0]; var templete = parse(json, "mix", acct_id, tlid);
} $("#timeline_" + tlid).append(templete[0]);
Object.keys(obj).forEach(function(key) { var locals = templete[1];
var skey = obj.length - key - 1; todo("Integrated TL MoreLoading...(Home)");
var toot = obj[skey]; console.log(sid);
var id = toot.id; var start = "https://" + domain + "/api/v1/timelines/home?max_id=" + sid;
var tarunix = date(toot.created_at, 'unix'); fetch(start, {
var beforekey2; method: "GET",
var key2; headers: {
Object.keys(locals).forEach(function(key2) { "content-type": "application/json",
if ($("[toot-id=" + toot.id + "]").length <1) { Authorization: "Bearer " + at
if (key2 > tarunix) { }
var local = locals[key2]; })
$("#timeline_" + tlid + " [toot-id=" + local + "]").after(parse([toot], 'home', .then(function(response) {
acct_id, tlid)); if (!response.ok) {
tarunix = 2147483647; response.text().then(function(text) {
} setLog(response.url, response.status, text);
});
} }
return response.json();
})
.catch(function(error) {
todo(error);
setLog(start, "JSON", error);
console.error(error);
})
.then(function(obj) {
if ($("[toot-id=" + obj[0].id + "]").length < 1) {
$("#timeline_" + tlid + " .cvo")
.eq(len)
.before(parse([obj[0]], "home", acct_id) + '<div class="divider"></div>');
//delete obj[0];
}
Object.keys(obj).forEach(function(key) {
var skey = obj.length - key - 1;
var toot = obj[skey];
var id = toot.id;
var tarunix = date(toot.created_at, "unix");
var beforekey2;
var key2;
Object.keys(locals).forEach(function(key2) {
if ($("[toot-id=" + toot.id + "]").length < 1) {
if (key2 > tarunix) {
var local = locals[key2];
$("#timeline_" + tlid + " [toot-id=" + local + "]").after(parse([toot], "home", acct_id, tlid));
tarunix = 2147483647;
}
}
});
});
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
todc();
}); });
});
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
todc();
}); });
});
} }

View File

@ -14,81 +14,83 @@ function searchMenu() {
function src(mode, offset) { function src(mode, offset) {
if (!offset) { if (!offset) {
$("#src-contents").html(""); $("#src-contents").html("");
var add = "" var add = "";
} else { } else {
var add = "&type=accounts&offset=" + $("#src-accts .cvo").length var add = "&type=accounts&offset=" + $("#src-accts .cvo").length;
} }
var q = $("#src").val(); var q = $("#src").val();
var acct_id = $("#src-acct-sel").val(); var acct_id = $("#src-acct-sel").val();
if (acct_id == "tootsearch") { if (acct_id == "tootsearch") {
tsAdd(q) tsAdd(q);
return false; return false;
} }
localStorage.setItem("last-use", acct_id); localStorage.setItem("last-use", acct_id);
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 m = q.match(/^#(.+)$/); var m = q.match(/^#(.+)$/);
if (m) { q = m[1]; } if (m) {
q = m[1];
}
if (user == "--now") { if (user == "--now") {
var user = $('#his-data').attr("user-id"); var user = $("#his-data").attr("user-id");
} }
if (!mode) { if (!mode) {
var start = "https://" + domain + "/api/v2/search?q=" + q + add var start = "https://" + domain + "/api/v2/search?q=" + q + add;
} else { } else {
var start = "https://" + domain + "/api/v1/search?q=" + q var start = "https://" + domain + "/api/v1/search?q=" + q;
} }
console.log("Try to search at " + start) console.log("Try to search at " + start);
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
src("v1") if (!response.ok) {
return false; response.text().then(function(text) {
}).then(function (json) { setLog(response.url, response.status, text);
console.log(["Search", json]); });
//ハッシュタグ
if (json.hashtags[0]) {
var tags = "";
Object.keys(json.hashtags).forEach(function (key4) {
var tag = json.hashtags[key4];
if (mode) {
tags = tags + '<a onclick="tl(\'tag\',\'' + tag + '\',\'' + acct_id +
'\',\'add\')" class="pointer">#' + escapeHTML(tag) + '</a><br> ';
} else {
tags = tags + graphDraw(tag, acct_id);
}
});
$("#src-contents").append("Tags<br>" + tags);
}
//トゥート
if (json.statuses[0]) {
var templete = parse(json.statuses, '', acct_id);
$("#src-contents").append("<br>Mentions<br>" + templete);
}
//アカウント
if (json.accounts[0]) {
var templete = userparse(json.accounts, '', acct_id);
if (!offset) {
$("#src-contents").append("<br>Accounts<div id=\"src-accts\">" + templete + '</div><a onclick="src(false,\'more\')" class="pointer">more...</a>');
} else {
$("#src-accts").append(templete)
} }
return response.json();
} })
jQuery("time.timeago").timeago(); .catch(function(error) {
}); src("v1");
return false;
})
.then(function(json) {
console.log(["Search", json]);
//ハッシュタグ
if (json.hashtags[0]) {
var tags = "";
Object.keys(json.hashtags).forEach(function(key4) {
var tag = json.hashtags[key4];
if (mode) {
tags = tags + "<a onclick=\"tl('tag','" + tag + "','" + acct_id + "','add')\" class=\"pointer\">#" + escapeHTML(tag) + "</a><br> ";
} else {
tags = tags + graphDraw(tag, acct_id);
}
});
$("#src-contents").append("Tags<br>" + tags);
}
//トゥート
if (json.statuses[0]) {
var templete = parse(json.statuses, "", acct_id);
$("#src-contents").append("<br>Mentions<br>" + templete);
}
//アカウント
if (json.accounts[0]) {
var templete = userparse(json.accounts, "", acct_id);
if (!offset) {
$("#src-contents").append('<br>Accounts<div id="src-accts">' + templete + '</div><a onclick="src(false,\'more\')" class="pointer">more...</a>');
} else {
$("#src-accts").append(templete);
}
}
jQuery("time.timeago").timeago();
});
} }
function tsAdd(q) { function tsAdd(q) {
var add = { var add = {
@ -102,115 +104,120 @@ function tsAdd(q) {
obj.push(add); obj.push(add);
var json = JSON.stringify(obj); var json = JSON.stringify(obj);
localStorage.setItem("column", json); localStorage.setItem("column", json);
parseColumn('add'); parseColumn("add");
} }
function tootsearch(tlid, q) { function tootsearch(tlid, q) {
var start = "https://tootsearch.chotto.moe/api/v1/search?from=0&sort=created_at%3Adesc&q=" + q var start = "https://tootsearch.chotto.moe/api/v1/search?from=0&sort=created_at%3Adesc&q=" + q;
console.log("Toot srrach at " + start) console.log("Toot srrach at " + start);
$("#notice_" + tlid).text("tootsearch(" + q + ")"); $("#notice_" + tlid).text("tootsearch(" + q + ")");
$("#notice_icon_" + tlid).text("search"); $("#notice_icon_" + tlid).text("search");
fetch(start, { fetch(start, {
method: 'GET', method: "GET",
headers: { headers: {
'content-type': 'application/json' "content-type": "application/json"
},
}).then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
todo(error); if (!response.ok) {
console.error(error); response.text().then(function(text) {
}).then(function (raw) { setLog(response.url, response.status, text);
var templete = ""; });
var json = raw.hits.hits;
var max_id = raw["hits"].length;
for (var i = 0; i < json.length; i++) {
var toot = json[i]["_source"];
if (lastid != toot.uri) {
if (toot && toot.account) {
templete = templete + parse([toot], "noauth", null, tlid, 0, [], "tootsearch")
}
} }
var lastid = toot.uri; return response.json();
} })
if (!templete) { .catch(function(error) {
templete = lang.lang_details_nodata; todo(error);
} else { setLog(start, "JSON", error);
templete = templete + '<div class="hide ts-marker" data-maxid="' + max_id + '"></div>'; console.error(error);
} })
$("#timeline_" + tlid).html(templete); .then(function(raw) {
var templete = "";
var json = raw.hits.hits;
var max_id = raw["hits"].length;
for (var i = 0; i < json.length; i++) {
var toot = json[i]["_source"];
if (lastid != toot.uri) {
if (toot && toot.account) {
templete = templete + parse([toot], "noauth", null, tlid, 0, [], "tootsearch");
}
}
var lastid = toot.uri;
}
if (!templete) {
templete = lang.lang_details_nodata;
} else {
templete = templete + '<div class="hide ts-marker" data-maxid="' + max_id + '"></div>';
}
$("#timeline_" + tlid).html(templete);
jQuery("time.timeago").timeago(); jQuery("time.timeago").timeago();
}); });
} }
function moreTs(tlid, q) { function moreTs(tlid, q) {
var sid = $("#timeline_" + tlid + " .ts-marker").last().attr("data-maxid"); var sid = $("#timeline_" + tlid + " .ts-marker")
.last()
.attr("data-maxid");
moreloading = true; moreloading = true;
var start = "https://tootsearch.chotto.moe/api/v1/search?from=" + sid + "&sort=created_at%3Adesc&q=" + q var start = "https://tootsearch.chotto.moe/api/v1/search?from=" + sid + "&sort=created_at%3Adesc&q=" + q;
$("#notice_" + tlid).text("tootsearch(" + q + ")"); $("#notice_" + tlid).text("tootsearch(" + q + ")");
$("#notice_icon_" + tlid).text("search"); $("#notice_icon_" + tlid).text("search");
fetch(start, { fetch(start, {
method: 'GET', method: "GET",
headers: { headers: {
'content-type': 'application/json' "content-type": "application/json"
},
}).then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
todo(error); if (!response.ok) {
console.error(error); response.text().then(function(text) {
}).then(function (raw) { setLog(response.url, response.status, text);
var templete = ""; });
var json = raw.hits.hits;
var max_id = raw["hits"].length;
for (var i = 0; i < json.length; i++) {
var toot = json[i]["_source"];
if (lastid != toot.uri) {
if (toot && toot.account) {
templete = templete + parse([toot], "noauth", null, tlid, 0, [], "tootsearch")
}
} }
var lastid = toot.uri; return response.json();
} })
if (!templete) { .catch(function(error) {
templete = lang.lang_details_nodata; todo(error);
} else { setLog(start, "JSON", error);
templete = templete + '<div class="hide ts-marker" data-maxid="' + max_id + '"></div>'; console.error(error);
} })
$("#timeline_" + tlid).append(templete); .then(function(raw) {
var templete = "";
var json = raw.hits.hits;
var max_id = raw["hits"].length;
for (var i = 0; i < json.length; i++) {
var toot = json[i]["_source"];
if (lastid != toot.uri) {
if (toot && toot.account) {
templete = templete + parse([toot], "noauth", null, tlid, 0, [], "tootsearch");
}
}
var lastid = toot.uri;
}
if (!templete) {
templete = lang.lang_details_nodata;
} else {
templete = templete + '<div class="hide ts-marker" data-maxid="' + max_id + '"></div>';
}
$("#timeline_" + tlid).append(templete);
jQuery("time.timeago").timeago(); jQuery("time.timeago").timeago();
}); });
} }
function graphDraw(tag, acct_id) { function graphDraw(tag, acct_id) {
var tags = ""; var tags = "";
var his = tag.history; var his = tag.history;
var max = Math.max.apply(null, [his[0].uses, his[1].uses, his[2].uses, his[3].uses, his[4].uses, his[5].uses, his[6].uses]); var max = Math.max.apply(null, [his[0].uses, his[1].uses, his[2].uses, his[3].uses, his[4].uses, his[5].uses, his[6].uses]);
var six = 50 - (his[6].uses / max * 50); var six = 50 - (his[6].uses / max) * 50;
var five = 50 - (his[5].uses / max * 50); var five = 50 - (his[5].uses / max) * 50;
var four = 50 - (his[4].uses / max * 50); var four = 50 - (his[4].uses / max) * 50;
var three = 50 - (his[3].uses / max * 50); var three = 50 - (his[3].uses / max) * 50;
var two = 50 - (his[2].uses / max * 50); var two = 50 - (his[2].uses / max) * 50;
var one = 50 - (his[1].uses / max * 50); var one = 50 - (his[1].uses / max) * 50;
var zero = 50 - (his[0].uses / max * 50); var zero = 50 - (his[0].uses / max) * 50;
if (max === 0) { if (max === 0) {
tags = '<br><br><svg version="1.1" viewbox="0 0 60 50" width="60" height="50">' + tags = '<br><br><svg version="1.1" viewbox="0 0 60 50" width="60" height="50">' + '</svg><span style="font-size:200%">' + his[0].uses + "</span>toot(s)&nbsp;<a onclick=\"tl('tag','" + escapeHTML(tag.name) + "','" + acct_id + "','add')\" class=\"pointer\">#" + escapeHTML(tag.name) + "</a>&nbsp;" + his[0].accounts + lang.lang_src_people;
'</svg><span style="font-size:200%">' + his[0].uses + '</span>toot(s)&nbsp;<a onclick="tl(\'tag\',\'' + escapeHTML(tag.name) + '\',\'' + acct_id +
'\',\'add\')" class="pointer">#' + escapeHTML(tag.name) + '</a>&nbsp;' + his[0].accounts + lang.lang_src_people;
} else { } else {
tags = '<br><br><svg version="1.1" viewbox="0 0 60 50" width="60" height="50">' + tags = '<br><br><svg version="1.1" viewbox="0 0 60 50" width="60" height="50">' + '<g><path d="M0,' + six + " L10," + five + " 20," + four + " 30," + three + " 40," + two + " 50," + one + " 60," + zero + '" style="stroke: #9e9e9e; stroke-width: 1;fill: none;"></path></g>' + '</svg><span style="font-size:200%">' + his[0].uses + "</span>toot&nbsp;<a onclick=\"tl('tag','" + escapeHTML(tag.name) + "','" + acct_id + "','add')\" class=\"pointer\">#" + escapeHTML(tag.name) + "</a>&nbsp;" + his[0].accounts + lang.lang_src_people;
'<g><path d="M0,' + six + ' L10,' + five + ' 20,' + four + ' 30,' + three + ' 40,' + two + ' 50,' + one + ' 60,' + zero + '" style="stroke: #9e9e9e; stroke-width: 1;fill: none;"></path></g>' +
'</svg><span style="font-size:200%">' + his[0].uses + '</span>toot&nbsp;<a onclick="tl(\'tag\',\'' + escapeHTML(tag.name) + '\',\'' + acct_id +
'\',\'add\')" class="pointer">#' + escapeHTML(tag.name) + '</a>&nbsp;' + his[0].accounts + lang.lang_src_people;
} }
return tags; return tags;
@ -221,7 +228,7 @@ function graphDraw(tag, acct_id) {
</svg> </svg>
*/ */
function trend() { function trend() {
console.log("get trend") console.log("get trend");
$("#src-contents").html(""); $("#src-contents").html("");
var acct_id = $("#src-acct-sel").val(); var acct_id = $("#src-acct-sel").val();
if (acct_id == "tootsearch") { if (acct_id == "tootsearch") {
@ -229,44 +236,43 @@ function trend() {
} }
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/trends" var start = "https://" + domain + "/api/v1/trends";
console.log(start) console.log(start);
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
//todo(error); if (!response.ok) {
console.error(error); response.text().then(function(text) {
}).then(function (json) { setLog(response.url, response.status, text);
var tags = ""; });
Object.keys(json).forEach(function (keye) { }
var tag = json[keye]; return response.json();
var his = tag.history; })
var max = Math.max.apply(null, [his[0].uses, his[1].uses, his[2].uses, his[3].uses, his[4].uses, his[5].uses, his[6].uses]); .catch(function(error) {
var six = 50 - (his[6].uses / max * 50); setLog(start, "JSON", error);
var five = 50 - (his[5].uses / max * 50); console.error(error);
var four = 50 - (his[4].uses / max * 50); })
var three = 50 - (his[3].uses / max * 50); .then(function(json) {
var two = 50 - (his[2].uses / max * 50); var tags = "";
var one = 50 - (his[1].uses / max * 50); Object.keys(json).forEach(function(keye) {
var zero = 50 - (his[0].uses / max * 50); var tag = json[keye];
tags = '<svg version="1.1" viewbox="0 0 60 50" width="60" height="50">' + var his = tag.history;
'<g><path d="M-1,51, -1,' + six + ', 0,' + six + ' L10,' + five + ' 20,' + four + ' 30,' + three + ' 40,' + two + ' 50,' + one + ' 60,' + zero + ' 61,' + zero + ' 61,51 -1,51" style="stroke: #0f8c0c;fill: rgba(13,113,19,.25); stroke-width: 1;"></path></g>' + var max = Math.max.apply(null, [his[0].uses, his[1].uses, his[2].uses, his[3].uses, his[4].uses, his[5].uses, his[6].uses]);
'</svg><span style="font-size:200%">' + his[0].uses + '</span>toots&nbsp;<a onclick="tl(\'tag\',\'' + tag.name + '\',\'' + acct_id + var six = 50 - (his[6].uses / max) * 50;
'\',\'add\')" class="pointer">#' + tag.name + '</a>&nbsp;' + his[0].accounts + lang.lang_src_people + "<br><br>"; var five = 50 - (his[5].uses / max) * 50;
var four = 50 - (his[4].uses / max) * 50;
var three = 50 - (his[3].uses / max) * 50;
var two = 50 - (his[2].uses / max) * 50;
var one = 50 - (his[1].uses / max) * 50;
var zero = 50 - (his[0].uses / max) * 50;
tags = '<svg version="1.1" viewbox="0 0 60 50" width="60" height="50">' + '<g><path d="M-1,51, -1,' + six + ", 0," + six + " L10," + five + " 20," + four + " 30," + three + " 40," + two + " 50," + one + " 60," + zero + " 61," + zero + ' 61,51 -1,51" style="stroke: #0f8c0c;fill: rgba(13,113,19,.25); stroke-width: 1;"></path></g>' + '</svg><span style="font-size:200%">' + his[0].uses + "</span>toots&nbsp;<a onclick=\"tl('tag','" + tag.name + "','" + acct_id + "','add')\" class=\"pointer\">#" + tag.name + "</a>&nbsp;" + his[0].accounts + lang.lang_src_people + "<br><br>";
$("#src-contents").append(tags); $("#src-contents").append(tags);
});
}); });
});
} }

View File

@ -1,163 +1,168 @@
//タグ表示 //タグ表示
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 == "tag") { if (mode == "tag") {
var acct_id = localStorage.getItem("main"); var acct_id = localStorage.getItem("main");
tl('tag', decodeURI(codex), acct_id, 'add'); tl("tag", decodeURI(codex), acct_id, "add");
} }
} }
//よく使うタグ //よく使うタグ
function tagShow(tag) { function tagShow(tag) {
$("[data-tag=" + decodeURI(tag).toLowerCase() + "]").toggleClass("hide"); $("[data-tag=" + decodeURI(tag).toLowerCase() + "]").toggleClass("hide");
} }
//タグ追加 //タグ追加
function tagPin(tag) { function tagPin(tag) {
var tags = localStorage.getItem("tag"); var tags = localStorage.getItem("tag");
if (!tags) { if (!tags) {
var obj = []; var obj = [];
} else { } else {
var obj = JSON.parse(tags); var obj = JSON.parse(tags);
} }
var can; var can;
Object.keys(obj).forEach(function (key) { Object.keys(obj).forEach(function(key) {
var tagT = obj[key]; var tagT = obj[key];
if (tagT == tag) { if (tagT == tag) {
can = true; can = true;
} else { } else {
can = false; can = false;
} }
}); });
if (!can) { if (!can) {
obj.push(tag); obj.push(tag);
} }
var json = JSON.stringify(obj); var json = JSON.stringify(obj);
localStorage.setItem("tag", json); localStorage.setItem("tag", json);
favTag(); favTag();
} }
//タグ削除 //タグ削除
function tagRemove(key) { function tagRemove(key) {
var tags = localStorage.getItem("tag"); var tags = localStorage.getItem("tag");
var obj = JSON.parse(tags); var obj = JSON.parse(tags);
obj.splice(key, 1); obj.splice(key, 1);
var json = JSON.stringify(obj); var json = JSON.stringify(obj);
localStorage.setItem("tag", json); localStorage.setItem("tag", json);
favTag(); favTag();
} }
function favTag() { function favTag() {
$("#taglist").html(""); $("#taglist").html("");
var tagarr = localStorage.getItem("tag"); var tagarr = localStorage.getItem("tag");
if (!tagarr) { if (!tagarr) {
var obj = []; var obj = [];
} else { } else {
var obj = JSON.parse(tagarr); var obj = JSON.parse(tagarr);
} }
var tags = ""; var tags = "";
var nowPT = localStorage.getItem("stable") var nowPT = localStorage.getItem("stable");
Object.keys(obj).forEach(function (key) { Object.keys(obj).forEach(function(key) {
var tag = obj[key]; var tag = obj[key];
if (nowPT != tag) { if (nowPT != tag) {
console.log("stable tags:" + nowPT + "/" + tag); console.log("stable tags:" + nowPT + "/" + tag);
var ptt = lang.lang_tags_realtime; var ptt = lang.lang_tags_realtime;
var nowon = ""; var nowon = "";
} else { } else {
var ptt = lang.lang_tags_unrealtime; var ptt = lang.lang_tags_unrealtime;
var nowon = "(" + lang.lang_tags_realtime + ")"; var nowon = "(" + lang.lang_tags_realtime + ")";
} }
tag = escapeHTML(tag); tag = escapeHTML(tag);
tags = tags + '<a onclick="tagShow(\'' + tag + '\')" class="pointer">#' + tag + '</a>' + nowon + '<span class="hide" data-tag="' + tag + '"> <a onclick="tagTL(\'tag\',\'' + tag + '\',false,\'add\')" class="pointer" title="' + lang.lang_parse_tagTL.replace("{{tag}}", '#' + tag) + '">TL</a> <a onclick="brInsert(\'#' + tag + '\')" class="pointer" title="' + lang.lang_parse_tagtoot.replace("{{tag}}", '#' + tag) + '">Toot</a> ' + tags = tags + "<a onclick=\"tagShow('" + tag + '\')" class="pointer">#' + tag + "</a>" + nowon + '<span class="hide" data-tag="' + tag + "\"> <a onclick=\"tagTL('tag','" + tag + '\',false,\'add\')" class="pointer" title="' + lang.lang_parse_tagTL.replace("{{tag}}", "#" + tag) + '">TL</a> <a onclick="brInsert(\'#' + tag + '\')" class="pointer" title="' + lang.lang_parse_tagtoot.replace("{{tag}}", "#" + tag) + '">Toot</a> ' + "<a onclick=\"autoToot('" + tag + '\');" class="pointer" title="' + lang.lang_tags_always + lang.lang_parse_tagtoot.replace("{{tag}}", "#" + tag) + '">' + ptt + "</a> <a onclick=\"tagRemove('" + key + '\')" class="pointer" title="' + lang.lang_tags_tagunpin.replace("{{tag}}", "#" + tag) + '">' + lang.lang_del + "</a></span> ";
'<a onclick="autoToot(\'' + tag + '\');" class="pointer" title="' + lang.lang_tags_always + lang.lang_parse_tagtoot.replace("{{tag}}", '#' + tag) + '">' + ptt + '</a> <a onclick="tagRemove(\'' + key + '\')" class="pointer" title="' + lang.lang_tags_tagunpin.replace("{{tag}}", '#' + tag) + '">' + lang.lang_del + '</a></span> '; });
}); if (obj.length > 0) {
if (obj.length > 0) { $("#taglist").append("My Tags:" + tags);
$("#taglist").append("My Tags:" + tags); } else {
} else { $("#taglist").append("");
$("#taglist").append(""); }
}
} }
function trendTag() { function trendTag() {
$(".trendtag").remove(); $(".trendtag").remove();
var domain = "imastodon.net" var domain = "imastodon.net";
var at = localStorage.getItem("acct_" + acct_id + "_at"); var at = localStorage.getItem("acct_" + acct_id + "_at");
var start = "https://" + domain + "/api/v1/trend_tags" var start = "https://" + domain + "/api/v1/trend_tags";
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
todo(error); if (!response.ok) {
console.error(error); response.text().then(function(text) {
}).then(function (json) { setLog(response.url, response.status, text);
if (json) { });
var tags = ""; }
json = json.score; return response.json();
Object.keys(json).forEach(function (tag) { })
tag = escapeHTML(tag); .catch(function(error) {
tags = tags + '<a onclick="tagShow(\'' + tag + '\')" class="pointer">#' + tag + '</a><span class="hide" data-tag="' + tag + '"> <a onclick="tagTL(\'tag\',\'' + tag + '\',false,\'add\')" class="pointer" title="#' + tag + 'のタイムライン">TL</a> <a onclick="show();brInsert(\'#' + tag + '\')" class="pointer" title="#' + tag + 'でトゥート">Toot</a></span> '; todo(error);
}); setLog(start, "JSON", error);
$("#taglist").append('<div class="trendtag">アイマストドントレンドタグ<i class="material-icons pointer" onclick="trendTag()" style="font-size:12px">refresh</i>:' + tags + '</div>'); console.error(error);
trendintervalset() })
} else { .then(function(json) {
$("#taglist").html(""); if (json) {
} var tags = "";
}); json = json.score;
Object.keys(json).forEach(function(tag) {
tag = escapeHTML(tag);
tags = tags + "<a onclick=\"tagShow('" + tag + '\')" class="pointer">#' + tag + '</a><span class="hide" data-tag="' + tag + "\"> <a onclick=\"tagTL('tag','" + tag + '\',false,\'add\')" class="pointer" title="#' + tag + 'のタイムライン">TL</a> <a onclick="show();brInsert(\'#' + tag + '\')" class="pointer" title="#' + tag + 'でトゥート">Toot</a></span> ';
});
$("#taglist").append('<div class="trendtag">アイマストドントレンドタグ<i class="material-icons pointer" onclick="trendTag()" style="font-size:12px">refresh</i>:' + tags + "</div>");
trendintervalset();
} else {
$("#taglist").html("");
}
});
} }
function trendintervalset() { function trendintervalset() {
setTimeout(trendTag, 6000000); setTimeout(trendTag, 6000000);
} }
function tagTL(a, b, c, d) { function tagTL(a, b, c, d) {
var acct_id = $("#post-acct-sel").val(); var acct_id = $("#post-acct-sel").val();
tl(a, b, acct_id, d); tl(a, b, acct_id, d);
} }
function autoToot(tag) { function autoToot(tag) {
tag = escapeHTML(tag) tag = escapeHTML(tag);
var nowPT = localStorage.getItem("stable") var nowPT = localStorage.getItem("stable");
if (nowPT == tag) { if (nowPT == tag) {
localStorage.removeItem("stable"); localStorage.removeItem("stable");
M.toast({ html: lang.lang_tags_unrealtime, displayLength: 3000 }) M.toast({ html: lang.lang_tags_unrealtime, displayLength: 3000 });
} else { } else {
localStorage.setItem("stable", tag); localStorage.setItem("stable", tag);
M.toast({ html: lang.lang_tags_tagwarn.replace("{{tag}}", tag).replace("{{tag}}", tag), displayLength: 3000 }) M.toast({ html: lang.lang_tags_tagwarn.replace("{{tag}}", tag).replace("{{tag}}", tag), displayLength: 3000 });
brInsert('#' + tag + " ") brInsert("#" + tag + " ");
} }
favTag(); favTag();
} }
//タグをフィーチャー //タグをフィーチャー
function tagFeature(name, acct_id){ function tagFeature(name, acct_id) {
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/featured_tags" var start = "https://" + domain + "/api/v1/featured_tags";
fetch(start, { fetch(start, {
method: 'POST', method: "POST",
headers: { headers: {
'content-type': 'application/json', "content-type": "application/json",
'Authorization': 'Bearer ' + at Authorization: "Bearer " + at
}, },
body: JSON.stringify({ body: JSON.stringify({
name: name name: name
}) })
}).then(function (response) { })
if (!response.ok) { .then(function(response) {
response.text().then(function(text) { if (!response.ok) {
setLog(response.url, response.status, text); response.text().then(function(text) {
}); setLog(response.url, response.status, text);
} });
return response.json(); }
}).catch(function (error) { return response.json();
return false; })
}).then(function (json) { .catch(function(error) {
console.log(json) return false;
M.toast({ html: "Complete: " + escapeHTML(name), displayLength: 3000 }) })
}); .then(function(json) {
console.log(json);
M.toast({ html: "Complete: " + escapeHTML(name), displayLength: 3000 });
});
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,73 +1,73 @@
//設定(setting.html)で読む //設定(setting.html)で読む
var envView = new Vue({ var envView = new Vue({
el: '#envView', el: "#envView",
data: { config: envConstruction }, data: { config: envConstruction },
methods: { methods: {
complete: function (i, val) { complete: function(i, val) {
var ls = envView.config[i].storage; var ls = envView.config[i].storage;
M.toast({ html: 'Complete', displayLength: 3000 }) M.toast({ html: "Complete", displayLength: 3000 });
if (!val) { if (!val) {
var id = envView.config[i].id; var id = envView.config[i].id;
var val = $("#" + id).val() var val = $("#" + id).val();
} }
localStorage.setItem(ls, val) localStorage.setItem(ls, val);
if (ls == "ha") { if (ls == "ha") {
hardwareAcceleration(val) hardwareAcceleration(val);
} }
if (ls == "ua_setting") { if (ls == "ua_setting") {
useragent(val) useragent(val);
} }
return true return true;
} }
} }
}); });
var tlView = new Vue({ var tlView = new Vue({
el: '#tlView', el: "#tlView",
data: { config: tlConstruction }, data: { config: tlConstruction },
methods: { methods: {
complete: function (i, val) { complete: function(i, val) {
var ls = tlView.config[i]; var ls = tlView.config[i];
if (val) { if (val) {
localStorage.setItem(ls.storage, val) localStorage.setItem(ls.storage, val);
} else { } else {
if (!ls.data) { if (!ls.data) {
ls = [ls] ls = [ls];
} else { } else {
ls = ls.data ls = ls.data;
} }
for (var j = 0; j < ls.length; j++) { for (var j = 0; j < ls.length; j++) {
M.toast({ html: 'Complete', displayLength: 3000 }) M.toast({ html: "Complete", displayLength: 3000 });
var id = ls[j].id; var id = ls[j].id;
var val = $("#" + id).val() var val = $("#" + id).val();
localStorage.setItem(ls[j].storage, val) localStorage.setItem(ls[j].storage, val);
} }
} }
return true return true;
} }
} }
}); });
var postView = new Vue({ var postView = new Vue({
el: '#postView', el: "#postView",
data: { config: postConstruction, kirishima: localStorage.getItem('kirishima'), quoters: localStorage.getItem('quoters') }, data: { config: postConstruction, kirishima: localStorage.getItem("kirishima"), quoters: localStorage.getItem("quoters") },
methods: { methods: {
complete: function (i, val) { complete: function(i, val) {
var ls = postView.config[i]; var ls = postView.config[i];
if (val) { if (val) {
localStorage.setItem(ls.storage, val) localStorage.setItem(ls.storage, val);
} else { } else {
if (!ls.data) { if (!ls.data) {
ls = [ls] ls = [ls];
} else { } else {
ls = ls.data ls = ls.data;
} }
for (var j = 0; j < ls.length; j++) { for (var j = 0; j < ls.length; j++) {
M.toast({ html: 'Complete', displayLength: 3000 }) M.toast({ html: "Complete", displayLength: 3000 });
var id = ls[j].id; var id = ls[j].id;
var val = $("#" + id).val() var val = $("#" + id).val();
localStorage.setItem(ls[j].storage, val) localStorage.setItem(ls[j].storage, val);
} }
} }
return true return true;
} }
} }
}); });
@ -83,7 +83,7 @@ function settings() {
$("#" + theme).prop("checked", true); $("#" + theme).prop("checked", true);
} else { } else {
if (cd != localStorage.getItem("theme")) { if (cd != localStorage.getItem("theme")) {
M.toast({ html: lang.lang_setting_theme.replace("{{set}}", ct), displayLength: 3000 }) M.toast({ html: lang.lang_setting_theme.replace("{{set}}", ct), displayLength: 3000 });
} }
//テーマはこの場で設定 //テーマはこの場で設定
themes(cd); themes(cd);
@ -92,14 +92,14 @@ function settings() {
var fontd = $("#font").val(); var fontd = $("#font").val();
if (fontd) { if (fontd) {
if (fontd != localStorage.getItem("font")) { if (fontd != localStorage.getItem("font")) {
M.toast({ html: lang.lang_setting_font.replace("{{set}}", ct), displayLength: 3000 }) M.toast({ html: lang.lang_setting_font.replace("{{set}}", ct), displayLength: 3000 });
} }
localStorage.setItem("font", fontd); localStorage.setItem("font", fontd);
themes(); themes();
} else { } else {
if (localStorage.getItem("font")) { if (localStorage.getItem("font")) {
localStorage.removeItem("font"); localStorage.removeItem("font");
M.toast({ html: lang.lang_setting_font.replace("{{set}}", ct), displayLength: 3000 }) M.toast({ html: lang.lang_setting_font.replace("{{set}}", ct), displayLength: 3000 });
themes(); themes();
} }
} }
@ -111,7 +111,7 @@ function load() {
for (var i = 0; i < max; i++) { for (var i = 0; i < max; i++) {
var ls = envView.config[i].storage; var ls = envView.config[i].storage;
if (localStorage.getItem(ls)) { if (localStorage.getItem(ls)) {
envView.config[i].setValue = localStorage.getItem(ls) envView.config[i].setValue = localStorage.getItem(ls);
} }
} }
var max = tlView.config.length; var max = tlView.config.length;
@ -119,13 +119,13 @@ function load() {
var ls = tlView.config[i].storage; var ls = tlView.config[i].storage;
if (ls) { if (ls) {
if (localStorage.getItem(ls)) { if (localStorage.getItem(ls)) {
tlView.config[i].setValue = localStorage.getItem(ls) tlView.config[i].setValue = localStorage.getItem(ls);
} }
} else { } else {
ls = tlView.config[i].data ls = tlView.config[i].data;
for (var j = 0; j < ls.length; j++) { for (var j = 0; j < ls.length; j++) {
if (localStorage.getItem(tlView.config[i].data[j].storage)) { if (localStorage.getItem(tlView.config[i].data[j].storage)) {
tlView.config[i].data[j].setValue = localStorage.getItem(tlView.config[i].data[j].storage) tlView.config[i].data[j].setValue = localStorage.getItem(tlView.config[i].data[j].storage);
} }
} }
} }
@ -135,12 +135,12 @@ function load() {
var ls = postView.config[i].storage; var ls = postView.config[i].storage;
if (ls) { if (ls) {
if (localStorage.getItem(ls)) { if (localStorage.getItem(ls)) {
postView.config[i].setValue = localStorage.getItem(ls) postView.config[i].setValue = localStorage.getItem(ls);
} }
} else { } else {
ls = postView.config[i].data ls = postView.config[i].data;
for (var j = 0; j < ls.length; j++) { for (var j = 0; j < ls.length; j++) {
postView.config[i].data[j].setValue = localStorage.getItem(ls[j].storage) postView.config[i].data[j].setValue = localStorage.getItem(ls[j].storage);
} }
} }
} }
@ -160,25 +160,25 @@ function load() {
var font = ""; var font = "";
} }
$("#font").val(font); $("#font").val(font);
$("#c1-file").text(localStorage.getItem("custom1")) $("#c1-file").text(localStorage.getItem("custom1"));
$("#c2-file").text(localStorage.getItem("custom2")); $("#c2-file").text(localStorage.getItem("custom2"));
$("#c3-file").text(localStorage.getItem("custom3")); $("#c3-file").text(localStorage.getItem("custom3"));
$("#c4-file").text(localStorage.getItem("custom4")); $("#c4-file").text(localStorage.getItem("custom4"));
var cvol = localStorage.getItem("customVol") var cvol = localStorage.getItem("customVol");
if (cvol) { if (cvol) {
$("#soundvol").val(cvol * 100); $("#soundvol").val(cvol * 100);
$("#soundVolVal").text(cvol * 100) $("#soundVolVal").text(cvol * 100);
} }
//$("#log").val(localStorage.getItem("errors")) //$("#log").val(localStorage.getItem("errors"))
} }
function customVol() { function customVol() {
var cvol = $("#soundvol").val() var cvol = $("#soundvol").val();
$("#soundVolVal").text(cvol) $("#soundVolVal").text(cvol);
localStorage.setItem("customVol", cvol / 100) localStorage.setItem("customVol", cvol / 100);
var sound = localStorage.getItem("favSound"); var sound = localStorage.getItem("favSound");
if (sound == "default") { if (sound == "default") {
var file = "../../source/notif.wav" var file = "../../source/notif.wav";
}else{ } else {
if (sound == "c1") { if (sound == "c1") {
var file = localStorage.getItem("custom1"); var file = localStorage.getItem("custom1");
} else if (sound == "c2") { } else if (sound == "c2") {
@ -208,13 +208,10 @@ function climute() {
return; return;
} }
var templete; var templete;
Object.keys(obj).forEach(function (key) { Object.keys(obj).forEach(function(key) {
var cli = obj[key]; var cli = obj[key];
var list = key * 1 + 1; var list = key * 1 + 1;
templete = '<div class="acct" id="acct_' + key + '">' + list + templete = '<div class="acct" id="acct_' + key + '">' + list + "." + escapeHTML(cli) + '<button class="btn waves-effect red disTar" onclick="cliMuteDel(' + key + ')">' + lang.lang_del + "</button><br></div>";
'.' +
escapeHTML(cli) + '<button class="btn waves-effect red disTar" onclick="cliMuteDel(' +
key + ')">' + lang.lang_del + '</button><br></div>';
$("#mute-cli").append(templete); $("#mute-cli").append(templete);
}); });
} }
@ -231,9 +228,11 @@ function cliMuteDel(key) {
function wordmute() { function wordmute() {
var word = localStorage.getItem("word_mute"); var word = localStorage.getItem("word_mute");
var obj = JSON.parse(word); var obj = JSON.parse(word);
if (!obj) { obj = [] } if (!obj) {
$('#wordmute').chips({ obj = [];
data: obj, }
$("#wordmute").chips({
data: obj
}); });
} }
function wordmuteSave() { function wordmuteSave() {
@ -245,9 +244,11 @@ function wordmuteSave() {
function wordemp() { function wordemp() {
var word = localStorage.getItem("word_emp"); var word = localStorage.getItem("word_emp");
var obj = JSON.parse(word); var obj = JSON.parse(word);
if (!obj) { obj = [] } if (!obj) {
$('#wordemp').chips({ obj = [];
data: obj, }
$("#wordemp").chips({
data: obj
}); });
} }
function wordempSave() { function wordempSave() {
@ -258,39 +259,44 @@ function wordempSave() {
function notftest() { function notftest() {
var os = localStorage.getItem("platform"); var os = localStorage.getItem("platform");
var options = { var options = {
body: lang.lang_setting_notftest + '(' + lang.lang_setting_notftestprof + ')', body: lang.lang_setting_notftest + "(" + lang.lang_setting_notftestprof + ")",
icon: localStorage.getItem("prof_0") icon: localStorage.getItem("prof_0")
}; };
var n = new Notification('TheDesk' + lang.lang_setting_notftest, options); var n = new Notification("TheDesk" + lang.lang_setting_notftest, options);
} }
function oks(no) { function oks(no) {
var txt = $("#oks-" + no).val(); var txt = $("#oks-" + no).val();
localStorage.setItem("oks-" + no, txt); localStorage.setItem("oks-" + no, txt);
M.toast({ html: lang.lang_setting_ksref, displayLength: 3000 }) M.toast({ html: lang.lang_setting_ksref, displayLength: 3000 });
} }
function oksload() { function oksload() {
if (localStorage.getItem("oks-1")) { $("#oks-1").val(localStorage.getItem("oks-1")) } if (localStorage.getItem("oks-1")) {
if (localStorage.getItem("oks-2")) { $("#oks-2").val(localStorage.getItem("oks-2")) } $("#oks-1").val(localStorage.getItem("oks-1"));
if (localStorage.getItem("oks-3")) { $("#oks-3").val(localStorage.getItem("oks-3")) } }
if (localStorage.getItem("oks-2")) {
$("#oks-2").val(localStorage.getItem("oks-2"));
}
if (localStorage.getItem("oks-3")) {
$("#oks-3").val(localStorage.getItem("oks-3"));
}
} }
function changelang(lang) { function changelang(lang) {
postMessage(["lang", lang], "*") postMessage(["lang", lang], "*");
} }
function exportSettings() { function exportSettings() {
Swal.fire({ Swal.fire({
title: lang.lang_setting_exportwarn, title: lang.lang_setting_exportwarn,
type: 'warning', type: "warning",
showCancelButton: true, showCancelButton: true,
confirmButtonColor: '#3085d6', confirmButtonColor: "#3085d6",
cancelButtonColor: '#d33', cancelButtonColor: "#d33",
confirmButtonText: lang.lang_yesno, confirmButtonText: lang.lang_yesno,
cancelButtonText: lang.lang_no cancelButtonText: lang.lang_no
}).then((result) => { }).then(result => {
if (result.value) { if (result.value) {
postMessage(["exportSettings", ""], "*") postMessage(["exportSettings", ""], "*");
} }
}) });
} }
function exportSettingsCore() { function exportSettingsCore() {
var exp = {}; var exp = {};
@ -309,27 +315,23 @@ function exportSettingsCore() {
var max = envView.config.length; var max = envView.config.length;
for (var i = 0; i < max; i++) { for (var i = 0; i < max; i++) {
var ls = envView.config[i].storage; var ls = envView.config[i].storage;
config[ls] = localStorage.getItem(ls) config[ls] = localStorage.getItem(ls);
} }
var max = tlView.config.length; var max = tlView.config.length;
for (var i = 0; i < max; i++) { for (var i = 0; i < max; i++) {
var ls = tlView.config[i].storage; var ls = tlView.config[i].storage;
config[ls] = localStorage.getItem(ls) config[ls] = localStorage.getItem(ls);
} }
var max = postView.config.length; var max = postView.config.length;
for (var i = 0; i < max; i++) { for (var i = 0; i < max; i++) {
var ls = postView.config[i].storage; var ls = postView.config[i].storage;
config[ls] = localStorage.getItem(ls) config[ls] = localStorage.getItem(ls);
} }
//Font //Font
config.font = localStorage.getItem("font"); config.font = localStorage.getItem("font");
exp.config = config; exp.config = config;
//keysc //keysc
exp.ksc = [ exp.ksc = [localStorage.getItem("oks-1"), localStorage.getItem("oks-2"), localStorage.getItem("oks-3")];
localStorage.getItem("oks-1"),
localStorage.getItem("oks-2"),
localStorage.getItem("oks-3")
];
//climu //climu
var cli = localStorage.getItem("client_mute"); var cli = localStorage.getItem("client_mute");
var climu = JSON.parse(cli); var climu = JSON.parse(cli);
@ -339,7 +341,7 @@ function exportSettingsCore() {
var wordmu = JSON.parse(wdm); var wordmu = JSON.parse(wdm);
exp.wordMute = wordmu; exp.wordMute = wordmu;
//spotify //spotify
exp.spotifyArtwork = localStorage.getItem("artwork") exp.spotifyArtwork = localStorage.getItem("artwork");
var content = localStorage.getItem("np-temp"); var content = localStorage.getItem("np-temp");
if (content || content == "" || content == "null") { if (content || content == "" || content == "null") {
exp.spotifyTemplete = content; exp.spotifyTemplete = content;
@ -350,27 +352,27 @@ function exportSettingsCore() {
var tagarr = localStorage.getItem("tag"); var tagarr = localStorage.getItem("tag");
var favtag = JSON.parse(tagarr); var favtag = JSON.parse(tagarr);
exp.favoriteTags = favtag; exp.favoriteTags = favtag;
exp.revisons = 2.1 exp.revisons = 2.1;
exp.meta = {} exp.meta = {};
exp.meta.date = new Date() exp.meta.date = new Date();
exp.meta.thedesk = localStorage.getItem("ver") exp.meta.thedesk = localStorage.getItem("ver");
exp.meta.platform = localStorage.getItem("platform") exp.meta.platform = localStorage.getItem("platform");
return exp; return exp;
} }
function importSettings() { function importSettings() {
Swal.fire({ Swal.fire({
title: lang.lang_setting_importwarn, title: lang.lang_setting_importwarn,
type: 'warning', type: "warning",
showCancelButton: true, showCancelButton: true,
confirmButtonColor: '#3085d6', confirmButtonColor: "#3085d6",
cancelButtonColor: '#d33', cancelButtonColor: "#d33",
confirmButtonText: lang.lang_yesno, confirmButtonText: lang.lang_yesno,
cancelButtonText: lang.lang_no cancelButtonText: lang.lang_no
}).then((result) => { }).then(result => {
if (result.value) { if (result.value) {
postMessage(["importSettings", ""], "*") postMessage(["importSettings", ""], "*");
} }
}) });
} }
function importSettingsCore(obj) { function importSettingsCore(obj) {
if (obj) { if (obj) {
@ -392,21 +394,21 @@ function importSettingsCore(obj) {
for (var i = 0; i < max; i++) { for (var i = 0; i < max; i++) {
var ls = envView.config[i].storage; var ls = envView.config[i].storage;
if (obj.config[ls]) { if (obj.config[ls]) {
localStorage.setItem(ls, obj.config[ls]) localStorage.setItem(ls, obj.config[ls]);
} }
} }
var max = tlView.config.length; var max = tlView.config.length;
for (var i = 0; i < max; i++) { for (var i = 0; i < max; i++) {
var ls = tlView.config[i].storage; var ls = tlView.config[i].storage;
if (obj.config[ls]) { if (obj.config[ls]) {
localStorage.setItem(ls, obj.config[ls]) localStorage.setItem(ls, obj.config[ls]);
} }
} }
var max = postView.config.length; var max = postView.config.length;
for (var i = 0; i < max; i++) { for (var i = 0; i < max; i++) {
var ls = postView.config[i].storage; var ls = postView.config[i].storage;
if (obj.config[ls]) { if (obj.config[ls]) {
localStorage.setItem(ls, obj.config[ls]) localStorage.setItem(ls, obj.config[ls]);
} }
} }
} else { } else {
@ -459,92 +461,112 @@ function importSettingsCore(obj) {
location.href = "index.html"; location.href = "index.html";
} else { } else {
Swal.fire({ Swal.fire({
type: 'error', type: "error",
title: 'Error' title: "Error"
}) });
} }
} }
function savefolder() { function savefolder() {
postMessage(["sendSinmpleIpc", "savefolder"], "*") postMessage(["sendSinmpleIpc", "savefolder"], "*");
} }
function font() { function font() {
postMessage(["sendSinmpleIpc", "fonts"], "*") postMessage(["sendSinmpleIpc", "fonts"], "*");
} }
function fontList(arg) { function fontList(arg) {
$("#fonts").removeClass("hide"); $("#fonts").removeClass("hide");
for (var i = 0; i < arg.length; i++) { for (var i = 0; i < arg.length; i++) {
var font = arg[i]; var font = arg[i];
$("#fonts").append('<div class="font pointer" style="font-family:' + font.family + '" onclick="insertFont(\'' + font.family + '\')">' + font.family + "</div>") $("#fonts").append('<div class="font pointer" style="font-family:' + font.family + '" onclick="insertFont(\'' + font.family + "')\">" + font.family + "</div>");
} }
} }
function insertFont(name) { function insertFont(name) {
$("#font").val(name); $("#font").val(name);
} }
$(".color-picker").each(function (i, elem) { $(".color-picker").each(function(i, elem) {
pickerDefine(i, "fff"); pickerDefine(i, "fff");
}); });
function pickerDefine(i, color) { function pickerDefine(i, color) {
var pickr = new Pickr({ var pickr = new Pickr({
el: '#color-picker' + i, el: "#color-picker" + i,
default: color, default: color,
showAlways: true, showAlways: true,
appendToBody: true, appendToBody: true,
closeWithKey: 'Escape', closeWithKey: "Escape",
comparison: false, comparison: false,
components: { components: {
preview: true, // Left side color comparison preview: true, // Left side color comparison
opacity: false, // Opacity slider opacity: false, // Opacity slider
hue: true, // Hue slider hue: true, // Hue slider
interaction: { interaction: {
rgba: false, // rgba option (red green blue and alpha) rgba: false, // rgba option (red green blue and alpha)
input: true, // input / output element input: true // input / output element
} }
}, },
strings: { strings: {
save: 'Save', // Default for save button save: "Save", // Default for save button
clear: 'Clear' // Default for clear button clear: "Clear" // Default for clear button
} }
}); });
pickr.on('change', (...args) => { pickr.on("change", (...args) => {
var rgb = 'rgb(' + args[0].toRGBA()[0] + ',' + args[0].toRGBA()[1] + ',' + args[0].toRGBA()[2] + ')'; var rgb = "rgb(" + args[0].toRGBA()[0] + "," + args[0].toRGBA()[1] + "," + args[0].toRGBA()[2] + ")";
$("#color-picker" + i + "_value").val(rgb) $("#color-picker" + i + "_value").val(rgb);
}); });
} }
function customComp() { function customComp() {
var nameC = $("#custom_name").val(); var nameC = $("#custom_name").val();
if (!nameC) { return false; } if (!nameC) {
return false;
}
var descC = $("#custom_desc").val(); var descC = $("#custom_desc").val();
var primaryC = $("#color-picker0_value").val(); var primaryC = $("#color-picker0_value").val();
if (!primaryC) { primaryC = "rgb(255,255,255)" } if (!primaryC) {
primaryC = "rgb(255,255,255)";
}
var secondaryC = $("#color-picker1_value").val(); var secondaryC = $("#color-picker1_value").val();
if (!secondaryC) { secondaryC = "rgb(255,255,255)" } if (!secondaryC) {
secondaryC = "rgb(255,255,255)";
}
var textC = $("#color-picker2_value").val(); var textC = $("#color-picker2_value").val();
if (!textC) { textC = "rgb(255,255,255)" } if (!textC) {
textC = "rgb(255,255,255)";
}
var multi = localStorage.getItem("multi"); var multi = localStorage.getItem("multi");
if($("#pickers").hasClass("advanceTheme")){ if ($("#pickers").hasClass("advanceTheme")) {
var accentC = $("#color-picker3_value").val(); var accentC = $("#color-picker3_value").val();
if (!accentC) { accentC = null } if (!accentC) {
var activeC = $("#color-picker4_value").val(); accentC = null;
if (!activeC) { activeC = null }
var modalC = $("#color-picker5_value").val();
if (!modalC) { modalC = null }
var bottomC = $("#color-picker6_value").val();
if (!bottomC) { bottomC = null }
var postboxC = $("#color-picker7_value").val();
if (!postboxC) { postboxC = null }
var subcolorC = $("#color-picker8_value").val();
if (!subcolorC) { subcolorC = null }
var advanceTheme = {
"TheDeskAccent": accentC,
"TheDeskActive": activeC,
"TheDeskModal": modalC,
"TheDeskBottom": bottomC,
"TheDeskPostbox": postboxC,
"TheDeskSubcolor": subcolorC
} }
}else{ var activeC = $("#color-picker4_value").val();
var advanceTheme = {} if (!activeC) {
activeC = null;
}
var modalC = $("#color-picker5_value").val();
if (!modalC) {
modalC = null;
}
var bottomC = $("#color-picker6_value").val();
if (!bottomC) {
bottomC = null;
}
var postboxC = $("#color-picker7_value").val();
if (!postboxC) {
postboxC = null;
}
var subcolorC = $("#color-picker8_value").val();
if (!subcolorC) {
subcolorC = null;
}
var advanceTheme = {
TheDeskAccent: accentC,
TheDeskActive: activeC,
TheDeskModal: modalC,
TheDeskBottom: bottomC,
TheDeskPostbox: postboxC,
TheDeskSubcolor: subcolorC
};
} else {
var advanceTheme = {};
} }
var my = JSON.parse(multi)[0].name; var my = JSON.parse(multi)[0].name;
@ -552,20 +574,20 @@ function customComp() {
if (id == "add_new") { if (id == "add_new") {
id = makeCID(); id = makeCID();
} }
localStorage.setItem("customtheme-id", id) localStorage.setItem("customtheme-id", id);
var json = { var json = {
"name": nameC, name: nameC,
"author": my, author: my,
"desc": descC, desc: descC,
"base": $("[name=direction]:checked").val(), base: $("[name=direction]:checked").val(),
"vars": { vars: {
"primary": primaryC, primary: primaryC,
"secondary": secondaryC, secondary: secondaryC,
"text": textC text: textC
}, },
"props": advanceTheme, props: advanceTheme,
"id": id id: id
} };
$("#custom_json").val(JSON.stringify(json)); $("#custom_json").val(JSON.stringify(json));
themes("custom"); themes("custom");
$("#custom").prop("checked", true); $("#custom").prop("checked", true);
@ -573,12 +595,12 @@ function customComp() {
$("#custom_desc").val(""); $("#custom_desc").val("");
$("#dark").prop("checked", true); $("#dark").prop("checked", true);
$("#custom_json").val(""); $("#custom_json").val("");
for(var i =0;i <= 8; i++){ for (var i = 0; i <= 8; i++) {
$("#color-picker" + i + "-wrap").html('<div class="color-picker" id="color-picker' + i + '"></div>') $("#color-picker" + i + "-wrap").html('<div class="color-picker" id="color-picker' + i + '"></div>');
$("#color-picker" + i + "_value").val(""); $("#color-picker" + i + "_value").val("");
pickerDefine(i, "fff"); pickerDefine(i, "fff");
} }
postMessage(["themeJsonCreate", JSON.stringify(json)], "*") postMessage(["themeJsonCreate", JSON.stringify(json)], "*");
} }
function deleteIt() { function deleteIt() {
var id = $("#custom-sel-sel").val(); var id = $("#custom-sel-sel").val();
@ -586,34 +608,34 @@ function deleteIt() {
$("#custom_desc").val(""); $("#custom_desc").val("");
$("#dark").prop("checked", true); $("#dark").prop("checked", true);
$("#custom_json").val(""); $("#custom_json").val("");
for(var i =0;i <= 8; i++){ for (var i = 0; i <= 8; i++) {
$("#color-picker" + i + "-wrap").html('<div class="color-picker" id="color-picker' + i + '"></div>') $("#color-picker" + i + "-wrap").html('<div class="color-picker" id="color-picker' + i + '"></div>');
$("#color-picker" + i + "_value").val(""); $("#color-picker" + i + "_value").val("");
pickerDefine(i, "fff"); pickerDefine(i, "fff");
} }
postMessage(["themeJsonDelete", id], "*") postMessage(["themeJsonDelete", id], "*");
} }
function ctLoad() { function ctLoad() {
postMessage(["sendSinmpleIpc", "theme-json-list"], "*") postMessage(["sendSinmpleIpc", "theme-json-list"], "*");
} }
function ctLoadCore(args) { function ctLoadCore(args) {
var templete = ""; var templete = "";
Object.keys(args).forEach(function (key) { Object.keys(args).forEach(function(key) {
var theme = args[key]; var theme = args[key];
var themeid = theme.id var themeid = theme.id;
templete = templete + '<option value="' + themeid + '">' + theme.name + '</option>'; templete = templete + '<option value="' + themeid + '">' + theme.name + "</option>";
}); });
if (args[0]) { if (args[0]) {
localStorage.setItem("customtheme-id", args[0].id) localStorage.setItem("customtheme-id", args[0].id);
} }
$("#custom-sel-sel").html(templete); $("#custom-sel-sel").html(templete);
templete = '<option value="add_new">' + $("#edit-selector").attr("data-add") + '</option>' + templete; templete = '<option value="add_new">' + $("#edit-selector").attr("data-add") + "</option>" + templete;
$("#custom-edit-sel").html(templete); $("#custom-edit-sel").html(templete);
$('select').formSelect(); $("select").formSelect();
} }
function customSel() { function customSel() {
var id = $("#custom-sel-sel").val(); var id = $("#custom-sel-sel").val();
localStorage.setItem("customtheme-id", id) localStorage.setItem("customtheme-id", id);
} }
function custom() { function custom() {
var id = $("#custom-edit-sel").val(); var id = $("#custom-edit-sel").val();
@ -622,91 +644,91 @@ function custom() {
$("#custom_desc").val(""); $("#custom_desc").val("");
$("#dark").prop("checked", true); $("#dark").prop("checked", true);
$("#custom_json").val(""); $("#custom_json").val("");
for(var i =0;i <= 8; i++){ for (var i = 0; i <= 8; i++) {
$("#color-picker" + i + "-wrap").html('<div class="color-picker" id="color-picker' + i + '"></div>') $("#color-picker" + i + "-wrap").html('<div class="color-picker" id="color-picker' + i + '"></div>');
$("#color-picker" + i + "_value").val(""); $("#color-picker" + i + "_value").val("");
pickerDefine(i, "fff"); pickerDefine(i, "fff");
} }
$("#delTheme").addClass("disabled") $("#delTheme").addClass("disabled");
} else { } else {
$("#delTheme").removeClass("disabled") $("#delTheme").removeClass("disabled");
postMessage(["themeJsonRequest", id], "*") postMessage(["themeJsonRequest", id], "*");
} }
} }
function customConnect(raw) { function customConnect(raw) {
var args = raw[0] var args = raw[0];
$("#custom_name").val(args.name); $("#custom_name").val(args.name);
$("#custom_desc").val(args.desc); $("#custom_desc").val(args.desc);
$("#" + args.base).prop("checked", true); $("#" + args.base).prop("checked", true);
//Primary //Primary
$("#color-picker0-wrap").html('<div class="color-picker" id="color-picker0"></div>') $("#color-picker0-wrap").html('<div class="color-picker" id="color-picker0"></div>');
pickerDefine(0, rgbToHex(args.vars.primary)) pickerDefine(0, rgbToHex(args.vars.primary));
$("#color-picker0_value").val(args.vars.primary); $("#color-picker0_value").val(args.vars.primary);
//Secondary //Secondary
$("#color-picker1-wrap").html('<div class="color-picker" id="color-picker1"></div>') $("#color-picker1-wrap").html('<div class="color-picker" id="color-picker1"></div>');
pickerDefine(1, rgbToHex(args.vars.secondary)) pickerDefine(1, rgbToHex(args.vars.secondary));
$("#color-picker1_value").val(args.vars.secondary); $("#color-picker1_value").val(args.vars.secondary);
//Text //Text
$("#color-picker2-wrap").html('<div class="color-picker" id="color-picker2"></div>') $("#color-picker2-wrap").html('<div class="color-picker" id="color-picker2"></div>');
$("#color-picker2_value").val(args.vars.text); $("#color-picker2_value").val(args.vars.text);
pickerDefine(2, rgbToHex(args.vars.text)) pickerDefine(2, rgbToHex(args.vars.text));
//TheDesk Only //TheDesk Only
advancedConncet(args, "TheDeskAccent", "secondary", 3) advancedConncet(args, "TheDeskAccent", "secondary", 3);
advancedConncet(args, "TheDeskActive", "primary", 4) advancedConncet(args, "TheDeskActive", "primary", 4);
advancedConncet(args, "TheDeskModal", "secondary", 5) advancedConncet(args, "TheDeskModal", "secondary", 5);
advancedConncet(args, "TheDeskBottom", "primary", 6) advancedConncet(args, "TheDeskBottom", "primary", 6);
advancedConncet(args, "TheDeskPostbox", "primary", 7) advancedConncet(args, "TheDeskPostbox", "primary", 7);
advancedConncet(args, "TheDeskSubcolor", "primary", 8) advancedConncet(args, "TheDeskSubcolor", "primary", 8);
$("#custom_json").val(raw[1]); $("#custom_json").val(raw[1]);
} }
function advancedConncet(args, tar, sub, i){ function advancedConncet(args, tar, sub, i) {
if (args.props) { if (args.props) {
if (args.props[tar]) { if (args.props[tar]) {
var color = args.props[tar]; var color = args.props[tar];
$("#pickers").addClass("advanceTheme") $("#pickers").addClass("advanceTheme");
$(".advanced").removeClass("hide") $(".advanced").removeClass("hide");
} else { } else {
var color = args.vars[sub]; var color = args.vars[sub];
} }
} else { } else {
var color = args.vars[sub]; var color = args.vars[sub];
} }
$("#color-picker"+i+"-wrap").html('<div class="color-picker" id="color-picker'+i+'"></div>') $("#color-picker" + i + "-wrap").html('<div class="color-picker" id="color-picker' + i + '"></div>');
$("#color-picker"+i+"_value").val(color); $("#color-picker" + i + "_value").val(color);
pickerDefine(i, rgbToHex(color)) pickerDefine(i, rgbToHex(color));
} }
function customImp() { function customImp() {
var json = $("#custom_import").val(); var json = $("#custom_import").val();
if (JSON5.parse(json)) { if (JSON5.parse(json)) {
postMessage(["themeJsonCreate", json], "*") postMessage(["themeJsonCreate", json], "*");
} else { } else {
Swal.fire({ Swal.fire({
type: 'error', type: "error",
title: 'Error' title: "Error"
}) });
} }
} }
function advanced(){ function advanced() {
$(".advanced").toggleClass("hide") $(".advanced").toggleClass("hide");
$("#pickers").toggleClass("advanceTheme") $("#pickers").toggleClass("advanceTheme");
} }
function clearCustomImport() { function clearCustomImport() {
$("#custom_import").val(""); $("#custom_import").val("");
} }
function hardwareAcceleration(had) { function hardwareAcceleration(had) {
postMessage(["ha", had], "*") postMessage(["ha", had], "*");
} }
function useragent(val){ function useragent(val) {
postMessage(["ua", val], "*") postMessage(["ua", val], "*");
} }
function customSound(key) { function customSound(key) {
postMessage(["customSound", key], "*") postMessage(["customSound", key], "*");
} }
function customSoundSave(key, file) { function customSoundSave(key, file) {
localStorage.setItem("custom" + key, file); localStorage.setItem("custom" + key, file);
$("#c1-file").text(file) $("#c1-file").text(file);
} }
window.onload = function () { window.onload = function() {
//最初に読む //最初に読む
load(); load();
climute(); climute();
@ -715,52 +737,56 @@ window.onload = function () {
checkSpotify(); checkSpotify();
voiceSettingLoad(); voiceSettingLoad();
oksload(); oksload();
ctLoad() ctLoad();
}; };
//設定画面で未読マーカーは要らない //設定画面で未読マーカーは要らない
function asReadEnd() { function asReadEnd() {
postMessage(["asReadComp", ""], "*") postMessage(["asReadComp", ""], "*");
} }
function checkupd(){ function checkupd() {
var ver = localStorage.getItem("ver"); var ver = localStorage.getItem("ver");
var start = "https://thedesk.top/ver.json"; var start = "https://thedesk.top/ver.json";
fetch(start, { fetch(start, {
method: 'GET' method: "GET"
}).then(function (response) { })
if (!response.ok) { .then(function(response) {
response.text().then(function(text) { if (!response.ok) {
setLog(response.url, response.status, text); response.text().then(function(text) {
}); setLog(response.url, response.status, text);
} });
return response.json();
}).catch(function (error) {
todo(error);
console.error(error);
}).then(function (mess) {
console.table(mess);
if (mess) {
var platform = localStorage.getItem("platform");
if (platform == "darwin") {
var newest = mess.desk_mac;
} else {
var newest = mess.desk;
} }
if (newest == ver) { return response.json();
Swal.fire({ })
type: 'info', .catch(function(error) {
title: lang.lang_setting_noupd, todo(error);
html: ver setLog(start, "JSON", error);
}) console.error(error);
} else if (ver.indexOf("beta") != -1 || winstore) { })
Swal.fire({ .then(function(mess) {
type: 'info', console.table(mess);
title: lang.lang_setting_thisisbeta, if (mess) {
html: ver var platform = localStorage.getItem("platform");
}) if (platform == "darwin") {
} else { var newest = mess.desk_mac;
localStorage.removeItem("new-ver-skip") } else {
location.href="index.html" var newest = mess.desk;
}
if (newest == ver) {
Swal.fire({
type: "info",
title: lang.lang_setting_noupd,
html: ver
});
} else if (ver.indexOf("beta") != -1 || winstore) {
Swal.fire({
type: "info",
title: lang.lang_setting_thisisbeta,
html: ver
});
} else {
localStorage.removeItem("new-ver-skip");
location.href = "index.html";
}
} }
} });
});
} }

View File

@ -1,189 +1,189 @@
function spotifyConnect() { function spotifyConnect() {
var auth = "https://accounts.spotify.com/authorize?client_id=0f18e54abe0b4aedb4591e353d3aff69&redirect_uri=https://thedesk.top/spotify-connect&response_type=code&scope=user-read-currently-playing"; var auth = "https://accounts.spotify.com/authorize?client_id=0f18e54abe0b4aedb4591e353d3aff69&redirect_uri=https://thedesk.top/spotify-connect&response_type=code&scope=user-read-currently-playing";
var platform = localStorage.getItem("platform"); var platform = localStorage.getItem("platform");
if (platform == "win32") { if (platform == "win32") {
postMessage(["openUrl", auth], "*") postMessage(["openUrl", auth], "*");
postMessage(["sendSinmpleIpc", "quit"], "*") postMessage(["sendSinmpleIpc", "quit"], "*");
} else { } else {
auth = auth + "&state=code"; auth = auth + "&state=code";
$("#spotify-code-show").removeClass("hide"); $("#spotify-code-show").removeClass("hide");
postMessage(["openUrl", auth], "*") postMessage(["openUrl", auth], "*");
} }
} }
function spotifyAuth() { function spotifyAuth() {
var code = $("#spotify-code").val(); var code = $("#spotify-code").val();
localStorage.setItem("spotify", "code"); localStorage.setItem("spotify", "code");
localStorage.setItem("spotify-refresh", code); localStorage.setItem("spotify-refresh", code);
$("#spotify-code-show").addClass("hide"); $("#spotify-code-show").addClass("hide");
$("#spotify-enable").addClass("disabled"); $("#spotify-enable").addClass("disabled");
$("#spotify-disable").removeClass("disabled"); $("#spotify-disable").removeClass("disabled");
} }
function spotifyDisconnect() { function spotifyDisconnect() {
localStorage.removeItem("spotify"); localStorage.removeItem("spotify");
localStorage.removeItem("spotify-refresh"); localStorage.removeItem("spotify-refresh");
checkSpotify(); checkSpotify();
} }
function checkSpotify() { function checkSpotify() {
if (localStorage.getItem("spotify")) { if (localStorage.getItem("spotify")) {
$("#spotify-enable").addClass("disabled"); $("#spotify-enable").addClass("disabled");
$("#spotify-disable").removeClass("disabled"); $("#spotify-disable").removeClass("disabled");
} else { } else {
$("#spotify-enable").removeClass("disabled"); $("#spotify-enable").removeClass("disabled");
$("#spotify-disable").addClass("disabled"); $("#spotify-disable").addClass("disabled");
} }
var content = localStorage.getItem("np-temp"); var content = localStorage.getItem("np-temp");
if (!content || content == "" || content == "null") { if (!content || content == "" || content == "null") {
var content = "#NowPlaying {song} / {album} / {artist}\n{url} #SpotifyWithTheDesk"; var content = "#NowPlaying {song} / {album} / {artist}\n{url} #SpotifyWithTheDesk";
} }
$("#np-temp").val(content); $("#np-temp").val(content);
var flag = localStorage.getItem("artwork"); var flag = localStorage.getItem("artwork");
if (flag) { if (flag) {
$("#awk_yes").prop("checked", true); $("#awk_yes").prop("checked", true);
} else { } else {
$("#awk_no").prop("checked", true); $("#awk_no").prop("checked", true);
} }
} }
function spotifyFlagSave() { function spotifyFlagSave() {
var awk = $("[name=awk]:checked").val(); var awk = $("[name=awk]:checked").val();
if (awk == "yes") { if (awk == "yes") {
localStorage.setItem("artwork", "yes"); localStorage.setItem("artwork", "yes");
M.toast({ html: lang.lang_spotify_img, displayLength: 3000 }) M.toast({ html: lang.lang_spotify_img, displayLength: 3000 });
} else { } else {
localStorage.removeItem("artwork"); localStorage.removeItem("artwork");
M.toast({ html: lang.lang_spotify_imgno, displayLength: 3000 }) M.toast({ html: lang.lang_spotify_imgno, displayLength: 3000 });
} }
} }
function nowplaying(mode) { function nowplaying(mode) {
if (mode == "spotify") { if (mode == "spotify") {
var start = "https://thedesk.top/now-playing?at=" + localStorage.getItem("spotify") + "&rt=" + localStorage.getItem("spotify-refresh"); var start = "https://thedesk.top/now-playing?at=" + localStorage.getItem("spotify") + "&rt=" + localStorage.getItem("spotify-refresh");
var at = localStorage.getItem("spotify"); var at = localStorage.getItem("spotify");
if (at) { if (at) {
fetch(start, { fetch(start, {
method: 'GET', method: "GET",
headers: { headers: {
'content-type': 'application/json' "content-type": "application/json"
} }
}).then(function (response) { })
if (!response.ok) { .then(function(response) {
response.text().then(function(text) { if (!response.ok) {
setLog(response.url, response.status, text); response.text().then(function(text) {
setLog(response.url, response.status, text);
});
}
return response.json();
})
.catch(function(error) {
todo(error);
setLog(start, "JSON", error);
console.error(error);
})
.then(function(json) {
console.table(json);
if (json.length < 1) {
return false;
}
var item = json.item;
var img = item.album.images[0].url;
var flag = localStorage.getItem("artwork");
if (flag) {
postMessage(["bmpImage", [img, 0]], "*");
}
var content = localStorage.getItem("np-temp");
if (!content || content == "" || content == "null") {
var content = "#NowPlaying {song} / {album} / {artist}\n{url}";
}
var regExp = new RegExp("{song}", "g");
content = content.replace(regExp, item.name);
var regExp = new RegExp("{album}", "g");
content = content.replace(regExp, item.album.name);
var regExp = new RegExp("{artist}", "g");
content = content.replace(regExp, item.artists[0].name);
var regExp = new RegExp("{url}", "g");
content = content.replace(regExp, item.external_urls.spotify);
var regExp = new RegExp("{composer}", "g");
content = content.replace(regExp, "");
var regExp = new RegExp("{hz}", "g");
content = content.replace(regExp, "");
var regExp = new RegExp("{bitRate}", "g");
content = content.replace(regExp, "");
var regExp = new RegExp("{lyricist}", "g");
content = content.replace(regExp, "");
var regExp = new RegExp("{bpm}", "g");
content = content.replace(regExp, "");
var regExp = new RegExp("{genre}", "g");
content = content.replace(regExp, "");
$("#textarea").val(content);
});
} else {
Swal.fire({
type: "info",
title: lang.lang_spotify_acct
}); });
} }
return response.json(); } else if (mode == "itunes") {
}).catch(function (error) { postMessage(["itunes", ""], "*");
todo(error); }
console.error(error);
}).then(function (json) {
console.table(json);
if (json.length < 1) {
return false;
}
var item = json.item;
var img = item.album.images[0].url;
var flag = localStorage.getItem("artwork");
if (flag) {
postMessage(["bmpImage", [img, 0]], "*")
}
var content = localStorage.getItem("np-temp");
if (!content || content == "" || content == "null") {
var content = "#NowPlaying {song} / {album} / {artist}\n{url}";
}
var regExp = new RegExp("{song}", "g");
content = content.replace(regExp, item.name);
var regExp = new RegExp("{album}", "g");
content = content.replace(regExp, item.album.name);
var regExp = new RegExp("{artist}", "g");
content = content.replace(regExp, item.artists[0].name);
var regExp = new RegExp("{url}", "g");
content = content.replace(regExp, item.external_urls.spotify);
var regExp = new RegExp("{composer}", "g");
content = content.replace(regExp, "");
var regExp = new RegExp("{hz}", "g");
content = content.replace(regExp, "");
var regExp = new RegExp("{bitRate}", "g");
content = content.replace(regExp, "");
var regExp = new RegExp("{lyricist}", "g");
content = content.replace(regExp, "");
var regExp = new RegExp("{bpm}", "g");
content = content.replace(regExp, "");
var regExp = new RegExp("{genre}", "g");
content = content.replace(regExp, "");
$("#textarea").val(content);
});
} else {
Swal.fire({
type: 'info',
title: lang.lang_spotify_acct
})
}
} else if (mode == "itunes") {
postMessage(["itunes", ""], "*")
}
} }
function npCore(arg) { function npCore(arg) {
if (arg.cmd) { if (arg.cmd) {
console.error(arg); console.error(arg);
return; return;
} }
console.table(arg); console.table(arg);
var content = localStorage.getItem("np-temp"); var content = localStorage.getItem("np-temp");
if (!content || content == "" || content == "null") { if (!content || content == "" || content == "null") {
var content = "#NowPlaying {song} / {album} / {artist}\n{url}"; var content = "#NowPlaying {song} / {album} / {artist}\n{url}";
} }
var flag = localStorage.getItem("artwork"); var flag = localStorage.getItem("artwork");
var platform = localStorage.getItem("platform"); var platform = localStorage.getItem("platform");
if (platform == "win32") { if (platform == "win32") {
if (flag && arg.path) { if (flag && arg.path) {
media(arg.path, "image/png", "new"); media(arg.path, "image/png", "new");
} }
} else if (platform == "darwin") { } else if (platform == "darwin") {
if (flag && arg.artwork) { if (flag && arg.artwork) {
media(arg.artwork, "image/png", "new"); media(arg.artwork, "image/png", "new");
} }
} }
var regExp = new RegExp("{song}", "g"); var regExp = new RegExp("{song}", "g");
content = content.replace(regExp, arg.name); content = content.replace(regExp, arg.name);
var regExp = new RegExp("{album}", "g"); var regExp = new RegExp("{album}", "g");
if(arg.album){ if (arg.album) {
if(arg.album.name){ if (arg.album.name) {
content = content.replace(regExp, arg.album.name); content = content.replace(regExp, arg.album.name);
} }
} }
var regExp = new RegExp("{artist}", "g"); var regExp = new RegExp("{artist}", "g");
content = content.replace(regExp, arg.artist); content = content.replace(regExp, arg.artist);
var regExp = new RegExp("{url}", "g"); var regExp = new RegExp("{url}", "g");
content = content.replace(regExp, ""); content = content.replace(regExp, "");
var regExp = new RegExp("{composer}", "g"); var regExp = new RegExp("{composer}", "g");
content = content.replace(regExp, arg.composer); content = content.replace(regExp, arg.composer);
var regExp = new RegExp("{hz}", "g"); var regExp = new RegExp("{hz}", "g");
content = content.replace(regExp, arg.sampleRate / 1000 + "kHz"); content = content.replace(regExp, arg.sampleRate / 1000 + "kHz");
var regExp = new RegExp("{lyricist}", "g"); var regExp = new RegExp("{lyricist}", "g");
content = content.replace(regExp, ""); content = content.replace(regExp, "");
var regExp = new RegExp("{bpm}", "g"); var regExp = new RegExp("{bpm}", "g");
content = content.replace(regExp, ""); content = content.replace(regExp, "");
var regExp = new RegExp("{bitRate}", "g"); var regExp = new RegExp("{bitRate}", "g");
content = content.replace(regExp, arg.bitRate + "kbps"); content = content.replace(regExp, arg.bitRate + "kbps");
var regExp = new RegExp("{genre}", "g"); var regExp = new RegExp("{genre}", "g");
content = content.replace(regExp, arg.genre); content = content.replace(regExp, arg.genre);
$("#textarea").val(content); $("#textarea").val(content);
} }
function spotifySave() { function spotifySave() {
var temp = $("#np-temp").val(); var temp = $("#np-temp").val();
localStorage.setItem("np-temp", temp); localStorage.setItem("np-temp", temp);
M.toast({ html: lang.lang_spotify_np, displayLength: 3000 }) M.toast({ html: lang.lang_spotify_np, displayLength: 3000 });
} }
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 == "spotify") { if (mode == "spotify") {
var coder = codex.split(":"); var coder = codex.split(":");
localStorage.setItem("spotify", coder[0]); localStorage.setItem("spotify", coder[0]);
localStorage.setItem("spotify-refresh", coder[1]); localStorage.setItem("spotify-refresh", coder[1]);
} else { } else {
}
}
} }

View File

@ -2,93 +2,96 @@
var todcTrigger = null; var todcTrigger = null;
function todo(mes) { function todo(mes) {
clearInterval(todcTrigger); clearInterval(todcTrigger);
$('#message').text(mes); $("#message").text(mes);
$('#message').fadeIn(); $("#message").fadeIn();
todcTrigger = setTimeout(todc, 4000); todcTrigger = setTimeout(todc, 4000);
} }
function todc() { function todc() {
$('#message').fadeOut(); $("#message").fadeOut();
} }
//reverse //reverse
function bottomReverse() { function bottomReverse() {
$("#bottom").toggleClass("reverse"); $("#bottom").toggleClass("reverse");
$(".leftside").toggleClass("reverse"); $(".leftside").toggleClass("reverse");
if ($("#bottom").hasClass("reverse")) { if ($("#bottom").hasClass("reverse")) {
localStorage.removeItem("reverse") localStorage.removeItem("reverse");
} else { } else {
localStorage.setItem("reverse", "true") localStorage.setItem("reverse", "true");
} }
} }
function tips(mode) { function tips(mode) {
postMessage(["sendSinmpleIpc", "endmem"], "*") postMessage(["sendSinmpleIpc", "endmem"], "*");
clearInterval(clockint); clearInterval(clockint);
clearInterval(spotStart); clearInterval(spotStart);
if (mode == "ver") { if (mode == "ver") {
tipsToggle() tipsToggle();
$("#tips-text").html('<img src="../../img/desk.png" width="20" onclick="todo(\'TheDesk is a nice client!: TheDesk ' + localStorage.getItem("ver") + ' git: '+ gitHash +'\')">TheDesk ' + localStorage.getItem("ver") + ' {'+ gitHash.slice(0, 7) +'} [<i class="material-icons" style="font-size:1.2rem;top: 3px;position: relative;">supervisor_account</i><span id="persons">1+</span>]') $("#tips-text").html('<img src="../../img/desk.png" width="20" onclick="todo(\'TheDesk is a nice client!: TheDesk ' + localStorage.getItem("ver") + " git: " + gitHash + "')\">TheDesk " + localStorage.getItem("ver") + " {" + gitHash.slice(0, 7) + '} [<i class="material-icons" style="font-size:1.2rem;top: 3px;position: relative;">supervisor_account</i><span id="persons">1+</span>]');
localStorage.setItem("tips", "ver") localStorage.setItem("tips", "ver");
} else if (mode == "clock") { } else if (mode == "clock") {
tipsToggle() tipsToggle();
localStorage.setItem("tips", "clock") localStorage.setItem("tips", "clock");
clock() clock();
} else if (mode == "memory") { } else if (mode == "memory") {
tipsToggle() tipsToggle();
localStorage.setItem("tips", "memory") localStorage.setItem("tips", "memory");
startmem(); startmem();
} else if (mode == "trend") { } else if (mode == "trend") {
tipsToggle() tipsToggle();
localStorage.setItem("tips", "trend") localStorage.setItem("tips", "trend");
trendTagonTip() trendTagonTip();
} else if (mode == "spotify") { } else if (mode == "spotify") {
tipsToggle() tipsToggle();
localStorage.setItem("tips", "spotify") localStorage.setItem("tips", "spotify");
var json = nowplaying("spotifytips") var json = nowplaying("spotifytips");
spotifytips(json) spotifytips(json);
} }
} }
//メモリ //メモリ
function startmem() { function startmem() {
postMessage(["sendSinmpleIpc", "startmem"], "*") postMessage(["sendSinmpleIpc", "startmem"], "*");
} }
function renderMem(use, cpu, total){ function renderMem(use, cpu, total) {
$("#tips-text").html(escapeHTML(cpu) + "<br>Memory:" + Math.floor(use / 1024 / 1024 / 102.4) / 10 + "/" + Math.floor(total / 1024 / 1024 / 102.4) / 10 + "GB(" + Math.floor(use / total * 100) + "%)") $("#tips-text").html(escapeHTML(cpu) + "<br>Memory:" + Math.floor(use / 1024 / 1024 / 102.4) / 10 + "/" + Math.floor(total / 1024 / 1024 / 102.4) / 10 + "GB(" + Math.floor((use / total) * 100) + "%)");
} }
//トレンドタグ //トレンドタグ
function trendTagonTip() { function trendTagonTip() {
$(".trendtag").remove(); $(".trendtag").remove();
var domain = "imastodon.net" var domain = "imastodon.net";
var at = localStorage.getItem("acct_" + acct_id + "_at"); var at = localStorage.getItem("acct_" + acct_id + "_at");
var start = "https://" + domain + "/api/v1/trend_tags" var start = "https://" + domain + "/api/v1/trend_tags";
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) {
if (!response.ok) {
response.text().then(function(text) {
setLog(response.url, response.status, text);
});
} }
return response.json(); })
}).catch(function (error) { .then(function(response) {
todo(error); if (!response.ok) {
console.error(error); response.text().then(function(text) {
}).then(function (json) { setLog(response.url, response.status, text);
if (json) { });
var tags = ""; }
json = json.score; return response.json();
Object.keys(json).forEach(function (tag) { })
tags = tags + '<a onclick="tagShow(\'' + tag + '\')" class="pointer">#' + escapeHTML(tag) + '</a><span class="hide" data-tag="' + tag + '"> <a onclick="tagTL(\'tag\',\'' + tag + '\',false,\'add\')" class="pointer" title="#' + tag + 'のタイムライン">TL</a> <a onclick="show();brInsert(\'#' + tag + '\')" class="pointer" title="#' + tag + 'でトゥート">Toot</a></span><br>'; .catch(function(error) {
}); todo(error);
$("#tips-text").html('<div class="trendtag">トレンドタグ<i class="material-icons pointer" onclick="trendTagonTip()" style="font-size:12px">refresh</i>:<br>' + tags + '</div>'); setLog(start, "JSON", error);
trendTagonTipInterval() console.error(error);
} else { })
$("#tips-text").html(""); .then(function(json) {
} if (json) {
}); var tags = "";
json = json.score;
Object.keys(json).forEach(function(tag) {
tags = tags + "<a onclick=\"tagShow('" + tag + '\')" class="pointer">#' + escapeHTML(tag) + '</a><span class="hide" data-tag="' + tag + "\"> <a onclick=\"tagTL('tag','" + tag + '\',false,\'add\')" class="pointer" title="#' + tag + 'のタイムライン">TL</a> <a onclick="show();brInsert(\'#' + tag + '\')" class="pointer" title="#' + tag + 'でトゥート">Toot</a></span><br>';
});
$("#tips-text").html('<div class="trendtag">トレンドタグ<i class="material-icons pointer" onclick="trendTagonTip()" style="font-size:12px">refresh</i>:<br>' + tags + "</div>");
trendTagonTipInterval();
} else {
$("#tips-text").html("");
}
});
} }
//Spotify //Spotify
function spotifytips() { function spotifytips() {
@ -96,64 +99,68 @@ function spotifytips() {
var at = localStorage.getItem("spotify"); var at = localStorage.getItem("spotify");
if (at) { if (at) {
fetch(start, { fetch(start, {
method: 'GET', method: "GET",
headers: { headers: {
'content-type': 'application/json' "content-type": "application/json"
} }
}).then(function (response) { })
if (!response.ok) { .then(function(response) {
response.text().then(function(text) { if (!response.ok) {
setLog(response.url, response.status, text); response.text().then(function(text) {
}); setLog(response.url, response.status, text);
} });
return response.json();
}).catch(function (error) {
todo(error);
console.error(error);
}).then(function (json) {
var ms = json.progress_ms;
var last = 1000 - ms % 1000;
var item = json.item;
var img = item.album.images[0].url;
var artisttxt = "";
for (i = 0; i < item.artists.length; i++) {
if (i > 0) {
artisttxt = artisttxt + "," + item.artists[i].name;
} else {
artisttxt = item.artists[0].name;
} }
} return response.json();
artisttxt = escapeHTML(artisttxt); })
sleep(last); .catch(function(error) {
var tms = item.duration_ms; todo(error);
var per = ms / item.duration_ms * 100; setLog(start, "JSON", error);
ms = ms / 1000; console.error(error);
tms = tms / 1000; })
var s = Math.round(ms) % 60; .then(function(json) {
if (s < 10) { var ms = json.progress_ms;
s = "0" + s; var last = 1000 - (ms % 1000);
} var item = json.item;
var m = (Math.round(ms) - Math.round(ms) % 60) / 60; var img = item.album.images[0].url;
var ts = Math.round(tms) % 60; var artisttxt = "";
if (ts < 10) { for (i = 0; i < item.artists.length; i++) {
ts = "0" + ts; if (i > 0) {
} artisttxt = artisttxt + "," + item.artists[i].name;
var tm = (Math.round(tms) - Math.round(tms) % 60) / 60; } else {
$("#tips-text").html('<div id="spot-box"><i class="material-icons pointer" onclick="spotifytips()" style="font-size:12px">refresh</i><img src="' + img + '" width="20" id="spot-img">' + escapeHTML(item.name) + '<span class="gray sml" id="spot-art">' + artisttxt + '</span><span id="spot-m">' + m + '</span>:<span id="spot-s">' + s + '</span>/' + tm + ":" + ts + '</span></div><div class="progress grey"><div class="determinate spotify-prog grey lighten-2" style="width: ' + per + '%" data-s="' + Math.round(ms) + '" data-total="' + item.duration_ms + '"></div></div>'); artisttxt = item.artists[0].name;
spotint = setInterval(spotStart, 1000); }
}); }
artisttxt = escapeHTML(artisttxt);
sleep(last);
var tms = item.duration_ms;
var per = (ms / item.duration_ms) * 100;
ms = ms / 1000;
tms = tms / 1000;
var s = Math.round(ms) % 60;
if (s < 10) {
s = "0" + s;
}
var m = (Math.round(ms) - (Math.round(ms) % 60)) / 60;
var ts = Math.round(tms) % 60;
if (ts < 10) {
ts = "0" + ts;
}
var tm = (Math.round(tms) - (Math.round(tms) % 60)) / 60;
$("#tips-text").html('<div id="spot-box"><i class="material-icons pointer" onclick="spotifytips()" style="font-size:12px">refresh</i><img src="' + img + '" width="20" id="spot-img">' + escapeHTML(item.name) + '<span class="gray sml" id="spot-art">' + artisttxt + '</span><span id="spot-m">' + m + '</span>:<span id="spot-s">' + s + "</span>/" + tm + ":" + ts + '</span></div><div class="progress grey"><div class="determinate spotify-prog grey lighten-2" style="width: ' + per + '%" data-s="' + Math.round(ms) + '" data-total="' + item.duration_ms + '"></div></div>');
spotint = setInterval(spotStart, 1000);
});
} else { } else {
Swal.fire({ Swal.fire({
type: 'info', type: "info",
title: lang.lang_spotify_acct title: lang.lang_spotify_acct
}) });
} }
} }
function spotStart() { function spotStart() {
var total = $(".spotify-prog").attr("data-total"); var total = $(".spotify-prog").attr("data-total");
var s = $(".spotify-prog").attr("data-s"); var s = $(".spotify-prog").attr("data-s");
var news = s * 1 + 1; var news = s * 1 + 1;
var per = news * 100000 / total; var per = (news * 100000) / total;
var ns = news % 60; var ns = news % 60;
var nm = (news - ns) / 60; var nm = (news - ns) / 60;
if (ns < 10) { if (ns < 10) {
@ -161,7 +168,7 @@ function spotStart() {
} }
if (per >= 100) { if (per >= 100) {
clearInterval(spotStart); clearInterval(spotStart);
spotifytips() spotifytips();
} else { } else {
$("#spot-m").text(nm); $("#spot-m").text(nm);
$("#spot-s").text(ns); $("#spot-s").text(ns);
@ -170,7 +177,6 @@ function spotStart() {
$(".spotify-prog").css("width", per + "%"); $(".spotify-prog").css("width", per + "%");
} }
function trendTagonTipInterval() { function trendTagonTipInterval() {
setTimeout(trendTagonTip, 6000000); setTimeout(trendTagonTip, 6000000);
} }
@ -178,18 +184,24 @@ function trendTagonTipInterval() {
var clockint; var clockint;
function clock() { function clock() {
var now = new Date(); var now = new Date();
var last = 1000 - now.getTime() % 1000; var last = 1000 - (now.getTime() % 1000);
sleep(last); sleep(last);
clockint = setInterval(clockStart, 1000); clockint = setInterval(clockStart, 1000);
} }
function clockStart() { function clockStart() {
var nowTime = new Date(); // 現在日時を得る var nowTime = new Date(); // 現在日時を得る
var nowHour = nowTime.getHours(); // 時を抜き出す var nowHour = nowTime.getHours(); // 時を抜き出す
if (nowHour < 10) { nowHour = "0" + nowHour } if (nowHour < 10) {
nowHour = "0" + nowHour;
}
var nowMin = nowTime.getMinutes(); // 分を抜き出す var nowMin = nowTime.getMinutes(); // 分を抜き出す
if (nowMin < 10) { nowMin = "0" + nowMin } if (nowMin < 10) {
nowMin = "0" + nowMin;
}
var nowSec = nowTime.getSeconds(); // 秒を抜き出す var nowSec = nowTime.getSeconds(); // 秒を抜き出す
if (nowSec < 10) { nowSec = "0" + nowSec } if (nowSec < 10) {
nowSec = "0" + nowSec;
}
var msg = nowTime.getFullYear() + "/" + (nowTime.getMonth() + 1) + "/" + nowTime.getDate() + '<span style="font-size:20px; font-family:Open Sans">' + nowHour + ":" + nowMin + ":" + nowSec + "</span>"; var msg = nowTime.getFullYear() + "/" + (nowTime.getMonth() + 1) + "/" + nowTime.getDate() + '<span style="font-size:20px; font-family:Open Sans">' + nowHour + ":" + nowMin + ":" + nowSec + "</span>";
$("#tips-text").html(msg); $("#tips-text").html(msg);
} }

View File

@ -256,13 +256,24 @@ function system(mainWindow, dir, lang, dirname) {
}); });
ipc.on("getLogs", (e, arg) => { ipc.on("getLogs", (e, arg) => {
var logs="" var logs=""
var todayLog=""
var yestLog=""
var yest2Log=""
fs.readdir(log_dir_path, function(err, files) { fs.readdir(log_dir_path, function(err, files) {
if (err) throw err; if (err) throw err;
files.filter(function(file) { files.filter(function(file) {
if (file == todayStr || file == yestStr || file == yest2Str) { if (file == todayStr) {
logs=logs+fs.readFileSync(join(log_dir_path, file), "utf8") todayLog=fs.readFileSync(join(log_dir_path, file), "utf8")
} }
if (file == yestStr) {
yestLog=logs+fs.readFileSync(join(log_dir_path, file), "utf8")
}
if (file == yest2Str) {
yest2Log=fs.readFileSync(join(log_dir_path, file), "utf8")
}
logs = todayLog + yestLog + yest2Log;
}); });
logs = yest2Log + yestLog + todayLog;
e.sender.webContents.send("logData", logs); e.sender.webContents.send("logData", logs);
}); });
}); });

View File

@ -156,7 +156,7 @@
return response.json(); return response.json();
}) })
.catch(function(error) { .catch(function(error) {
todo(error); todo(error);setLog(start, "JSON", error);
console.error(error); console.error(error);
}) })
.then(function(json) { .then(function(json) {
@ -228,7 +228,7 @@
return response.json(); return response.json();
}) })
.catch(function(error) { .catch(function(error) {
todo(error); todo(error);setLog(start, "JSON", error);
console.error(error); console.error(error);
}) })
.then(function(json) { .then(function(json) {