Add list on misskey

This commit is contained in:
Cutls 2019-04-08 00:14:06 +09:00
parent 50bfbbd755
commit f1c4276d06
8 changed files with 270 additions and 60 deletions

View File

@ -57,14 +57,8 @@ function load() {
localStorage.setItem("acct", 0);
var acctN = 0;
}
var electron = require("electron");
var remote=electron.remote;
var platform=remote.process.platform;
if(localStorage.getItem("winstore")!="localinstall"){
$("#linux").prop("checked", false);
}else{
//全部チェックアリでいいと思うの
$("#linux").prop("checked", true);
}
}
//最初に読む

View File

@ -13,6 +13,32 @@ function list(){
var acct_id = $("#list-acct-sel").val();
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem("acct_"+ acct_id + "_at");
if(localStorage.getItem("mode_" + domain)=="misskey"){
var start = "https://" + domain + "/api/users/lists/list"
fetch(start, {
method: 'POST',
body: JSON.stringify({
i:at
}),
}).then(function(response) {
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 + '\',\'' + list.title + '\',\'' + acct_id +
'\')" class="pointer">'+lang.lang_list_show+'</a>';
});
$("#lists").html(lists);
}else{
$("#lists").html(lang.lang_list_nodata);
}
});
}else{
var start = "https://" + domain + "/api/v1/lists"
console.log(start)
fetch(start, {
@ -31,9 +57,9 @@ function list(){
var lists = "";
Object.keys(json).forEach(function(key) {
var list = json[key];
lists = lists + list.title+':<a onclick="listShow(' + list.id + ',\'' + 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 = lists + list.title+':<a onclick="listShow(\'' + list.id + '\',\'' + 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';
});
$("#lists").html(lists);
}else{
@ -41,11 +67,13 @@ function list(){
}
});
}
}
function makeNewList(){
var acct_id = $("#list-acct-sel").val();
var text=$("#list-add").val();
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem("acct_"+ acct_id + "_at");
if(localStorage.getItem("mode_" + domain)!="misskey"){
var start = "https://" + domain + "/api/v1/lists"
console.log(start)
var httpreq = new XMLHttpRequest();
@ -63,6 +91,25 @@ function makeNewList(){
$("#list-add").val("")
}
}
}else{
var start = "https://" + domain + "/users/lists/create"
console.log(start)
var httpreq = new XMLHttpRequest();
httpreq.open('POST', start, true);
httpreq.setRequestHeader('Content-Type', 'application/json');
httpreq.responseType = "json";
httpreq.send(JSON.stringify({
i:at,
title: text
}));
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
var json = httpreq.response;
list();
$("#list-add").val("")
}
}
}
}
function listShow(id,title,acct_id){
localStorage.setItem("list_"+id+"_"+acct_id,title);
@ -100,6 +147,7 @@ function listUser(id,acct_id){
function hisList(user,acct_id){
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem("acct_"+ acct_id + "_at");
if(localStorage.getItem("mode_" + domain)!="misskey"){
var start = "https://" + domain + "/api/v1/lists"
console.log(start)
fetch(start, {
@ -118,7 +166,7 @@ function hisList(user,acct_id){
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 +
lists = lists + '<a onclick="listAdd(\'' + list.id + '\',\'' + user + '\',\'' + acct_id +
'\')" class="pointer">'+escapeHTML(list.title)+'</a><br> ';
});
$("#his-lists-a").html(lists);
@ -144,7 +192,7 @@ function hisList(user,acct_id){
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 +
lists = lists + '<a onclick="listRemove(\'' + list.id + '\',\'' + user + '\',\'' + acct_id +
'\')" class="pointer">'+list.title+'</a><br> ';
});
$("#his-lists-b").html(lists);
@ -152,20 +200,57 @@ function hisList(user,acct_id){
$("#his-lists-b").html(lang.lang_list_nodata);
}
});
}else{
var start = "https://" + domain + "/api/users/lists/list"
fetch(start, {
method: 'POST',
body: JSON.stringify({
i:at
}),
}).then(function(response) {
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 + '\',\'' + list.title + '\',\'' + acct_id +
'\')" class="pointer">'+lang.lang_list_show+'</a>';
});
$("#his-lists-a").html(lists);
}else{
$("#his-lists-a").html(lang.lang_list_nodata);
}
});
$("#his-lists-b").html("");
}
}
function listAdd(id,user,acct_id){
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem("acct_"+ acct_id + "_at");
if(localStorage.getItem("mode_" + domain)=="misskey"){
var start = "https://" + domain + "/api/users/lists/push"
var i={
i:at,
listId:id,
userId:user
}
}else{
var start = "https://" + domain + "/api/v1/lists/"+id+"/accounts"
var i={
account_ids: [user]
}
}
console.log(start)
var httpreq = new XMLHttpRequest();
httpreq.open('POST', start, true);
httpreq.setRequestHeader('Content-Type', 'application/json');
httpreq.setRequestHeader('Authorization', 'Bearer ' + at);
httpreq.responseType = "json";
httpreq.send(JSON.stringify({
account_ids: [user]
}));
httpreq.send(JSON.stringify(i));
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
var json = httpreq.response;
@ -176,16 +261,28 @@ function listAdd(id,user,acct_id){
function listRemove(id,user,acct_id){
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem("acct_"+ acct_id + "_at");
if(localStorage.getItem("mode_" + domain)=="misskey"){
var start = "https://" + domain + "/api/users/lists/push"
var method='POST'
var i={
i:at,
listId:id,
userId:user
}
}else{
var start = "https://" + domain + "/api/v1/lists/"+id+"/accounts"
var method='DELETE'
var i={
account_ids: [user]
}
}
console.log(start)
var httpreq = new XMLHttpRequest();
httpreq.open('DELETE', start, true);
httpreq.open(method, start, true);
httpreq.setRequestHeader('Content-Type', 'application/json');
httpreq.setRequestHeader('Authorization', 'Bearer ' + at);
httpreq.responseType = "json";
httpreq.send(JSON.stringify({
account_ids: [user]
}));
httpreq.send(JSON.stringify(i));
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
var json = httpreq.response;

View File

@ -164,6 +164,7 @@ function reload(type, cc, acct_id, tlid, data, mute, delc, voice, mode) {
localStorage.setItem("now", type);
if(localStorage.getItem("mode_" + domain)=="misskey"){
var misskey=true;
console.log(type);
if (type == "home") {
var start = "wss://" + domain +
"/?i=" + at;
@ -183,12 +184,12 @@ function reload(type, cc, acct_id, tlid, data, mute, delc, voice, mode) {
var start = "wss://" + domain +
"/hybrid-timeline?i=" + at;
} else if (type == "tag") {
Materialize.toast(lang_misskeyparse_tagnostr[lang], 1000);
Materialize.toast(lang.lang_misskeyparse_tagnostr, 3000);
} else if (type == "noauth") {
var start = "wss://" + acct_id +
"/local-timeline?i=" + at;
} else if (type=="list"){
Materialize.toast(lang_misskeyparse_listnostr[lang], 1000);
Materialize.toast(lang.lang_misskeyparse_listnostr, 3000);
}
}else{
var misskey=false;
@ -463,6 +464,115 @@ function moreload(type, tlid) {
});
}
}
//TL差分取得
function tlDiff(type, data, acct_id, tlid, delc, voice, mode) {
console.log("sabun")
var multi = localStorage.getItem("column");
var obj = JSON.parse(multi);
var acct_id = obj[tlid].domain;
if (!type) {
var type = obj[tlid].type;
}else{
var data;
}
if(type=="tag"){
var data=obj[tlid].data;
var tag = localStorage.getItem("tag-range");
if(tag=="local"){
data=data+"&local=true";
}
}else if(type=="list"){
var data=obj[tlid].data;
}
var sid = $("#timeline_" + tlid + " .cvo").first().attr("unique-id");
if (sid && !moreloading) {
if (type == "mix" && localStorage.getItem("mode_" + localStorage.getItem("domain_" + acct_id))!="misskey") {
return;
}else if (type == "plus" && localStorage.getItem("mode_" + localStorage.getItem("domain_" + acct_id))!="misskey") {
return;
}else if (type == "notf") {
return;
}
moreloading=true;
localStorage.setItem("now", type);
todo(cap(type) + " TL MoreLoading");
if(type!="noauth"){
var at = localStorage.getItem("acct_"+ acct_id + "_at");
var hdr={
'content-type': 'application/json',
'Authorization': 'Bearer ' + at
};
var domain = localStorage.getItem("domain_" + acct_id);
}else{
var hdr={
'content-type': 'application/json'
};
domain=acct_id;
}
if(localStorage.getItem("mode_" + domain)=="misskey"){
var misskey=true;
hdr={
'content-type': 'application/json'
};
var url=misskeycom(type, data);
var start = "https://" + domain + "/api/notes/"+url;
var method="POST";
var req={};
if(type!="noauth"){
req.i=at;
}
if(type=="local-media"||type=="pub-media"){
req.mediaOnly=true;
}
if(type=="tag"){
req.tag=data;
}
if(type=="list"){
req.listId=data;
}
req.sinceId=sid;
req.limit=20;
var i={
method: method,
headers: hdr,
body: JSON.stringify(req),
}
}else{
var misskey=false;
var start = "https://" + domain + "/api/v1/timelines/" + com(type,data) +
"since_id=" + sid;
if(type=="dm"){
var start = "https://" + domain + "/api/v1/conversations?" +
"since_id=" + sid;
}
var method="GET";
var i={
method: method,
headers: hdr
};
}
fetch(start, i).then(function(response) {
return response.json();
}).catch(function(error) {
todo(error);
console.error(error);
}).then(function(json) {
console.log(json);
if(misskey){
var templete = misskeyParse(json, '', acct_id, tlid,"",mute);
}else{
var templete = parse(json, '', acct_id, tlid,"",mute, type);
}
$("#timeline_" + tlid).prepend(templete);
additional(acct_id, tlid);
jQuery("time.timeago").timeago();
moreloading=false;
todc();
});
}
}
//WebSocket切断
function tlCloser() {

View File

@ -168,7 +168,7 @@ function parseColumn() {
}
var html='<div class="boxIn" id="timeline_box_' + key + '_box" tlid="' + key +
'" data-acct="'+acct.domain+'"><div class="notice-box z-depth-2" id="menu_'+key+'" style="'+insert+' ">'+
'<div class="area-notice"><i class="material-icons waves-effect red-text" id="notice_icon_' + key + '"'+notf_attr+' style="font-size:40px; padding-top:25%;" onclick="goTop(' + key + ')" title="'+lang.lang_layout_gotop +'"></i></div>'+
'<div class="area-notice"><i class="material-icons waves-effect red-text" id="notice_icon_' + key + '"'+notf_attr+' style="font-size:40px; padding-top:25%;" onclick="checkStr(\''+acct.type+'\', \''+data+'\', \''+acct.domain+'\', \''+key+'\', \''+delc+'\',\''+voice+'\',null)" title="'+lang.lang_layout_gotop +'"></i></div>'+
'<div class="area-notice_name"><span id="notice_' + key + '" class="tl-title"></span></div>'+
'<div class="area-a1"><a onclick="notfToggle(' + acct.domain + ',' + key +
')" class="setting nex '+if_notf+'" title="'+unique_notf+'"'+icnsert+'><i class="material-icons waves-effect nex notf-icon_' +
@ -240,6 +240,15 @@ function parseColumn() {
}
}
}
function checkStr(type, data, acct_id, key, delc,voice){
if($('#notice_icon_' + key).hasClass("red-text") && type!="notf" && type!="mix"){
console.log("sabun-get")
goTop(key);
tlDiff(type, data, acct_id, key, delc,voice,"");
}else{
goTop(key);
}
}
//セカンダリートゥートボタン
function secvis(set){
if(set=="public"){

View File

@ -49,7 +49,7 @@ body,html{overflow-y: scroll;}
<div class="col s6">
<input type="text" id="url" style="width:70%" placeholder="ex)mstdn.jp">
<div id="ins-suggest"></div>
Check if TheDesk is not working on Windows, you want to login Pleroma servers, you cannot login when it checked.<br>
Uncheck it to skip pasiting code.(login to Mastodon on Windows or macOS) (Recommended: pcheck)<br>
<input type="checkbox" class="filled-in" id="linux" />
<label for="linux">Code setup</label><br>
<input type="checkbox" class="filled-in" id="misskey" />

View File

@ -49,7 +49,7 @@ body,html{overflow-y: scroll;}
<div class="col s6">
<input type="text" id="url" style="width:70%" placeholder="ex)mstdn.jp">
<div id="ins-suggest"></div>
Windows以外でご使用の方やPleromaにログインされる方はチェックを入れて下さい。ログインできない場合、チェックを外してください。<br>
チェックを外すとコード貼り付けをスキップできます。(<u>Mastodon</u>にWindowsやmacOSからログインする場合)失敗する場合はチェックを入れてください。<br>
<input type="checkbox" class="filled-in" id="linux" />
<label for="linux">コードセットアップ</label><br>
<input type="checkbox" class="filled-in" id="misskey" />

View File

@ -2,7 +2,7 @@
"list":"List of accounts",
"back":"Back",
"add":"Add an account",
"codesetupwarn":"Check if TheDesk is not working on Windows, you want to login Pleroma servers, you cannot login when it checked.",
"codesetupwarn":"Uncheck it to skip pasiting code.(login to Mastodon on Windows or macOS) (Recommended: pcheck)",
"codesetup":"Code setup",
"mainacct":"Main an account",
"selacct":"Select an account",

View File

@ -2,7 +2,7 @@
"list":"アカウント一覧",
"back":"戻る",
"add":"アカウントを追加",
"codesetupwarn":"Windows以外でご使用の方やPleromaにログインされる方はチェックを入れて下さい。ログインできない場合、チェックを外してください。",
"codesetupwarn":"チェックを外すとコード貼り付けをスキップできます。(<u>Mastodon</u>にWindowsやmacOSからログインする場合)失敗する場合はチェックを入れてください。",
"codesetup":"コードセットアップ",
"mainacct":"メインアカウント",
"selacct":"アカウントを選択",