From 36ad187296f74ae3ed6cb12a4ef26b27d8d13d0f Mon Sep 17 00:00:00 2001 From: cutls Date: Wed, 2 Jun 2021 15:59:36 +0900 Subject: [PATCH] with acct lookup --- .prettierrc | 8 + app/js/post/status.js | 1258 ++++++++++++++++++----------------- app/js/tl/filter.js | 1006 ++++++++++++++-------------- app/js/tl/notification.js | 827 +++++++++++------------ app/js/ui/settings.js | 43 +- app/js/userdata/showOnTL.js | 1146 +++++++++++++++---------------- app/view/pl-PL/index.html | 2 +- app/view/pl-PL/setting.html | 4 +- 8 files changed, 2174 insertions(+), 2120 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..216ef32a --- /dev/null +++ b/.prettierrc @@ -0,0 +1,8 @@ +{ + "tabWidth": 4, + "useTabs": true, + "semi": false, + "singleQuote": true, + "printWidth": 200, + "jsxBracketSameLine": true +} \ No newline at end of file diff --git a/app/js/post/status.js b/app/js/post/status.js index 8b0797ec..4cbf0984 100644 --- a/app/js/post/status.js +++ b/app/js/post/status.js @@ -1,685 +1,703 @@ //お気に入り登録やブースト等、フォローやブロック等 //お気に入り登録 function fav(id, acct_id, remote) { - if ($(`.cvo[unique-id=${id}]`).hasClass('faved')) { - var flag = 'unfavourite' - } else { - var flag = 'favourite' - } - var domain = localStorage.getItem('domain_' + acct_id) - var at = localStorage.getItem('acct_' + acct_id + '_at') - var start = 'https://' + domain + '/api/v1/statuses/' + id + '/' + flag - 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() - httpreq.onreadystatechange = function () { - if (httpreq.readyState === 4) { - var json = httpreq.response - if (this.status !== 200) { - setLog(start, this.status, json) - } - if (json.reblog) { - json = json.reblog - } - if (remote != 'remote') { - //APIのふぁぼカウントがおかしい - if ($('[unique-id=' + id + '] .fav_ct').text() == json.favourites_count) { - if (flag == 'unfavourite') { - var fav = json.favourites_count - 1 - if (fav * 1 < 0) { - fav = 0 - } - } else { - var fav = json.favourites_count - //var fav = json.favourites_count; - } - } else { - var fav = json.favourites_count - } - $('[unique-id=' + id + '] .fav_ct').text(fav) - $('[unique-id=' + id + '] .rt_ct').text(json.reblogs_count) - if ($('[unique-id=' + id + ']').hasClass('faved')) { - $('[unique-id=' + id + ']').removeClass('faved') - $('.fav_' + id).removeClass('yellow-text') - } else { - $('[unique-id=' + id + ']').addClass('faved') - $('.fav_' + id).addClass('yellow-text') - } - } else { - M.toast({ html: lang.lang_status_favWarn, displayLength: 1000 }) - } - } - } + if ($(`.cvo[unique-id=${id}]`).hasClass('faved')) { + var flag = 'unfavourite' + } else { + var flag = 'favourite' + } + var domain = localStorage.getItem('domain_' + acct_id) + var at = localStorage.getItem('acct_' + acct_id + '_at') + var start = 'https://' + domain + '/api/v1/statuses/' + id + '/' + flag + 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() + httpreq.onreadystatechange = function() { + if (httpreq.readyState === 4) { + var json = httpreq.response + if (this.status !== 200) { + setLog(start, this.status, json) + } + if (json.reblog) { + json = json.reblog + } + if (remote != 'remote') { + //APIのふぁぼカウントがおかしい + if ($('[unique-id=' + id + '] .fav_ct').text() == json.favourites_count) { + if (flag == 'unfavourite') { + var fav = json.favourites_count - 1 + if (fav * 1 < 0) { + fav = 0 + } + } else { + var fav = json.favourites_count + //var fav = json.favourites_count; + } + } else { + var fav = json.favourites_count + } + $('[unique-id=' + id + '] .fav_ct').text(fav) + $('[unique-id=' + id + '] .rt_ct').text(json.reblogs_count) + if ($('[unique-id=' + id + ']').hasClass('faved')) { + $('[unique-id=' + id + ']').removeClass('faved') + $('.fav_' + id).removeClass('yellow-text') + } else { + $('[unique-id=' + id + ']').addClass('faved') + $('.fav_' + id).addClass('yellow-text') + } + } else { + M.toast({ html: lang.lang_status_favWarn, displayLength: 1000 }) + } + } + } } //ブースト function rt(id, acct_id, remote, vis) { - if ($(`.cvo[toot-id=${id}]`).hasClass('rted')) { - var flag = 'unreblog' - } else { - var flag = 'reblog' - } - var domain = localStorage.getItem('domain_' + acct_id) - var at = localStorage.getItem('acct_' + acct_id + '_at') - var start = 'https://' + domain + '/api/v1/statuses/' + id + '/' + flag - var httpreq = new XMLHttpRequest() - httpreq.open('POST', start, true) - httpreq.setRequestHeader('Content-Type', 'application/json') - httpreq.setRequestHeader('Authorization', 'Bearer ' + at) - httpreq.responseType = 'json' - if (vis) { - httpreq.send(JSON.stringify({ visibility: vis })) - } else { - httpreq.send() - } - httpreq.onreadystatechange = function () { - if (httpreq.readyState === 4) { - var json = httpreq.response - if (this.status !== 200) { - setLog(start, this.status, json) - } - if (json.reblog) { - json = json.reblog - } - console.log(['Success: boost', json]) - $('[toot-id=' + id + '] .fav_ct').text(json.favourites_count) - if (!json.reblog) { - if (flag == 'unreblog') { - var rt = json.reblogs_count - 1 - if (rt * 1 < 0) { - rt = 0 - } - } else { - var rt = json.reblogs_count - } - $('[toot-id=' + id + '] .rt_ct').text(rt) - } else { - $('[toot-id=' + id + '] .rt_ct').text(json.reblogs_count) - } + if ($(`.cvo[toot-id=${id}]`).hasClass('rted')) { + var flag = 'unreblog' + } else { + var flag = 'reblog' + } + var domain = localStorage.getItem('domain_' + acct_id) + var at = localStorage.getItem('acct_' + acct_id + '_at') + var start = 'https://' + domain + '/api/v1/statuses/' + id + '/' + flag + var httpreq = new XMLHttpRequest() + httpreq.open('POST', start, true) + httpreq.setRequestHeader('Content-Type', 'application/json') + httpreq.setRequestHeader('Authorization', 'Bearer ' + at) + httpreq.responseType = 'json' + if (vis) { + httpreq.send(JSON.stringify({ visibility: vis })) + } else { + httpreq.send() + } + httpreq.onreadystatechange = function() { + if (httpreq.readyState === 4) { + var json = httpreq.response + if (this.status !== 200) { + setLog(start, this.status, json) + } + if (json.reblog) { + json = json.reblog + } + console.log(['Success: boost', json]) + $('[toot-id=' + id + '] .fav_ct').text(json.favourites_count) + if (!json.reblog) { + if (flag == 'unreblog') { + var rt = json.reblogs_count - 1 + if (rt * 1 < 0) { + rt = 0 + } + } else { + var rt = json.reblogs_count + } + $('[toot-id=' + id + '] .rt_ct').text(rt) + } else { + $('[toot-id=' + id + '] .rt_ct').text(json.reblogs_count) + } - if ($('[toot-id=' + id + ']').hasClass('rted')) { - $('[toot-id=' + id + ']').removeClass('rted') - $('.rt_' + id).removeClass('light-blue-text') - } else { - $('[toot-id=' + id + ']').addClass('rted') - $('.rt_' + id).addClass('light-blue-text') - } - } - } + if ($('[toot-id=' + id + ']').hasClass('rted')) { + $('[toot-id=' + id + ']').removeClass('rted') + $('.rt_' + id).removeClass('light-blue-text') + } else { + $('[toot-id=' + id + ']').addClass('rted') + $('.rt_' + id).addClass('light-blue-text') + } + } + } } + function boostWith(vis) { - var id = $('#tootmodal').attr('data-id') - var acct_id = $('#tootmodal').attr('data-acct') - rt(id, acct_id, false, vis) + var id = $('#tootmodal').attr('data-id') + var acct_id = $('#tootmodal').attr('data-acct') + rt(id, acct_id, false, vis) } //ブックマーク function bkm(id, acct_id, tlid) { - if ($(`.cvo[unique-id=${id}]`).hasClass('bkmed')) { - var flag = 'unbookmark' - } else { - var flag = 'bookmark' - } - var domain = localStorage.getItem('domain_' + acct_id) - var at = localStorage.getItem('acct_' + acct_id + '_at') - var start = 'https://' + domain + '/api/v1/statuses/' + id + '/' + flag - 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() - httpreq.onreadystatechange = function () { - if (httpreq.readyState === 4) { - var json = httpreq.response - if (this.status !== 200) { - setLog(start, this.status, json) - } - if (json.reblog) { - json = json.reblog - } - var fav = json.favourites_count - $('[toot-id=' + id + '] .fav_ct').text(fav) - $('[toot-id=' + id + '] .rt_ct').text(json.reblogs_count) - if (flag == 'unbookmark') { - $('.bkmStr_' + id).text(lang.lang_parse_bookmark) - $('.bkm_' + id).removeClass('red-text') - $('[toot-id=' + id + ']').removeClass('bkmed') - } else { - $('.bkmStr_' + id).text(lang.lang_parse_unbookmark) - $('.bkm_' + id).addClass('red-text') - $('[toot-id=' + id + ']').addClass('bkmed') - } - var tlidTar = $(`.bookmark-timeline[data-acct=${acct_id}]`).attr('tlid') - columnReload(tlidTar, 'bookmark') - } - } + if ($(`.cvo[unique-id=${id}]`).hasClass('bkmed')) { + var flag = 'unbookmark' + } else { + var flag = 'bookmark' + } + var domain = localStorage.getItem('domain_' + acct_id) + var at = localStorage.getItem('acct_' + acct_id + '_at') + var start = 'https://' + domain + '/api/v1/statuses/' + id + '/' + flag + 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() + httpreq.onreadystatechange = function() { + if (httpreq.readyState === 4) { + var json = httpreq.response + if (this.status !== 200) { + setLog(start, this.status, json) + } + if (json.reblog) { + json = json.reblog + } + var fav = json.favourites_count + $('[toot-id=' + id + '] .fav_ct').text(fav) + $('[toot-id=' + id + '] .rt_ct').text(json.reblogs_count) + if (flag == 'unbookmark') { + $('.bkmStr_' + id).text(lang.lang_parse_bookmark) + $('.bkm_' + id).removeClass('red-text') + $('[toot-id=' + id + ']').removeClass('bkmed') + } else { + $('.bkmStr_' + id).text(lang.lang_parse_unbookmark) + $('.bkm_' + id).addClass('red-text') + $('[toot-id=' + id + ']').addClass('bkmed') + } + var tlidTar = $(`.bookmark-timeline[data-acct=${acct_id}]`).attr('tlid') + columnReload(tlidTar, 'bookmark') + } + } } //フォロー async function follow(acct_id, resolve) { - if ($('#his-data').hasClass('locked')) { - locked = true - } else { - locked = false - } - if (!acct_id && acct_id != 'selector') { - var acct_id = $('#his-data').attr('use-acct') + if ($('#his-data').hasClass('locked')) { + locked = true + } else { + locked = false + } + if (!acct_id && acct_id != 'selector') { + var acct_id = $('#his-data').attr('use-acct') + } else if (acct_id == 'selector') { + var acct_id = $('#user-acct-sel').val() + } + if (!resolve && $('#his-data').hasClass('following')) { + var flag = 'unfollow' + var flagm = 'delete' + } else { + var flag = 'follow' + var flagm = 'create' + } - } else if (acct_id == 'selector') { - var acct_id = $('#user-acct-sel').val() - } - if (!resolve && $('#his-data').hasClass('following')) { - var flag = 'unfollow' - var flagm = 'delete' - } else { - var flag = 'follow' - var flagm = 'create' - } - - var id = $('#his-data').attr('user-id') - if (resolve == 'selector') { - var fullacct = $('#his-acct').attr('fullname') - var id = await acctResolve(acct_id, fullacct) - console.log(id) - } - var domain = localStorage.getItem('domain_' + acct_id) - var at = localStorage.getItem('acct_' + acct_id + '_at') - var start = 'https://' + domain + '/api/v1/accounts/' + id + '/' + flag - if (localStorage.getItem('mode_' + domain) == 'misskey') { - var start = 'https://' + domain + '/api/following/' + flagm - var ent = { i: at, userId: id } - } else if (flag == 'follow') { - var ent = {} - } - 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(ent)) - httpreq.onreadystatechange = function () { - if (httpreq.readyState === 4) { - var json = httpreq.response - if (this.status !== 200) { - setLog(start, this.status, json) - } - console.log(['Success: folllow', json]) - if ($('#his-data').hasClass('following')) { - $('#his-data').removeClass('following') - $('#his-follow-btn-text').text(lang.lang_status_follow) - } else { - $('#his-data').addClass('following') - if (locked) { - $('#his-follow-btn-text').text(lang.lang_status_requesting) - } else { - $('#his-follow-btn-text').text(lang.lang_status_unfollow) - } - } - } - } + var id = $('#his-data').attr('user-id') + if (resolve == 'selector') { + var fullacct = $('#his-acct').attr('fullname') + var data = await acctResolve(acct_id, fullacct) + var { id } = data + console.log(id) + } + var domain = localStorage.getItem('domain_' + acct_id) + var at = localStorage.getItem('acct_' + acct_id + '_at') + var start = 'https://' + domain + '/api/v1/accounts/' + id + '/' + flag + if (localStorage.getItem('mode_' + domain) == 'misskey') { + var start = 'https://' + domain + '/api/following/' + flagm + var ent = { i: at, userId: id } + } else if (flag == 'follow') { + var ent = {} + } + 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(ent)) + httpreq.onreadystatechange = function() { + if (httpreq.readyState === 4) { + var json = httpreq.response + if (this.status !== 200) { + setLog(start, this.status, json) + } + console.log(['Success: folllow', json]) + if ($('#his-data').hasClass('following')) { + $('#his-data').removeClass('following') + $('#his-follow-btn-text').text(lang.lang_status_follow) + } else { + $('#his-data').addClass('following') + if (locked) { + $('#his-follow-btn-text').text(lang.lang_status_requesting) + } else { + $('#his-follow-btn-text').text(lang.lang_status_unfollow) + } + } + } + } } async function acctResolve(acct_id, user) { - console.log('Get user data of ' + user) - var domain = localStorage.getItem('domain_' + acct_id) - if (localStorage.getItem('mode_' + domain) == 'misskey') { - return false - } - var at = localStorage.getItem('acct_' + acct_id + '_at') - var start = 'https://' + domain + '/api/v2/search?resolve=true&q=' + user - let promise = await fetch(start, { - method: 'GET', - headers: { - 'content-type': 'application/json', - Authorization: 'Bearer ' + at - } - }) - var idJson = await promise.json() - if (idJson.accounts[0]) { - var id = idJson.accounts[0].id - } else { - M.toast({ html: lang.lang_fatalerroroccured, displayLength: 2000 }) - } - return id -} + console.log('Get user data of ' + user) + const domain = localStorage.getItem('domain_' + acct_id) + if (localStorage.getItem('mode_' + domain) == 'misskey') { + return false + } + const at = localStorage.getItem('acct_' + acct_id + '_at') + const options = { + method: 'GET', + headers: { + 'content-type': 'application/json', + Authorization: 'Bearer ' + at, + }, + } + try { + const start = `https://${domain}/api/v1/accounts/lookup?acct=${user}` + const promise = fetch(start, options) + const idJson = await promise.json() + if (idJson) { + return idJson + } else { + return await acctResolveLegacy(domain, user, options) + } + } catch { + return await acctResolveLegacy(domain, user, options) + } +} +async function acctResolveLegacy(domain, user, options) { + console.log(`Get user data of ${user} with legacy method`) + try { + const start = 'https://' + domain + '/api/v2/search?resolve=true&q=' + user + const promise = fetch(start, options) + const idJson = await promise.json() + if (idJson.accounts[0]) { + return idJson.accounts[0] + } else { + M.toast({ html: lang.lang_fatalerroroccured, displayLength: 2000 }) + } + } catch { + console.log('Error occured on searching and fetching with resolve') + } +} //ブロック function block(acct_id) { - if ($('#his-data').hasClass('blocking')) { - var flag = 'unblock' - var txt = lang.lang_status_unmute - } else { - var flag = 'block' - var txt = lang.lang_status_block - } - Swal.fire({ - title: txt, - text: '', - type: 'warning', - showCancelButton: true, - confirmButtonText: lang.lang_yesno, - cancelButtonText: lang.lang_no - }).then(result => { - if (result.value) { - if (!acct_id) { - var acct_id = $('#his-data').attr('use-acct') - } - var id = $('#his-data').attr('user-id') - var domain = localStorage.getItem('domain_' + acct_id) - var at = localStorage.getItem('acct_' + acct_id + '_at') - var start = 'https://' + domain + '/api/v1/accounts/' + id + '/' + flag - 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() - httpreq.onreadystatechange = function () { - if (httpreq.readyState === 4) { - if (this.status !== 200) { - setLog(start, this.status, this.response) - } - if ($('#his-data').hasClass('blocking')) { - $('#his-data').removeClass('blocking') - $('#his-block-btn-text').text(lang.lang_status_block) - } else { - $('#his-data').addClass('blocking') - $('#his-block-btn-text').text(lang.lang_status_unblock) - } - } - } - } - }) + if ($('#his-data').hasClass('blocking')) { + var flag = 'unblock' + var txt = lang.lang_status_unmute + } else { + var flag = 'block' + var txt = lang.lang_status_block + } + Swal.fire({ + title: txt, + text: '', + type: 'warning', + showCancelButton: true, + confirmButtonText: lang.lang_yesno, + cancelButtonText: lang.lang_no, + }).then((result) => { + if (result.value) { + if (!acct_id) { + var acct_id = $('#his-data').attr('use-acct') + } + var id = $('#his-data').attr('user-id') + var domain = localStorage.getItem('domain_' + acct_id) + var at = localStorage.getItem('acct_' + acct_id + '_at') + var start = 'https://' + domain + '/api/v1/accounts/' + id + '/' + flag + 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() + httpreq.onreadystatechange = function() { + if (httpreq.readyState === 4) { + if (this.status !== 200) { + setLog(start, this.status, this.response) + } + if ($('#his-data').hasClass('blocking')) { + $('#his-data').removeClass('blocking') + $('#his-block-btn-text').text(lang.lang_status_block) + } else { + $('#his-data').addClass('blocking') + $('#his-block-btn-text').text(lang.lang_status_unblock) + } + } + } + } + }) } //ミュート function muteDo(acct_id) { - if ($('#his-data').hasClass('muting')) { - var flag = 'unmute' - var flagm = 'delete' - var txt = lang.lang_status_unmute - } else { - var flag = 'mute' - var flagm = 'create' - var txt = lang.lang_status_mute - } - Swal.fire({ - title: txt, - text: '', - type: 'warning', - showCancelButton: true, - confirmButtonText: lang.lang_yesno, - cancelButtonText: lang.lang_no - }).then(result => { - if (result.value) { - if (!acct_id) { - var acct_id = $('#his-data').attr('use-acct') - } - var id = $('#his-data').attr('user-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/mute/' + flagm - var ent = { i: at, userId: id } - var rq = JSON.stringify(ent) - } else { - var start = 'https://' + domain + '/api/v1/accounts/' + id + '/' + flag - var rq = '' - } - 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(rq) - httpreq.onreadystatechange = function () { - if (httpreq.readyState === 4) { - if (this.status !== 200) { - setLog(start, this.status, this.response) - } - if ($('#his-data').hasClass('muting')) { - $('#his-data').removeClass('muting') - $('#his-mute-btn-text').text(lang.lang_status_mute) - } else { - $('#his-data').addClass('muting') - $('#his-mute-btn-text').text(lang.lang_status_unmute) - } - } - } - } - }) + if ($('#his-data').hasClass('muting')) { + var flag = 'unmute' + var flagm = 'delete' + var txt = lang.lang_status_unmute + } else { + var flag = 'mute' + var flagm = 'create' + var txt = lang.lang_status_mute + } + Swal.fire({ + title: txt, + text: '', + type: 'warning', + showCancelButton: true, + confirmButtonText: lang.lang_yesno, + cancelButtonText: lang.lang_no, + }).then((result) => { + if (result.value) { + if (!acct_id) { + var acct_id = $('#his-data').attr('use-acct') + } + var id = $('#his-data').attr('user-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/mute/' + flagm + var ent = { i: at, userId: id } + var rq = JSON.stringify(ent) + } else { + var start = 'https://' + domain + '/api/v1/accounts/' + id + '/' + flag + var rq = '' + } + 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(rq) + httpreq.onreadystatechange = function() { + if (httpreq.readyState === 4) { + if (this.status !== 200) { + setLog(start, this.status, this.response) + } + if ($('#his-data').hasClass('muting')) { + $('#his-data').removeClass('muting') + $('#his-mute-btn-text').text(lang.lang_status_mute) + } else { + $('#his-data').addClass('muting') + $('#his-mute-btn-text').text(lang.lang_status_unmute) + } + } + } + } + }) } //投稿削除 function del(id, 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/notes/delete' - var httpreq = new XMLHttpRequest() - httpreq.open('POST', start, true) - httpreq.setRequestHeader('Content-Type', 'application/json') - httpreq.responseType = 'json' - httpreq.send(JSON.stringify({ i: at, noteId: id })) - $('[toot-id=' + id + ']').hide() - $('[toot-id=' + id + ']').remove() - } else { - var start = 'https://' + domain + '/api/v1/statuses/' + id - var httpreq = new XMLHttpRequest() - httpreq.open('DELETE', start, true) - httpreq.setRequestHeader('Content-Type', 'application/json') - httpreq.setRequestHeader('Authorization', 'Bearer ' + at) - httpreq.responseType = 'json' - httpreq.send() - } - httpreq.onreadystatechange = function () { - if (httpreq.readyState === 4) { - if (this.status !== 200) { - setLog(start, this.status, this.response) - } - } - } + 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/notes/delete' + var httpreq = new XMLHttpRequest() + httpreq.open('POST', start, true) + httpreq.setRequestHeader('Content-Type', 'application/json') + httpreq.responseType = 'json' + httpreq.send(JSON.stringify({ i: at, noteId: id })) + $('[toot-id=' + id + ']').hide() + $('[toot-id=' + id + ']').remove() + } else { + var start = 'https://' + domain + '/api/v1/statuses/' + id + var httpreq = new XMLHttpRequest() + httpreq.open('DELETE', start, true) + httpreq.setRequestHeader('Content-Type', 'application/json') + httpreq.setRequestHeader('Authorization', 'Bearer ' + at) + httpreq.responseType = 'json' + httpreq.send() + } + httpreq.onreadystatechange = function() { + if (httpreq.readyState === 4) { + if (this.status !== 200) { + setLog(start, this.status, this.response) + } + } + } } //redraft function redraft(id, acct_id) { - Swal.fire({ - title: lang.lang_status_redraftTitle, - text: lang.lang_status_redraft, - type: 'warning', - showCancelButton: true, - confirmButtonText: lang.lang_yesno, - cancelButtonText: lang.lang_no - }).then(result => { - if (result.value) { - show() - 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/notes/delete' - var httpreq = new XMLHttpRequest() - httpreq.open('POST', start, true) - httpreq.setRequestHeader('Content-Type', 'application/json') - httpreq.responseType = 'json' - httpreq.send(JSON.stringify({ i: at, noteId: id })) - $('[toot-id=' + id + ']').hide() - $('[toot-id=' + id + ']').remove() - } else { - var start = 'https://' + domain + '/api/v1/statuses/' + id - var httpreq = new XMLHttpRequest() - httpreq.open('DELETE', start, true) - httpreq.setRequestHeader('Content-Type', 'application/json') - httpreq.setRequestHeader('Authorization', 'Bearer ' + at) - httpreq.responseType = 'json' - httpreq.send() - } - httpreq.onreadystatechange = function () { - if (httpreq.readyState === 4) { - if (this.status !== 200) { - setLog(start, this.status, this.response) - } - var json = httpreq.response - draftToPost(json, acct_id, id) - } - } - } - }) + Swal.fire({ + title: lang.lang_status_redraftTitle, + text: lang.lang_status_redraft, + type: 'warning', + showCancelButton: true, + confirmButtonText: lang.lang_yesno, + cancelButtonText: lang.lang_no, + }).then((result) => { + if (result.value) { + show() + 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/notes/delete' + var httpreq = new XMLHttpRequest() + httpreq.open('POST', start, true) + httpreq.setRequestHeader('Content-Type', 'application/json') + httpreq.responseType = 'json' + httpreq.send(JSON.stringify({ i: at, noteId: id })) + $('[toot-id=' + id + ']').hide() + $('[toot-id=' + id + ']').remove() + } else { + var start = 'https://' + domain + '/api/v1/statuses/' + id + var httpreq = new XMLHttpRequest() + httpreq.open('DELETE', start, true) + httpreq.setRequestHeader('Content-Type', 'application/json') + httpreq.setRequestHeader('Authorization', 'Bearer ' + at) + httpreq.responseType = 'json' + httpreq.send() + } + httpreq.onreadystatechange = function() { + if (httpreq.readyState === 4) { + if (this.status !== 200) { + setLog(start, this.status, this.response) + } + var json = httpreq.response + draftToPost(json, acct_id, id) + } + } + } + }) } + function draftToPost(json, acct_id, id) { - $('#post-acct-sel').prop('disabled', true) - $('#post-acct-sel').val(acct_id) - $('select').formSelect() - mdCheck() - mediack = null - if(json.media_attachments) mediack = json.media_attachments[0] - //メディアがあれば - var media_ids = [] - if (mediack) { - for (var i = 0; i <= 4; i++) { - if (json.media_attachments[i]) { - media_ids.push(json.media_attachments[i].id) - $('#preview').append( - '' - ) - } else { - break - } - } - } - var vismode = json.visibility - vis(vismode) - var medias = media_ids.join(',') - $('#media').val(medias) - localStorage.setItem('nohide', true) - show() - if (json.text) { - var html = json.text - } else { - var html = json.status - html = html.replace(/^

(.+)<\/p>$/, '$1') - html = html.replace(//, '\n') - html = html.replace(/

/, '\n') - html = html.replace(/<\/p>/, '\n') - html = html.replace(//g, '$1') - html = $.strip_tags(html) - } - $('#textarea').val(html) - if (json.spoiler_text) { - cw(true) - $('#cw-text').val(json.spoiler_text) - } - if (json.sensitive) { - $('#nsfw').addClass('yellow-text') - $('#nsfw').html('visibility') - $('#nsfw').addClass('nsfw-avail') - } - if (json.in_reply_to_id) { - $('#reply').val(json.in_reply_to_id) - } + $('#post-acct-sel').prop('disabled', true) + $('#post-acct-sel').val(acct_id) + $('select').formSelect() + mdCheck() + mediack = null + if (json.media_attachments) mediack = json.media_attachments[0] + //メディアがあれば + var media_ids = [] + if (mediack) { + for (var i = 0; i <= 4; i++) { + if (json.media_attachments[i]) { + media_ids.push(json.media_attachments[i].id) + $('#preview').append('') + } else { + break + } + } + } + var vismode = json.visibility + vis(vismode) + var medias = media_ids.join(',') + $('#media').val(medias) + localStorage.setItem('nohide', true) + show() + if (json.text) { + var html = json.text + } else { + var html = json.status + html = html.replace(/^

(.+)<\/p>$/, '$1') + html = html.replace(//, '\n') + html = html.replace(/

/, '\n') + html = html.replace(/<\/p>/, '\n') + html = html.replace(//g, '$1') + html = $.strip_tags(html) + } + $('#textarea').val(html) + if (json.spoiler_text) { + cw(true) + $('#cw-text').val(json.spoiler_text) + } + if (json.sensitive) { + $('#nsfw').addClass('yellow-text') + $('#nsfw').html('visibility') + $('#nsfw').addClass('nsfw-avail') + } + if (json.in_reply_to_id) { + $('#reply').val(json.in_reply_to_id) + } } //ピン留め function pin(id, acct_id) { - if ($(`.cvo[unique-id=${id}]`).hasClass('pined')) { - var flag = 'unpin' - } else { - var flag = 'pin' - } - var domain = localStorage.getItem('domain_' + acct_id) - var at = localStorage.getItem('acct_' + acct_id + '_at') - var start = 'https://' + domain + '/api/v1/statuses/' + id + '/' + flag - 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() - httpreq.onreadystatechange = function () { - if (httpreq.readyState === 4) { - var json = httpreq.response - if (this.status !== 200) { - setLog(start, this.status, this.response) - } - console.log(['Success: pinned', json]) - if (flag == 'unpin') { - $('[toot-id=' + id + ']').removeClass('pined') - $('.pin_' + id).removeClass('blue-text') - $('.pinStr_' + id).text(lang.lang_parse_pin) - } else { - $('[toot-id=' + id + ']').addClass('pined') - $('.pin_' + id).addClass('blue-text') - $('.pinStr_' + id).text(lang.lang_parse_unpin) - } - } - } + if ($(`.cvo[unique-id=${id}]`).hasClass('pined')) { + var flag = 'unpin' + } else { + var flag = 'pin' + } + var domain = localStorage.getItem('domain_' + acct_id) + var at = localStorage.getItem('acct_' + acct_id + '_at') + var start = 'https://' + domain + '/api/v1/statuses/' + id + '/' + flag + 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() + httpreq.onreadystatechange = function() { + if (httpreq.readyState === 4) { + var json = httpreq.response + if (this.status !== 200) { + setLog(start, this.status, this.response) + } + console.log(['Success: pinned', json]) + if (flag == 'unpin') { + $('[toot-id=' + id + ']').removeClass('pined') + $('.pin_' + id).removeClass('blue-text') + $('.pinStr_' + id).text(lang.lang_parse_pin) + } else { + $('[toot-id=' + id + ']').addClass('pined') + $('.pin_' + id).addClass('blue-text') + $('.pinStr_' + id).text(lang.lang_parse_unpin) + } + } + } } //フォロリク function request(id, flag, acct_id) { - var domain = localStorage.getItem('domain_' + acct_id) - var at = localStorage.getItem('acct_' + acct_id + '_at') - var start = 'https://' + domain + '/api/v1/follow_requests/' + id + '/' + flag - 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() - httpreq.onreadystatechange = function () { - if (httpreq.readyState === 4) { - var json = httpreq.response - if (this.status !== 200) { - setLog(start, this.status, this.response) - } - console.log(['Success: request', 'type:' + flag, json]) - showReq() - } - } + var domain = localStorage.getItem('domain_' + acct_id) + var at = localStorage.getItem('acct_' + acct_id + '_at') + var start = 'https://' + domain + '/api/v1/follow_requests/' + id + '/' + flag + 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() + httpreq.onreadystatechange = function() { + if (httpreq.readyState === 4) { + var json = httpreq.response + if (this.status !== 200) { + setLog(start, this.status, this.response) + } + console.log(['Success: request', 'type:' + flag, json]) + showReq() + } + } } //ドメインブロック(未実装) function domainblock(add, flag, acct_id) { - if (!acct_id) { - var acct_id = $('#his-data').attr('use-acct') - } - var domain = localStorage.getItem('domain_' + acct_id) - var at = localStorage.getItem('acct_' + acct_id + '_at') - var start = 'https://' + domain + '/api/v1/domain_blocks' - 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() - httpreq.onreadystatechange = function () { - if (httpreq.readyState === 4) { - var json = httpreq.response - if (this.status !== 200) { - setLog(start, this.status, this.response) - } - console.log(['Success: domain block', json]) - showDom() - } - } + if (!acct_id) { + var acct_id = $('#his-data').attr('use-acct') + } + var domain = localStorage.getItem('domain_' + acct_id) + var at = localStorage.getItem('acct_' + acct_id + '_at') + var start = 'https://' + domain + '/api/v1/domain_blocks' + 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() + httpreq.onreadystatechange = function() { + if (httpreq.readyState === 4) { + var json = httpreq.response + if (this.status !== 200) { + setLog(start, this.status, this.response) + } + console.log(['Success: domain block', json]) + showDom() + } + } } function addDomainblock() { - var domain = $('#domainblock').val() - domainblock(domain, 'POST') + var domain = $('#domainblock').val() + domainblock(domain, 'POST') } //ユーザー強調 function empUser() { - var usr = localStorage.getItem('user_emp') - var obj = JSON.parse(usr) - var id = $('#his-acct').attr('fullname') - if (!obj) { - var obj = [] - obj.push(id) - M.toast({ html: id + lang.lang_status_emphas, displayLength: 4000 }) - } else { - var can - Object.keys(obj).forEach(function (key) { - var usT = obj[key] - if (usT != id && !can) { - can = false - } else { - can = true - obj.splice(key, 1) - M.toast({ html: id + lang.lang_status_unemphas, displayLength: 4000 }) - } - }) - } - var json = JSON.stringify(obj) - localStorage.setItem('user_emp', json) + var usr = localStorage.getItem('user_emp') + var obj = JSON.parse(usr) + var id = $('#his-acct').attr('fullname') + if (!obj) { + var obj = [] + obj.push(id) + M.toast({ html: id + lang.lang_status_emphas, displayLength: 4000 }) + } else { + var can + Object.keys(obj).forEach(function(key) { + var usT = obj[key] + if (usT != id && !can) { + can = false + } else { + can = true + obj.splice(key, 1) + M.toast({ html: id + lang.lang_status_unemphas, displayLength: 4000 }) + } + }) + } + var json = JSON.stringify(obj) + localStorage.setItem('user_emp', json) } //Endorse function pinUser() { - var id = $('#his-data').attr('user-id') - var acct_id = $('#his-data').attr('use-acct') - if ($('#his-end-btn').hasClass('endorsed')) { - var flag = 'unpin' - } else { - var flag = 'pin' - } - var domain = localStorage.getItem('domain_' + acct_id) - var at = localStorage.getItem('acct_' + acct_id + '_at') - var start = 'https://' + domain + '/api/v1/accounts/' + id + '/' + flag - 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() - httpreq.onreadystatechange = function () { - if (httpreq.readyState === 4) { - var json = httpreq.response - if (this.status !== 200) { - setLog(start, this.status, this.response) - } - if ($('#his-end-btn').hasClass('endorsed')) { - $('#his-end-btn').removeClass('endorsed') - $('#his-end-btn').text(lang.lang_status_endorse) - } else { - $('#his-end-btn').addClass('endorsed') - $('#his-end-btn').text(lang.lang_status_unendorse) - } - } - } + var id = $('#his-data').attr('user-id') + var acct_id = $('#his-data').attr('use-acct') + if ($('#his-end-btn').hasClass('endorsed')) { + var flag = 'unpin' + } else { + var flag = 'pin' + } + var domain = localStorage.getItem('domain_' + acct_id) + var at = localStorage.getItem('acct_' + acct_id + '_at') + var start = 'https://' + domain + '/api/v1/accounts/' + id + '/' + flag + 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() + httpreq.onreadystatechange = function() { + if (httpreq.readyState === 4) { + var json = httpreq.response + if (this.status !== 200) { + setLog(start, this.status, this.response) + } + if ($('#his-end-btn').hasClass('endorsed')) { + $('#his-end-btn').removeClass('endorsed') + $('#his-end-btn').text(lang.lang_status_endorse) + } else { + $('#his-end-btn').addClass('endorsed') + $('#his-end-btn').text(lang.lang_status_unendorse) + } + } + } } //URLコピー function tootUriCopy(url) { - execCopy(url) - M.toast({ html: lang.lang_details_url, displayLength: 1500 }) + execCopy(url) + M.toast({ html: lang.lang_details_url, displayLength: 1500 }) } //他のアカウントで… function staEx(mode) { - var url = $('#tootmodal').attr('data-url') - var acct_id = $('#status-acct-sel').val() - var domain = localStorage.getItem('domain_' + acct_id) - var at = localStorage.getItem('acct_' + acct_id + '_at') - var start = 'https://' + domain + '/api/v2/search?resolve=true&q=' + url - 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 (json) { - if (json.statuses) { - if (json.statuses[0]) { - var id = json.statuses[0].id - if (mode == 'rt') { - rt(id, acct_id, 'remote') - } else if (mode == 'fav') { - fav(id, acct_id, 'remote') - } else if (mode == 'reply') { - reEx(id) - } - } - } - }) - return + var url = $('#tootmodal').attr('data-url') + var acct_id = $('#status-acct-sel').val() + var domain = localStorage.getItem('domain_' + acct_id) + var at = localStorage.getItem('acct_' + acct_id + '_at') + var start = 'https://' + domain + '/api/v2/search?resolve=true&q=' + url + 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(json) { + if (json.statuses) { + if (json.statuses[0]) { + var id = json.statuses[0].id + if (mode == 'rt') { + rt(id, acct_id, 'remote') + } else if (mode == 'fav') { + fav(id, acct_id, 'remote') + } else if (mode == 'reply') { + reEx(id) + } + } + } + }) + return } + function toggleAction(elm) { - console.log(elm) - const instance = M.Dropdown.init(elm) - console.log(instance.isOpen) - instance.open() -} + console.log(elm) + const instance = M.Dropdown.init(elm) + console.log(instance.isOpen) + instance.open() +} \ No newline at end of file diff --git a/app/js/tl/filter.js b/app/js/tl/filter.js index f5fcf386..b0a04a96 100644 --- a/app/js/tl/filter.js +++ b/app/js/tl/filter.js @@ -1,487 +1,500 @@ /*メディアフィルター機能*/ //各TL上方のMedia[On/Off] function mediaToggle(tlid) { - var media = localStorage.getItem('media_' + tlid) - if (media) { - localStorage.removeItem('media_' + tlid) - $('#sta-media-' + tlid).text('Off') - $('#sta-media-' + tlid).css('color', 'red') - $('#timeline_' + tlid).removeClass('media-filter') - } else { - localStorage.setItem('media_' + tlid, 'true') - $('#sta-media-' + tlid).text('On') - $('#sta-media-' + tlid).css('color', '#009688') - $('#timeline_' + tlid).addClass('media-filter') - } + var media = localStorage.getItem('media_' + tlid) + if (media) { + localStorage.removeItem('media_' + tlid) + $('#sta-media-' + tlid).text('Off') + $('#sta-media-' + tlid).css('color', 'red') + $('#timeline_' + tlid).removeClass('media-filter') + } else { + localStorage.setItem('media_' + tlid, 'true') + $('#sta-media-' + tlid).text('On') + $('#sta-media-' + tlid).css('color', '#009688') + $('#timeline_' + tlid).addClass('media-filter') + } } /* Remote only */ function remoteOnly(tlid, type) { - var multi = localStorage.getItem('column') - var obj = JSON.parse(multi) - if (obj[tlid].data) { - if (obj[tlid].data.remote) { - obj[tlid].data.remote = false - var json = JSON.stringify(obj) - localStorage.setItem('column', json) - $('#sta-remote-' + tlid).text('Off') - $('#sta-remote-' + tlid).css('color', '#009688') - } else { - obj[tlid].data.remote = true - var json = JSON.stringify(obj) - localStorage.setItem('column', json) - $('#sta-remote-' + tlid).text('On') - $('#sta-remote-' + tlid).css('color', 'red') - } - } else { - obj[tlid].data = {} - obj[tlid].data.remote = true - var json = JSON.stringify(obj) - localStorage.setItem('column', json) - $('#sta-remote-' + tlid).text('On') - $('#sta-remote-' + tlid).css('color', 'red') - } - columnReload(tlid, type) + var multi = localStorage.getItem('column') + var obj = JSON.parse(multi) + if (obj[tlid].data) { + if (obj[tlid].data.remote) { + obj[tlid].data.remote = false + var json = JSON.stringify(obj) + localStorage.setItem('column', json) + $('#sta-remote-' + tlid).text('Off') + $('#sta-remote-' + tlid).css('color', '#009688') + } else { + obj[tlid].data.remote = true + var json = JSON.stringify(obj) + localStorage.setItem('column', json) + $('#sta-remote-' + tlid).text('On') + $('#sta-remote-' + tlid).css('color', 'red') + } + } else { + obj[tlid].data = {} + obj[tlid].data.remote = true + var json = JSON.stringify(obj) + localStorage.setItem('column', json) + $('#sta-remote-' + tlid).text('On') + $('#sta-remote-' + tlid).css('color', 'red') + } + columnReload(tlid, type) } + function remoteOnlyCk(tlid) { - var multi = localStorage.getItem('column') - var obj = JSON.parse(multi) - if (obj[tlid].data) { - if (obj[tlid].data.remote) { - $('#sta-remote-' + tlid).text('On') - $('#sta-remote-' + tlid).css('color', 'red') - return true - } - } - return false + var multi = localStorage.getItem('column') + var obj = JSON.parse(multi) + if (obj[tlid].data) { + if (obj[tlid].data.remote) { + $('#sta-remote-' + tlid).text('On') + $('#sta-remote-' + tlid).css('color', 'red') + return true + } + } + return false } //各TL上方のBT[BTOnly/BTExc/Off] function ebtToggle(tlid) { - var ebt = localStorage.getItem('ebt_' + tlid) - if (ebt == 'true') { - localStorage.setItem('ebt_' + tlid, 'but') - $('#sta-bt-' + tlid).text('BT Only') - $('#sta-bt-' + tlid).css('color', '#ff9800') - $('#timeline_' + tlid).addClass('except-bt-filter') - $('#timeline_' + tlid).removeClass('bt-filter') - } else if (ebt == 'but') { - localStorage.removeItem('ebt_' + tlid) - $('#sta-bt-' + tlid).text('Off') - $('#sta-bt-' + tlid).css('color', 'red') - $('#timeline_' + tlid).removeClass('bt-filter') - $('#timeline_' + tlid).removeClass('except-bt-filter') - } else { - localStorage.setItem('ebt_' + tlid, 'true') - $('#sta-bt-' + tlid).text('BT Ex') - $('#sta-bt-' + tlid).css('color', '#009688') - $('#timeline_' + tlid).addClass('bt-filter') - $('#timeline_' + tlid).removeClass('except-bt-filter') - } + var ebt = localStorage.getItem('ebt_' + tlid) + if (ebt == 'true') { + localStorage.setItem('ebt_' + tlid, 'but') + $('#sta-bt-' + tlid).text('BT Only') + $('#sta-bt-' + tlid).css('color', '#ff9800') + $('#timeline_' + tlid).addClass('except-bt-filter') + $('#timeline_' + tlid).removeClass('bt-filter') + } else if (ebt == 'but') { + localStorage.removeItem('ebt_' + tlid) + $('#sta-bt-' + tlid).text('Off') + $('#sta-bt-' + tlid).css('color', 'red') + $('#timeline_' + tlid).removeClass('bt-filter') + $('#timeline_' + tlid).removeClass('except-bt-filter') + } else { + localStorage.setItem('ebt_' + tlid, 'true') + $('#sta-bt-' + tlid).text('BT Ex') + $('#sta-bt-' + tlid).css('color', '#009688') + $('#timeline_' + tlid).addClass('bt-filter') + $('#timeline_' + tlid).removeClass('except-bt-filter') + } } //各TL上方のMedia[On/Off]をチェック function mediaCheck(tlid) { - var media = localStorage.getItem('media_' + tlid) - if (media) { - $('#sta-media-' + tlid).text('On') - $('#sta-media-' + tlid).css('color', '#009688') - $('#timeline_' + tlid).addClass('media-filter') - } else { - $('#sta-media-' + tlid).text('Off') - $('#sta-media-' + tlid).css('color', 'red') - $('#timeline_' + tlid).removeClass('media-filter') - } + var media = localStorage.getItem('media_' + tlid) + if (media) { + $('#sta-media-' + tlid).text('On') + $('#sta-media-' + tlid).css('color', '#009688') + $('#timeline_' + tlid).addClass('media-filter') + } else { + $('#sta-media-' + tlid).text('Off') + $('#sta-media-' + tlid).css('color', 'red') + $('#timeline_' + tlid).removeClass('media-filter') + } } //各TL上方のBT[On/Off]をチェック function ebtCheck(tlid) { - var ebt = localStorage.getItem('ebt_' + tlid) - if (ebt == 'true') { - $('#sta-bt-' + tlid).text('BT Ex') - $('#sta-bt-' + tlid).css('color', '#009688') - $('#timeline_' + tlid).addClass('bt-filter') - $('#timeline_' + tlid).removeClass('except-bt-filter') - } else if (ebt == 'but') { - $('#sta-bt-' + tlid).text('BT Only') - $('#sta-bt-' + tlid).css('color', '#ff9800') - $('#timeline_' + tlid).addClass('except-bt-filter') - $('#timeline_' + tlid).removeClass('bt-filter') - } else { - $('#sta-bt-' + tlid).text('Off') - $('#sta-bt-' + tlid).css('color', 'red') - $('#timeline_' + tlid).removeClass('bt-filter') - $('#timeline_' + tlid).removeClass('except-bt-filter') - } + var ebt = localStorage.getItem('ebt_' + tlid) + if (ebt == 'true') { + $('#sta-bt-' + tlid).text('BT Ex') + $('#sta-bt-' + tlid).css('color', '#009688') + $('#timeline_' + tlid).addClass('bt-filter') + $('#timeline_' + tlid).removeClass('except-bt-filter') + } else if (ebt == 'but') { + $('#sta-bt-' + tlid).text('BT Only') + $('#sta-bt-' + tlid).css('color', '#ff9800') + $('#timeline_' + tlid).addClass('except-bt-filter') + $('#timeline_' + tlid).removeClass('bt-filter') + } else { + $('#sta-bt-' + tlid).text('Off') + $('#sta-bt-' + tlid).css('color', 'red') + $('#timeline_' + tlid).removeClass('bt-filter') + $('#timeline_' + tlid).removeClass('except-bt-filter') + } } /* 削除追跡*/ function catchToggle(tlid) { - var catchck = localStorage.getItem('catch_' + tlid) - if (catchck) { - localStorage.removeItem('catch_' + tlid) - $('#sta-del-' + tlid).text('Off') - $('#sta-del-' + tlid).css('color', 'red') - parseColumn(tlid) - } else { - localStorage.setItem('catch_' + tlid, 'true') - $('#sta-del-' + tlid).text('On') - $('#sta-del-' + tlid).css('color', '#009688') - parseColumn(tlid) - } + var catchck = localStorage.getItem('catch_' + tlid) + if (catchck) { + localStorage.removeItem('catch_' + tlid) + $('#sta-del-' + tlid).text('Off') + $('#sta-del-' + tlid).css('color', 'red') + parseColumn(tlid) + } else { + localStorage.setItem('catch_' + tlid, 'true') + $('#sta-del-' + tlid).text('On') + $('#sta-del-' + tlid).css('color', '#009688') + parseColumn(tlid) + } } + function catchCheck(tlid) { - var catchck = localStorage.getItem('catch_' + tlid) - if (catchck) { - $('#sta-del-' + tlid).text('On') - $('#sta-del-' + tlid).css('color', '#009688') - } else { - $('#sta-del-' + tlid).text('Off') - $('#sta-del-' + tlid).css('color', 'red') - } + var catchck = localStorage.getItem('catch_' + tlid) + if (catchck) { + $('#sta-del-' + tlid).text('On') + $('#sta-del-' + tlid).css('color', '#009688') + } else { + $('#sta-del-' + tlid).text('Off') + $('#sta-del-' + tlid).css('color', 'red') + } } + function delreset(tlid) { - $('[tlid=' + tlid + '] .by_delcatch').hide() - $('[tlid=' + tlid + '] .by_delcatch').remove() + $('[tlid=' + tlid + '] .by_delcatch').hide() + $('[tlid=' + tlid + '] .by_delcatch').remove() } /*ワードフィルター機能*/ function filterMenu() { - $('#left-menu a').removeClass('active') - $('#filterMenu').addClass('active') - $('.menu-content').addClass('hide') - $('#filter-box').removeClass('hide') + $('#left-menu a').removeClass('active') + $('#filterMenu').addClass('active') + $('.menu-content').addClass('hide') + $('#filter-box').removeClass('hide') } + function filter() { - $('#filtered-words').html('') - $('#filter-edit-id').val('') - var acct_id = $('#filter-acct-sel').val() - var domain = localStorage.getItem('domain_' + acct_id) - var at = localStorage.getItem('acct_' + acct_id + '_at') - var start = 'https://' + domain + '/api/v1/filters' - 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 (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) + - `(for ${context}): + $('#filtered-words').html('') + $('#filter-edit-id').val('') + var acct_id = $('#filter-acct-sel').val() + var domain = localStorage.getItem('domain_' + acct_id) + var at = localStorage.getItem('acct_' + acct_id + '_at') + var start = 'https://' + domain + '/api/v1/filters' + 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(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) + + `(for ${context}): ${lang.lang_edit} / ${lang.lang_del}
` - }) - if (filters == '') { - filters = lang.lang_filter_nodata + '
' - } - $('#filtered-words').html(filters) - } else { - $('#filtered-words').html(lang_filter_nodata) - } - }) + }) + if (filters == '') { + filters = lang.lang_filter_nodata + '
' + } + $('#filtered-words').html(filters) + } else { + $('#filtered-words').html(lang_filter_nodata) + } + }) } -function filterTime(day, hour, min) { - $('#days_filter').val(day) - $('#hours_filter').val(hour) - $('#mins_filter').val(min) -} -function makeNewFilter() { - var acct_id = $('#filter-acct-sel').val() - var phr = $('#filter-add-word').val() - var cont = [] - if ($('#home_filter:checked').val()) { - cont.push('home') - } - if ($('#local_filter:checked').val()) { - cont.push('public') - } - if ($('#notf_filter:checked').val()) { - cont.push('notifications') - } - if ($('#conv_filter:checked').val()) { - cont.push('thread') - } - if ($('#prof_filter:checked').val()) { - cont.push('profiles') - } - if (!cont.length) { - $('#filtered-words').html('Error:' + lang.lang_filter_errordegree) - } - var exc = $('#except_filter:checked').val() - var who = $('#wholeword_filter:checked').val() - if (!who) { - who = false - } - var time = $('#days_filter').val() * 24 * 60 * 60 + $('#hours_filter').val() * 60 * 60 + $('#mins_filter').val() * 60 - var domain = localStorage.getItem('domain_' + acct_id) - var at = localStorage.getItem('acct_' + acct_id + '_at') - if ($('#filter-edit-id').val()) { - var start = 'https://' + domain + '/api/v1/filters/' + $('#filter-edit-id').val() - var method = 'PUT' - } else { - var start = 'https://' + domain + '/api/v1/filters' - var method = 'POST' - } - var httpreq = new XMLHttpRequest() - httpreq.open(method, start, true) - httpreq.setRequestHeader('Content-Type', 'application/json') - httpreq.setRequestHeader('Authorization', 'Bearer ' + at) - httpreq.responseType = 'json' - httpreq.send( - JSON.stringify({ - phrase: phr, - context: cont, - irreversible: exc, - whole_word: who, - expires_in: time, - }) - ) - httpreq.onreadystatechange = function () { - if (httpreq.readyState === 4) { - var json = httpreq.response - if (this.status !== 200) { - setLog(start, this.status, this.response) - } - filter() - filterUpdate(acct_id) - $('#filter-add-word').val('') - $('#home_filter').prop('checked', false) - $('#local_filter').prop('checked', false) - $('#notf_filter').prop('checked', false) - $('#conv_filter').prop('checked', false) - $('#prof_filter').prop('checked', false) - $('#except_filter').prop('checked', false) - $('#wholeword_filter').prop('checked', false) - $('#days_filter').val('0') - $('#hours_filter').val('0') - $('#mins_filter').val('0') - $('#add-filter-btn').text(lang.lang_add) - $('#filter-edit-id').val('') - } - } +function filterTime(day, hour, min) { + $('#days_filter').val(day) + $('#hours_filter').val(hour) + $('#mins_filter').val(min) } + +function makeNewFilter() { + var acct_id = $('#filter-acct-sel').val() + var phr = $('#filter-add-word').val() + var cont = [] + if ($('#home_filter:checked').val()) { + cont.push('home') + } + if ($('#local_filter:checked').val()) { + cont.push('public') + } + if ($('#notf_filter:checked').val()) { + cont.push('notifications') + } + if ($('#conv_filter:checked').val()) { + cont.push('thread') + } + if ($('#prof_filter:checked').val()) { + cont.push('profiles') + } + if (!cont.length) { + $('#filtered-words').html('Error:' + lang.lang_filter_errordegree) + } + var exc = $('#except_filter:checked').val() + var who = $('#wholeword_filter:checked').val() + if (!who) { + who = false + } + var time = $('#days_filter').val() * 24 * 60 * 60 + $('#hours_filter').val() * 60 * 60 + $('#mins_filter').val() * 60 + var domain = localStorage.getItem('domain_' + acct_id) + var at = localStorage.getItem('acct_' + acct_id + '_at') + if ($('#filter-edit-id').val()) { + var start = 'https://' + domain + '/api/v1/filters/' + $('#filter-edit-id').val() + var method = 'PUT' + } else { + var start = 'https://' + domain + '/api/v1/filters' + var method = 'POST' + } + + var httpreq = new XMLHttpRequest() + httpreq.open(method, start, true) + httpreq.setRequestHeader('Content-Type', 'application/json') + httpreq.setRequestHeader('Authorization', 'Bearer ' + at) + httpreq.responseType = 'json' + httpreq.send( + JSON.stringify({ + phrase: phr, + context: cont, + irreversible: exc, + whole_word: who, + expires_in: time, + }) + ) + httpreq.onreadystatechange = function() { + if (httpreq.readyState === 4) { + var json = httpreq.response + if (this.status !== 200) { + setLog(start, this.status, this.response) + } + filter() + filterUpdate(acct_id) + $('#filter-add-word').val('') + $('#home_filter').prop('checked', false) + $('#local_filter').prop('checked', false) + $('#notf_filter').prop('checked', false) + $('#conv_filter').prop('checked', false) + $('#prof_filter').prop('checked', false) + $('#except_filter').prop('checked', false) + $('#wholeword_filter').prop('checked', false) + $('#days_filter').val('0') + $('#hours_filter').val('0') + $('#mins_filter').val('0') + $('#add-filter-btn').text(lang.lang_add) + $('#filter-edit-id').val('') + } + } +} + function filterEdit(id, acct_id) { - $('#filter-add-word').val('') - $('#home_filter').prop('checked', false) - $('#local_filter').prop('checked', false) - $('#notf_filter').prop('checked', false) - $('#conv_filter').prop('checked', false) - $('#except_filter').prop('checked', false) - $('#wholeword_filter').prop('checked', false) - $('#days_filter').val('0') - $('#hours_filter').val('0') - $('#mins_filter').val('0') - $('#add-filter-btn').text(lang.lang_edit) - $('#filter-edit-id').val(id) - var domain = localStorage.getItem('domain_' + acct_id) - var at = localStorage.getItem('acct_' + acct_id + '_at') - var start = 'https://' + domain + '/api/v1/filters/' + id - 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 (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) - } - }) + $('#filter-add-word').val('') + $('#home_filter').prop('checked', false) + $('#local_filter').prop('checked', false) + $('#notf_filter').prop('checked', false) + $('#conv_filter').prop('checked', false) + $('#except_filter').prop('checked', false) + $('#wholeword_filter').prop('checked', false) + $('#days_filter').val('0') + $('#hours_filter').val('0') + $('#mins_filter').val('0') + $('#add-filter-btn').text(lang.lang_edit) + $('#filter-edit-id').val(id) + var domain = localStorage.getItem('domain_' + acct_id) + var at = localStorage.getItem('acct_' + acct_id + '_at') + var start = 'https://' + domain + '/api/v1/filters/' + id + 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(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) + } + }) } + function filterDel(id, acct_id) { - var domain = localStorage.getItem('domain_' + acct_id) - var at = localStorage.getItem('acct_' + acct_id + '_at') - var start = 'https://' + domain + '/api/v1/filters/' + id - var httpreq = new XMLHttpRequest() - httpreq.open('DELETE', start, true) - httpreq.setRequestHeader('Content-Type', 'application/json') - httpreq.setRequestHeader('Authorization', 'Bearer ' + at) - httpreq.responseType = 'json' - httpreq.send() - httpreq.onreadystatechange = function () { - if (httpreq.readyState === 4) { - var json = httpreq.response - if (this.status !== 200) { - setLog(start, this.status, this.response) - } - filter() - filterUpdate(acct_id) - } - } + var domain = localStorage.getItem('domain_' + acct_id) + var at = localStorage.getItem('acct_' + acct_id + '_at') + var start = 'https://' + domain + '/api/v1/filters/' + id + var httpreq = new XMLHttpRequest() + httpreq.open('DELETE', start, true) + httpreq.setRequestHeader('Content-Type', 'application/json') + httpreq.setRequestHeader('Authorization', 'Bearer ' + at) + httpreq.responseType = 'json' + httpreq.send() + httpreq.onreadystatechange = function() { + if (httpreq.readyState === 4) { + var json = httpreq.response + if (this.status !== 200) { + setLog(start, this.status, this.response) + } + filter() + filterUpdate(acct_id) + } + } } + function getFilter(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/filters' - 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 (json) { - localStorage.setItem('filter_' + acct_id, JSON.stringify(json)) - }) - } else { - localStorage.setItem('filter_' + acct_id, JSON.stringify({})) - } + 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/filters' + 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(json) { + localStorage.setItem('filter_' + acct_id, JSON.stringify(json)) + }) + } else { + localStorage.setItem('filter_' + acct_id, JSON.stringify({})) + } } + function getFilterType(json, type) { - if (!json) { - return [] - } - if (type == 'local') { - type = 'public' - } else if (type == 'list') { - type = 'home' - } else if (type == 'notf') { - type = 'notifi' - } - var mutedfilters = [] - Object.keys(json).forEach(function (key) { - var filterword = json[key] - var phrases = filterword.phrase - var arr = filterword.context - if (arr.join(',').indexOf(type) !== -1) { - mutedfilters.push(phrases) - } else if (type == 'mix') { - if (arr.indexOf('home') !== -1 || arr.indexOf('public') !== -1) { - mutedfilters.push(phrases) - } - } - }) - return mutedfilters + if (!json) { + return [] + } + if (type == 'local') { + type = 'public' + } else if (type == 'list') { + type = 'home' + } else if (type == 'notf') { + type = 'notifi' + } + var mutedfilters = [] + Object.keys(json).forEach(function(key) { + var filterword = json[key] + var phrases = filterword.phrase + var arr = filterword.context + if (arr.join(',').indexOf(type) !== -1) { + mutedfilters.push(phrases) + } else if (type == 'mix') { + if (arr.indexOf('home') !== -1 || arr.indexOf('public') !== -1) { + mutedfilters.push(phrases) + } + } + }) + return mutedfilters } + function getFilterTypeByAcct(acct_id, type) { - if (localStorage.getItem('filter_' + acct_id) != 'undefined') { - var mute = getFilterType(JSON.parse(localStorage.getItem('filter_' + acct_id)), type) - } else { - var mute = [] - } - return mute + if (localStorage.getItem('filter_' + acct_id) != 'undefined') { + var mute = getFilterType(JSON.parse(localStorage.getItem('filter_' + acct_id)), type) + } else { + var mute = [] + } + return mute } + function filterUpdate(acct_id) { - var domain = localStorage.getItem('domain_' + acct_id) - var at = localStorage.getItem('acct_' + acct_id + '_at') - var start = 'https://' + domain + '/api/v1/filters' - 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 (json) { - localStorage.setItem('filter_' + acct_id, JSON.stringify(json)) - filterUpdateInternal(json, 'home') - filterUpdateInternal(json, 'local') - filterUpdateInternal(json, 'notf') - filterUpdateInternal(json, 'pub') - }) + var domain = localStorage.getItem('domain_' + acct_id) + var at = localStorage.getItem('acct_' + acct_id + '_at') + var start = 'https://' + domain + '/api/v1/filters' + 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(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) { - var home = getFilterType(json, type) - var wordmute = localStorage.getItem('word_mute') - if (wordmute) { - var wordmute = JSON.parse(wordmute) - home = home.concat(wordmute) - } - if (home) { - $('[data-acct=' + acct_id + '] [data-type=' + type + '] .cvo').each(function (i, elem) { - var id = $(elem).attr('toot-id') - $('[toot-id=' + id + ']').removeClass('hide') - var text = $(elem).find('.toot').html() - Object.keys(home).forEach(function (key8) { - var word = home[key8] - var regExp = new RegExp(word.replace(/[.*+?^=!:${}()|[\]\/\\]/g, '\\$&'), 'g') - if ($.strip_tags(text).match(regExp)) { - $('[toot-id=' + id + ']').addClass('hide') - } - }) - }) - } + var home = getFilterType(json, type) + var wordmute = localStorage.getItem('word_mute') + if (wordmute) { + var wordmute = JSON.parse(wordmute) + home = home.concat(wordmute) + } + if (home) { + $('[data-acct=' + acct_id + '] [data-type=' + type + '] .cvo').each(function(i, elem) { + var id = $(elem).attr('toot-id') + $('[toot-id=' + id + ']').removeClass('hide') + var text = $(elem).find('.toot').html() + Object.keys(home).forEach(function(key8) { + var word = home[key8] + var regExp = new RegExp(word.replace(/[.*+?^=!:${}()|[\]\/\\]/g, '\\$&'), 'g') + if ($.strip_tags(text).match(regExp)) { + $('[toot-id=' + id + ']').addClass('hide') + } + }) + }) + } } /* ' - $('#timeline_' + tlid).html(templete) - // $('#landing_' + tlid).hide() - jQuery('time.timeago').timeago() - } - $('#notf-box').addClass('fetched') - todc() - //Markers - var markers = localStorage.getItem('markers') - if (markers == 'yes') { - markers = true - } else { - markers = false - } - if (markers) { - getMarker(tlid, 'notf', acct_id) - } - } - } - if (!misskey) { - if (localStorage.getItem('streaming_' + acct_id)) { - var wss = localStorage.getItem('streaming_' + acct_id) - } else { - var wss = 'wss://' + domain - } - var start = wss + '/api/v1/streaming/?stream=user&access_token=' + at - } else { - var start = 'wss://' + domain + '/?i=' + at - } + httpreq.responseType = 'json' + httpreq.send(body) + httpreq.onreadystatechange = function() { + if (httpreq.readyState === 4) { + var json = httpreq.response + if (this.status !== 200) { + $('#landing_' + tlid).append(`

${this.status}
${escapeHTML(this.response)}`) + setLog(start, this.status, this.response) + } + var max_id = httpreq.getResponseHeader('link') + if (max_id) { + max_id = max_id.match(/[?&]{1}max_id=([0-9]+)/)[1] + } + if (json[0]) { + var templete = '' + var lastnotf = localStorage.getItem('lastnotf_' + acct_id) + localStorage.setItem('lastnotf_' + acct_id, json[0].id) + Object.keys(json).forEach(function(key) { + 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 mute = getFilterTypeByAcct(acct_id, 'notif') + //Pleromaにはmoveというtypeがあるらしい。何が互換APIじゃ + if (obj.type != 'follow' && obj.type != 'move' && obj.type != 'follow_request') { + if (misskey) { + templete = templete + misskeyParse([obj], 'notf', acct_id, tlid, -1, mute) + } else { + templete = templete + parse([obj], 'notf', acct_id, tlid, -1, mute) + } + } else if (obj.type == 'follow_request') { + templete = templete + userparse([obj.account], 'request', acct_id, tlid, -1) + } else { + if (misskey) { + templete = templete + misskeyUserparse([obj], 'notf', acct_id, tlid, -1, mute) + } else { + templete = templete + userparse([obj.account], obj.type, acct_id, tlid, -1) + } + } + }) + templete = templete + '
' + $('#timeline_' + tlid).html(templete) + // $('#landing_' + tlid).hide() + jQuery('time.timeago').timeago() + } + $('#notf-box').addClass('fetched') + todc() + //Markers + var markers = localStorage.getItem('markers') + if (markers == 'yes') { + markers = true + } else { + markers = false + } + if (markers) { + getMarker(tlid, 'notf', acct_id) + } + } + } + if (!misskey) { + if (localStorage.getItem('streaming_' + acct_id)) { + var wss = localStorage.getItem('streaming_' + acct_id) + } else { + var wss = 'wss://' + domain + } + var start = wss + '/api/v1/streaming/?stream=user&access_token=' + at + } else { + var start = 'wss://' + domain + '/?i=' + at + } } + function notfCommon(acct_id, tlid, sys, stream) { - todo('Notifications Loading...') - var native = localStorage.getItem('nativenotf') - var at = localStorage.getItem('acct_' + acct_id + '_at') - if (!native) { - native = 'yes' - } - var domain = localStorage.getItem('domain_' + acct_id) - if (localStorage.getItem('mode_' + domain) == 'misskey') { - var misskey = true - var start = 'https://' + domain + '/api/i/notifications' - var i = { - method: 'POST', - headers: { - 'content-type': 'application/json' - }, - body: JSON.stringify({ - i: at - }) - } - } else { - var misskey = false - var start = 'https://' + domain + '/api/v1/notifications' - var i = { - method: 'GET', - headers: { - 'content-type': 'application/json', - Authorization: 'Bearer ' + at - } - } - } - if(stream == 'only') { - notfWS(misskey, acct_id, tlid, domain, at) - return false - } - fetch(start, i) - .then(function(response) { - console.log('header to get param:' + response.headers.get('link')) - if (!response.ok) { - response.text().then(function(text) { - console.log('notf error', 'div[data-notf=' + acct_id + '] .landing') - $('div[data-notf=' + acct_id + '] .landing').append(`
${response.status}
${escapeHTML(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[0]) { - var templete = '' - var lastnotf = localStorage.getItem('lastnotf_' + acct_id) - localStorage.setItem('lastnotf_' + acct_id, json[0].id) - Object.keys(json).forEach(function(key) { - 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 mute = getFilterTypeByAcct(acct_id, 'notif') - //Pleromaにはmoveというtypeがあるらしい。何が互換APIじゃ - if (obj.type != 'follow' && obj.type != 'move') { - if (misskey) { - templete = templete + misskeyParse([obj], 'notf', acct_id, 'notf', -1, mute) - } else { - templete = templete + parse([obj], 'notf', acct_id, 'notf', -1, mute) - } - } else { - if (misskey) { - templete = templete + misskeyUserparse([obj], 'notf', acct_id, 'notf', -1, mute) - } else { - templete = templete + userparse([obj.account], obj.type, acct_id, 'notf', -1) - } - } - }) - $('div[data-notf=' + acct_id + ']').html(templete) - // $('#landing_' + tlid).hide() - jQuery('time.timeago').timeago() - } - $('#notf-box').addClass('fetched') - todc() - if(stream != 'no') notfWS(misskey, acct_id, tlid, domain, at) - }) + todo('Notifications Loading...') + var native = localStorage.getItem('nativenotf') + var at = localStorage.getItem('acct_' + acct_id + '_at') + if (!native) { + native = 'yes' + } + var domain = localStorage.getItem('domain_' + acct_id) + if (localStorage.getItem('mode_' + domain) == 'misskey') { + var misskey = true + var start = 'https://' + domain + '/api/i/notifications' + var i = { + method: 'POST', + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({ + i: at, + }), + } + } else { + var misskey = false + var start = 'https://' + domain + '/api/v1/notifications' + var i = { + method: 'GET', + headers: { + 'content-type': 'application/json', + Authorization: 'Bearer ' + at, + }, + } + } + if (stream == 'only') { + notfWS(misskey, acct_id, tlid, domain, at) + return false + } + fetch(start, i) + .then(function(response) { + console.log('header to get param:' + response.headers.get('link')) + if (!response.ok) { + response.text().then(function(text) { + console.log('notf error', 'div[data-notf=' + acct_id + '] .landing') + $('div[data-notf=' + acct_id + '] .landing').append(`
${response.status}
${escapeHTML(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[0]) { + var templete = '' + var lastnotf = localStorage.getItem('lastnotf_' + acct_id) + localStorage.setItem('lastnotf_' + acct_id, json[0].id) + Object.keys(json).forEach(function(key) { + 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 mute = getFilterTypeByAcct(acct_id, 'notif') + //Pleromaにはmoveというtypeがあるらしい。何が互換APIじゃ + if (obj.type != 'follow' && obj.type != 'move') { + if (misskey) { + templete = templete + misskeyParse([obj], 'notf', acct_id, 'notf', -1, mute) + } else { + templete = templete + parse([obj], 'notf', acct_id, 'notf', -1, mute) + } + } else { + if (misskey) { + templete = templete + misskeyUserparse([obj], 'notf', acct_id, 'notf', -1, mute) + } else { + templete = templete + userparse([obj.account], obj.type, acct_id, 'notf', -1) + } + } + }) + $('div[data-notf=' + acct_id + ']').html(templete) + // $('#landing_' + tlid).hide() + jQuery('time.timeago').timeago() + } + $('#notf-box').addClass('fetched') + todc() + if (stream != 'no') notfWS(misskey, acct_id, tlid, domain, at) + }) } -function notfWS(misskey, acct_id, tlid, domain, at) { - if(mastodonBaseWsStatus[domain] == 'available') return false - if (!misskey) { - if (localStorage.getItem('streaming_' + acct_id)) { - var wss = localStorage.getItem('streaming_' + acct_id) - } else { - var wss = 'wss://' + domain - } - var start = wss + '/api/v1/streaming/?stream=user&access_token=' + at - var wsid = websocketNotf.length - websocketNotf[acct_id] = new WebSocket(start) - websocketNotf[acct_id].onopen = function(mess) { - console.table({ - acct_id: acct_id, - type: 'Connect Streaming API(Notf)', - domain: domain, - message: [mess] - }) - $('i[data-notf=' + acct_id + ']').removeClass('red-text') - } - websocketNotf[acct_id].onmessage = function(mess) { - $('#landing_' + tlid).hide() - //console.log(["Receive Streaming API(Notf):" + acct_id + "(" + domain + ")", JSON.parse(JSON.parse(mess.data).payload)]); - var popup = localStorage.getItem('popup') - if (!popup) { - popup = 0 - } - var obj = JSON.parse(JSON.parse(mess.data).payload) - var type = JSON.parse(mess.data).event - if (type == 'notification') { - var templete = '' - localStorage.setItem('lastnotf_' + acct_id, obj.id) - if (!$('#unread_' + tlid + ' .material-icons').hasClass('teal-text')) { - //markers show中はダメ - if (obj.type != 'follow' && obj.type != 'follow_request') { - templete = parse([obj], 'notf', acct_id, 'notf', popup) - } else if (obj.type == 'follow_request') { - templete = userparse([obj.account], 'request', acct_id, 'notf', -1) - } else { - templete = userparse([obj], obj.type, acct_id, 'notf', popup) - } - if (!$('div[data-notfIndv=' + acct_id + '_' + obj.id + ']').length) { - $('div[data-notf=' + acct_id + ']').prepend(templete) - $('div[data-const=notf_' + acct_id + ']').prepend(templete) - } - jQuery('time.timeago').timeago() - } - } else if (type == 'delete') { - $('[toot-id=' + obj + ']').hide() - $('[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) { - console.error('WebSocket Close ', error) - errorct++ - console.log(errorct) - if (errorct < 3) { - notfWS(misskey, acct_id, tlid, domain, at) - } - } - } +function notfWS(misskey, acct_id, tlid, domain, at) { + if (mastodonBaseWsStatus[domain] == 'available') return false + if (!misskey) { + if (localStorage.getItem('streaming_' + acct_id)) { + var wss = localStorage.getItem('streaming_' + acct_id) + } else { + var wss = 'wss://' + domain + } + var start = wss + '/api/v1/streaming/?stream=user&access_token=' + at + + var wsid = websocketNotf.length + websocketNotf[acct_id] = new WebSocket(start) + websocketNotf[acct_id].onopen = function(mess) { + console.table({ + acct_id: acct_id, + type: 'Connect Streaming API(Notf)', + domain: domain, + message: [mess], + }) + $('i[data-notf=' + acct_id + ']').removeClass('red-text') + } + websocketNotf[acct_id].onmessage = function(mess) { + $('#landing_' + tlid).hide() + //console.log(["Receive Streaming API(Notf):" + acct_id + "(" + domain + ")", JSON.parse(JSON.parse(mess.data).payload)]); + var popup = localStorage.getItem('popup') + if (!popup) { + popup = 0 + } + var obj = JSON.parse(JSON.parse(mess.data).payload) + var type = JSON.parse(mess.data).event + if (type == 'notification') { + var templete = '' + localStorage.setItem('lastnotf_' + acct_id, obj.id) + if (!$('#unread_' + tlid + ' .material-icons').hasClass('teal-text')) { + //markers show中はダメ + if (obj.type != 'follow' && obj.type != 'follow_request') { + templete = parse([obj], 'notf', acct_id, 'notf', popup) + } else if (obj.type == 'follow_request') { + templete = userparse([obj.account], 'request', acct_id, 'notf', -1) + } else { + templete = userparse([obj], obj.type, acct_id, 'notf', popup) + } + if (!$('div[data-notfIndv=' + acct_id + '_' + obj.id + ']').length) { + $('div[data-notf=' + acct_id + ']').prepend(templete) + $('div[data-const=notf_' + acct_id + ']').prepend(templete) + } + jQuery('time.timeago').timeago() + } + } else if (type == 'delete') { + $('[toot-id=' + obj + ']').hide() + $('[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) { + console.error('WebSocket Close ', error) + errorct++ + console.log(errorct) + if (errorct < 3) { + notfWS(misskey, acct_id, tlid, domain, at) + } + } + } } //一定のスクロールで発火 function notfmore(tlid) { - console.log({ status: 'kicked', status: moreloading }) - 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 - } - var sid = $('#timeline_' + tlid + ' .notif-marker') - .last() - .attr('data-maxid') - var at = localStorage.getItem('acct_' + acct_id + '_at') - var domain = localStorage.getItem('domain_' + acct_id) - if (sid && !moreloading) { - moreloading = true - var httpreq = new XMLHttpRequest() - if (localStorage.getItem('mode_' + domain) == 'misskey') { - var misskey = true - var start = 'https://' + domain + '/api/i/notifications' - httpreq.open(POST, start, true) - httpreq.setRequestHeader('Content-Type', 'application/json') - var body = JSON.stringify({ - i: at, - untilID: sid - }) - } else { - var misskey = false - if (localStorage.getItem('exclude-' + tlid)) { - var exc = localStorage.getItem('exclude-' + tlid) + '&max_id=' + sid - } else { - var exc = '?max_id=' + sid - } - var start = 'https://' + domain + '/api/v1/notifications' + exc - httpreq.open('GET', start, true) - httpreq.setRequestHeader('Content-Type', 'application/json') - httpreq.setRequestHeader('Authorization', 'Bearer ' + at) - var body = '' - } + console.log({ status: 'kicked', status: moreloading }) + 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 + } + var sid = $('#timeline_' + tlid + ' .notif-marker') + .last() + .attr('data-maxid') + var at = localStorage.getItem('acct_' + acct_id + '_at') + var domain = localStorage.getItem('domain_' + acct_id) + if (sid && !moreloading) { + moreloading = true + var httpreq = new XMLHttpRequest() + if (localStorage.getItem('mode_' + domain) == 'misskey') { + var misskey = true + var start = 'https://' + domain + '/api/i/notifications' + httpreq.open(POST, start, true) + httpreq.setRequestHeader('Content-Type', 'application/json') + var body = JSON.stringify({ + i: at, + untilID: sid, + }) + } else { + var misskey = false + if (localStorage.getItem('exclude-' + tlid)) { + var exc = localStorage.getItem('exclude-' + tlid) + '&max_id=' + sid + } else { + var exc = '?max_id=' + sid + } + var start = 'https://' + domain + '/api/v1/notifications' + exc + httpreq.open('GET', start, true) + httpreq.setRequestHeader('Content-Type', 'application/json') + httpreq.setRequestHeader('Authorization', 'Bearer ' + at) + var body = '' + } - httpreq.responseType = 'json' - httpreq.send(body) - httpreq.onreadystatechange = function() { - if (httpreq.readyState === 4) { - var json = httpreq.response - if (this.status !== 200) { - setLog(start, this.status, this.response) - } - console.log(['More notifications on ' + tlid, json]) - var max_id = httpreq.getResponseHeader('link').match(/[?&]{1}max_id=([0-9]+)/)[1] - if (json[0]) { - var templete = '' - var lastnotf = localStorage.getItem('lastnotf_' + acct_id) - localStorage.setItem('lastnotf_' + acct_id, json[0].id) - Object.keys(json).forEach(function(key) { - var obj = json[key] - var mute = getFilterTypeByAcct(acct_id, 'notif') - if (obj.type != 'follow') { - if (misskey) { - templete = templete + misskeyParse([obj], 'notf', acct_id, 'notf', -1, mute) - } else { - templete = templete + parse([obj], 'notf', acct_id, 'notf', -1, mute) - } - } else { - if (misskey) { - templete = templete + misskeyUserparse([obj], 'notf', acct_id, 'notf', -1, mute) - } else { - templete = templete + userparse([obj.account], obj.type, acct_id, 'notf', -1) - } - } - }) - moreloading = false - templete = templete + '
' - $('#timeline_' + tlid).append(templete) - // $('#landing_' + tlid).hide() - jQuery('time.timeago').timeago() - } - $('#notf-box').addClass('fetched') - todc() - } - } - } + httpreq.responseType = 'json' + httpreq.send(body) + httpreq.onreadystatechange = function() { + if (httpreq.readyState === 4) { + var json = httpreq.response + if (this.status !== 200) { + setLog(start, this.status, this.response) + } + console.log(['More notifications on ' + tlid, json]) + var max_id = httpreq.getResponseHeader('link').match(/[?&]{1}max_id=([0-9]+)/)[1] + if (json[0]) { + var templete = '' + var lastnotf = localStorage.getItem('lastnotf_' + acct_id) + localStorage.setItem('lastnotf_' + acct_id, json[0].id) + Object.keys(json).forEach(function(key) { + var obj = json[key] + var mute = getFilterTypeByAcct(acct_id, 'notif') + if (obj.type != 'follow') { + if (misskey) { + templete = templete + misskeyParse([obj], 'notf', acct_id, 'notf', -1, mute) + } else { + templete = templete + parse([obj], 'notf', acct_id, 'notf', -1, mute) + } + } else { + if (misskey) { + templete = templete + misskeyUserparse([obj], 'notf', acct_id, 'notf', -1, mute) + } else { + templete = templete + userparse([obj.account], obj.type, acct_id, 'notf', -1) + } + } + }) + moreloading = false + templete = templete + '
' + $('#timeline_' + tlid).append(templete) + // $('#landing_' + tlid).hide() + jQuery('time.timeago').timeago() + } + $('#notf-box').addClass('fetched') + todc() + } + } + } } //通知トグルボタン function notfToggle(acct, tlid) { - if ($('#notf-box_' + tlid).hasClass('column-hide')) { - $('#notf-box_' + tlid).css('display', 'block') - $('#notf-box_' + tlid).animate( - { - height: '400px' - }, - { - duration: 300, - complete: function() { - $('#notf-box_' + tlid).css('overflow-y', 'scroll') - $('#notf-box_' + tlid).removeClass('column-hide') - } - } - ) - } else { - $('#notf-box_' + tlid).css('overflow-y', 'hidden') - $('#notf-box_' + tlid).animate( - { - height: '0' - }, - { - duration: 300, - complete: function() { - $('#notf-box_' + tlid).addClass('column-hide') - $('#notf-box_' + tlid).css('display', 'none') - } - } - ) - } - notfCanceler(acct) + if ($('#notf-box_' + tlid).hasClass('column-hide')) { + $('#notf-box_' + tlid).css('display', 'block') + $('#notf-box_' + tlid).animate({ + height: '400px', + }, { + duration: 300, + complete: function() { + $('#notf-box_' + tlid).css('overflow-y', 'scroll') + $('#notf-box_' + tlid).removeClass('column-hide') + }, + }) + } else { + $('#notf-box_' + tlid).css('overflow-y', 'hidden') + $('#notf-box_' + tlid).animate({ + height: '0', + }, { + duration: 300, + complete: function() { + $('#notf-box_' + tlid).addClass('column-hide') + $('#notf-box_' + tlid).css('display', 'none') + }, + }) + } + notfCanceler(acct) } + function notfCanceler(acct) { - $('.notf-reply_' + acct).text(0) - localStorage.removeItem('notf-reply_' + acct) - $('.notf-reply_' + acct).addClass('hide') - $('.notf-fav_' + acct).text(0) - localStorage.removeItem('notf-fav_' + acct) - $('.notf-fav_' + acct).addClass('hide') - $('.notf-bt_' + acct).text(0) - localStorage.removeItem('notf-bt_' + acct) - $('.notf-bt_' + acct).addClass('hide') - $('.notf-follow_' + acct).text(0) - localStorage.removeItem('notf-follow_' + acct) - $('.notf-follow_' + acct).addClass('hide') - $('.notf-icon_' + acct).removeClass('red-text') - var id = $('#announce_' + acct + ' .announcement').first().attr('data-id') - $('.notf-announ_' + acct + '_ct').text("") - $(`.boxIn[data-acct=${acct}] .notice-box`).removeClass('has-notf') - if(id) { - localStorage.setItem('announ_' + acct, id) - } + $('.notf-reply_' + acct).text(0) + localStorage.removeItem('notf-reply_' + acct) + $('.notf-reply_' + acct).addClass('hide') + $('.notf-fav_' + acct).text(0) + localStorage.removeItem('notf-fav_' + acct) + $('.notf-fav_' + acct).addClass('hide') + $('.notf-bt_' + acct).text(0) + localStorage.removeItem('notf-bt_' + acct) + $('.notf-bt_' + acct).addClass('hide') + $('.notf-follow_' + acct).text(0) + localStorage.removeItem('notf-follow_' + acct) + $('.notf-follow_' + acct).addClass('hide') + $('.notf-icon_' + acct).removeClass('red-text') + var id = $('#announce_' + acct + ' .announcement') + .first() + .attr('data-id') + $('.notf-announ_' + acct + '_ct').text('') + $(`.boxIn[data-acct=${acct}] .notice-box`).removeClass('has-notf') + if (id) { + localStorage.setItem('announ_' + acct, id) + } } + function allNotfRead() { - var multi = localStorage.getItem('multi') - if (multi) { - var obj = JSON.parse(multi) - Object.keys(obj).forEach(function(key) { - notfCanceler(key) - }) - } + var multi = localStorage.getItem('multi') + if (multi) { + var obj = JSON.parse(multi) + Object.keys(obj).forEach(function(key) { + notfCanceler(key) + }) + } } -allNotfRead() +allNotfRead() \ No newline at end of file diff --git a/app/js/ui/settings.js b/app/js/ui/settings.js index 63124893..fea14516 100644 --- a/app/js/ui/settings.js +++ b/app/js/ui/settings.js @@ -544,12 +544,7 @@ function insertFont(name) { } function copyColor(from, to) { - let props = [ - 'background', 'subcolor', 'text', 'accent', - 'modal', 'modalFooter', 'third', 'forth', - 'bottom', 'emphasized', 'postbox', 'active', - 'selected', 'selectedWithShared' - ] + let props = ['background', 'subcolor', 'text', 'accent', 'modal', 'modalFooter', 'third', 'forth', 'bottom', 'emphasized', 'postbox', 'active', 'selected', 'selectedWithShared'] let i = 0 let color for (tag of props) { @@ -589,11 +584,7 @@ function customComp(preview) { var textC = $('#color-picker1_value').val() var accentC = $('#color-picker3_value').val() var multi = localStorage.getItem('multi') - let advanced = [ - 'modal', 'modalFooter', 'third', 'forth', - 'bottom', 'emphasized', 'postbox', 'active', - 'selected', 'selectedWithShared' - ] + let advanced = ['modal', 'modalFooter', 'third', 'forth', 'bottom', 'emphasized', 'postbox', 'active', 'selected', 'selectedWithShared'] var advanceTheme = {} let i = 4 for (tag of advanced) { @@ -606,9 +597,7 @@ function customComp(preview) { var my = JSON.parse(multi)[0].name var id = $('#custom-edit-sel').val() - const defaults = [ - 'black', 'blue', 'brown', 'green', 'indigo', 'polar', 'snow', 'white' - ] + const defaults = ['black', 'blue', 'brown', 'green', 'indigo', 'polar', 'snow', 'white'] if (id == 'add_new' || defaults.includes(id)) { id = makeCID() } @@ -622,11 +611,11 @@ function customComp(preview) { background: bgC, subcolor: subcolorC, text: textC, - accent: accentC + accent: accentC, }, advanced: advanceTheme, id: id, - version: '2' + version: '2', } $('#custom_json').val(JSON.stringify(json)) if (preview) { @@ -640,7 +629,6 @@ function customComp(preview) { }) postMessage(['themeJsonCreate', JSON.stringify(json)], '*') } - } function deleteIt() { @@ -710,16 +698,11 @@ function customConnect(raw) { $('#color-picker2_value').val(args.primary.subcolor) //Accent $('#color-picker3_value').val(args.primary.accent) - let advanced = [ - 'modal', 'modalFooter', 'third', 'forth', - 'bottom', 'emphasized', 'postbox', 'active', - 'selected', 'selectedWithShared' - ] + let advanced = ['modal', 'modalFooter', 'third', 'forth', 'bottom', 'emphasized', 'postbox', 'active', 'selected', 'selectedWithShared'] let i = 4 for (tag of advanced) { if (args.advanced[tag]) { $(`#color-picker${i}_value`).val(args.advanced[tag]) - } $(`#use-color_${i}`).prop('checked', true) i++ @@ -765,7 +748,7 @@ function customSoundSave(key, file) { } function pluginLoad() { $('#plugin-edit-sel').val('add_new') - $(".plugin_delete").addClass('disabled') + $('.plugin_delete').addClass('disabled') var template = '' var pgns = localStorage.getItem('plugins') var args = JSON.parse(pgns ? pgns : '[]') @@ -783,9 +766,9 @@ function pluginEdit() { $('#plugin').attr('data-id', id) if (id == 'add_new') { editor.setValue('', -1) - $(".plugin_delete").addClass('disabled') + $('.plugin_delete').addClass('disabled') } else { - $(".plugin_delete").removeClass('disabled') + $('.plugin_delete').removeClass('disabled') var pgns = localStorage.getItem('plugins') var args = JSON.parse(pgns ? pgns : '[]') Object.keys(args).forEach(function (key) { @@ -823,7 +806,7 @@ function completePlugin(comp) { id = makeCID() args.push({ id: id, - content: inputPlugin + content: inputPlugin, }) } else { Object.keys(args).forEach(function (key) { @@ -857,7 +840,7 @@ async function deletePlugin() { const alert = await Swal.fire({ title: 'delete', icon: 'warning', - showCancelButton: true + showCancelButton: true, }) if (!alert) return false editor.setValue('', -1) @@ -959,4 +942,6 @@ function lastFmSet() { M.toast({ html: 'Complete: last.fm', displayLength: 3000 }) } -function stopVideo() { return false } \ No newline at end of file +function stopVideo() { + return false +} \ No newline at end of file diff --git a/app/js/userdata/showOnTL.js b/app/js/userdata/showOnTL.js index c33e9327..9229ce50 100644 --- a/app/js/userdata/showOnTL.js +++ b/app/js/userdata/showOnTL.js @@ -1,586 +1,612 @@ //ユーザーデータ表示 -localStorage.removeItem("history") -//コード受信 +localStorage.removeItem('history') + //コード受信 if (location.search) { - var m = location.search.match(/\?mode=([a-zA-Z-0-9]+)\&code=(.+)/) - var mode = m[1] - var codex = m[2] - if (mode == "user") { - udgEx(codex, "main") - } + var m = location.search.match(/\?mode=([a-zA-Z-0-9]+)\&code=(.+)/) + var mode = m[1] + var codex = m[2] + if (mode == 'user') { + udgEx(codex, 'main') + } } -function udgEx(user, acct_id) { - if (user == "selector") { - user = $("#his-acct").attr("fullname") - } - if (acct_id == "selector") { - acct_id = $("#user-acct-sel").val() - } - if (acct_id == "main") { - acct_id = localStorage.getItem("main") - } - console.log("Get user data of " + user) - var domain = localStorage.getItem("domain_" + acct_id) - if (localStorage.getItem("mode_" + domain) == "misskey") { - return false - } - var at = localStorage.getItem("acct_" + acct_id + "_at") - var start = "https://" + domain + "/api/v2/search?resolve=true&q=" + encodeURIComponent(user) - Swal.fire({ - title: 'Loading...', - html: lang.lang_details_fetch, - showConfirmButton: false, - showCloseButton: true, - onBeforeOpen: () => { - Swal.showLoading() - }, - onClose: () => { }, - }).then((result) => { }) - fetch(start, { - method: "GET", - headers: { - "content-type": "application/json", - Authorization: "Bearer " + at - } - }) - .then(function (response) { - if (!response.ok) { - Swal.close() - 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.accounts[0]) { - var id = json.accounts[0].id - udg(id, acct_id, true) - } else { - Swal.close() - postMessage(["openUrl", user], "*") - } - }) - return true -} -function udg(user, acct_id, isSwal) { - reset() - if (!user) { - user = localStorage.getItem("user-id_" + acct_id) - } - todo("User Data Loading...") - var domain = localStorage.getItem("domain_" + acct_id) - if (localStorage.getItem("mode_" + domain) == "misskey") { - misskeyUdg(user, acct_id) - return - } - var at = localStorage.getItem("acct_" + acct_id + "_at") - var start = "https://" + domain + "/api/v1/accounts/" + user - fetch(start, { - method: "GET", - headers: { - "content-type": "application/json", - Authorization: "Bearer " + at - } - }) - .then(function (response) { - if(isSwal) Swal.close() - 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 (!localStorage.getItem("history")) { - $("#his-history-btn").prop("disabled", true) - } else { - $("#his-history-btn").prop("disabled", false) - $("#his-data").attr("history", localStorage.getItem("history")) - } - //moved設定時 - if (json.moved) { - M.toast({ - html: lang.lang_showontl_movetxt + '", - displayLength: 4000 - }) - } - $("#his-data").modal("open") - $("#his-data").attr("user-id", user) - $("#his-data").attr("use-acct", acct_id) - if (json.username != json.acct) { - //Remote - $("#his-data").attr("remote", "true") - var fullname = json.acct - } else { - $("#his-data").attr("remote", "false") - var fullname = json.acct + "@" + domain - } - utlShow(json.id, "", acct_id) - flw(json.id, "", acct_id) - fer(json.id, "", acct_id) - var dis_name = escapeHTML(json.display_name) - dis_name = twemoji.parse(dis_name) - var note = json.note - if (json.emojis) { - var actemojick = json.emojis[0] - } else { - var actemojick = false - } - //絵文字があれば - if (actemojick) { - Object.keys(json.emojis).forEach(function (key5) { - var emoji = json.emojis[key5] - var shortcode = emoji.shortcode - var emoji_url = '' - var regExp = new RegExp(":" + shortcode + ":", "g") - dis_name = dis_name.replace(regExp, emoji_url) - note = note.replace(regExp, emoji_url) - }) - } - //noteの解析 - //var tags = '
#$1'; - //var mens = '@$1'; - //note=note.replace(/#(\S+)/gi, tags) - //note=note.replace(/\s@([a-zA-Z_0-9@.-]+)/gi, mens) - $("#his-name").html(dis_name) - $("#his-acct").text(json.acct) - $("#his-acct").attr("fullname", fullname) - $("#his-prof").attr("src", json.avatar) - $("#util-add").removeClass("hide") - const title = $('.column-first').html() - $("#my-data-nav .anc-link").removeClass("active-back") - $('.column-first').addClass("active-back") - $('#his-data-title').html(title) - $("#his-data").css("background-image", "url(" + json.header + ")") - $("#his-sta").text(json.statuses_count) - $("#his-follow").text(json.following_count) - var flerc = json.followers_count - if (flerc < 0) { - flerc = "-" - } - $("#his-follower").text(flerc) - $("#his-since").text(crat(json.created_at)) - $("#his-openin").attr("data-href", json.url) - if (json.fields) { - var table = "" - if (json.fields.length > 0) { - $("#his-des").css("max-height", "250px") - table = '' - for (var i = 0; i < json.fields.length; i++) { - var fname = json.fields[i].name - var fval = json.fields[i].value - if (json.fields[i].verified_at) { - var when = lang.lang_showontl_verified + ":" + crat(json.fields[i].verified_at) - var color = "rgba(121,189,154,.25);" - } else { - var when = "" - var color = "inherit" - } - table = table + '" - } - table = table + "
' + escapeHTML(fname) + '' + fval + "
" - $("#his-des").html(twemoji.parse(note)) - } else { - $("#his-des").css("max-height", "400px") - } - $("#his-table").html(twemoji.parse(table)) - } else { - $("#his-des").css("max-height", "400px") - } - $("#his-des").html(twemoji.parse(note)) - if (json.bot) { - $("#his-bot").html(lang.lang_showontl_botacct) - $("#his-bot").removeClass("hide") - } - $("#his-des").attr("data-acct", acct_id) - $("#his-data").css("background-size", "cover") - $("#his-float-timeline").css("height", $("#his-data-show").height() + "px") - localStorage.setItem("history", user) - //自分の時 - if (json.acct == localStorage.getItem("user_" + acct_id)) { - showFav("", acct_id) - showBlo("", acct_id) - showMut("", acct_id) - showDom("", acct_id) - showReq("", acct_id) - showFrl("", acct_id) - $("#his-name-val").val(json.display_name) - if (json.fields.length > 0) { - if (json.fields[0]) { - $("#his-f1-name").val(json.fields[0].name) - $("#his-f1-val").val($.strip_tags(json.fields[0].value)) - } - if (json.fields[1]) { - $("#his-f2-name").val(json.fields[1].name) - $("#his-f2-val").val($.strip_tags(json.fields[1].value)) - } - if (json.fields[2]) { - $("#his-f3-name").val(json.fields[2].name) - $("#his-f3-val").val($.strip_tags(json.fields[2].value)) - } - if (json.fields[3]) { - $("#his-f4-name").val(json.fields[3].name) - $("#his-f4-val").val($.strip_tags(json.fields[3].value)) - } - } - var des = json.note - des = des.replace(/
/g, "\n") - des = $.strip_tags(des) - $("#his-des-val").val(des) - $("#his-follow-btn").hide() - $("#his-block-btn").hide() - $("#his-mute-btn").hide() - $("#his-notf-btn").hide() - $("#his-domain-btn").hide() - $("#his-emp-btn").hide() - $(".only-my-data").show() - $(".only-his-data").hide() - if (localStorage.getItem("main") == acct_id) { - $("#his-main-acct").hide() - } - } else { - relations(user, acct_id) - $(".only-my-data").hide() - $(".only-his-data").show() - } - todc() - if (json.locked) { - $('#his-data').addClass('locked') - } else { - $('#his-data').removeClass('locked') - } - //外部データ取得(死かもしれないので) - udAdd(acct_id, user, json.url) - }) +async function udgEx(user, acct_id) { + if (user == 'selector') { + user = $('#his-acct').attr('fullname') + } + if (acct_id == 'selector') { + acct_id = $('#user-acct-sel').val() + } + if (acct_id == 'main') { + acct_id = localStorage.getItem('main') + } + console.log('Get user data of ' + user) + var domain = localStorage.getItem('domain_' + acct_id) + if (localStorage.getItem('mode_' + domain) == 'misskey') { + return false + } + var at = localStorage.getItem('acct_' + acct_id + '_at') + var data = await acctResolve(acct_id, user) + if (data.id) { + var { id } = data + udg(id, acct_id, true) + } else { + Swal.close() + postMessage(['openUrl', user], '*') + } + + return true + var start = 'https://' + domain + '/api/v2/search?resolve=true&q=' + encodeURIComponent(user) + Swal.fire({ + title: 'Loading...', + html: lang.lang_details_fetch, + showConfirmButton: false, + showCloseButton: true, + onBeforeOpen: () => { + Swal.showLoading() + }, + onClose: () => {}, + }).then((result) => {}) + fetch(start, { + method: 'GET', + headers: { + 'content-type': 'application/json', + Authorization: 'Bearer ' + at, + }, + }) + .then(function(response) { + if (!response.ok) { + Swal.close() + 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.accounts[0]) { + var id = json.accounts[0].id + udg(id, acct_id, true) + } else { + Swal.close() + postMessage(['openUrl', user], '*') + } + }) + return true } + +function udg(user, acct_id, isSwal) { + reset() + if (!user) { + user = localStorage.getItem('user-id_' + acct_id) + } + todo('User Data Loading...') + var domain = localStorage.getItem('domain_' + acct_id) + if (localStorage.getItem('mode_' + domain) == 'misskey') { + misskeyUdg(user, acct_id) + return + } + var at = localStorage.getItem('acct_' + acct_id + '_at') + var start = 'https://' + domain + '/api/v1/accounts/' + user + fetch(start, { + method: 'GET', + headers: { + 'content-type': 'application/json', + Authorization: 'Bearer ' + at, + }, + }) + .then(function(response) { + if (isSwal) Swal.close() + 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 (!localStorage.getItem('history')) { + $('#his-history-btn').prop('disabled', true) + } else { + $('#his-history-btn').prop('disabled', false) + $('#his-data').attr('history', localStorage.getItem('history')) + } + //moved設定時 + if (json.moved) { + M.toast({ + html: lang.lang_showontl_movetxt + '', + displayLength: 4000, + }) + } + $('#his-data').modal('open') + $('#his-data').attr('user-id', user) + $('#his-data').attr('use-acct', acct_id) + if (json.username != json.acct) { + //Remote + $('#his-data').attr('remote', 'true') + var fullname = json.acct + } else { + $('#his-data').attr('remote', 'false') + var fullname = json.acct + '@' + domain + } + utlShow(json.id, '', acct_id) + flw(json.id, '', acct_id) + fer(json.id, '', acct_id) + var dis_name = escapeHTML(json.display_name) + dis_name = twemoji.parse(dis_name) + + var note = json.note + if (json.emojis) { + var actemojick = json.emojis[0] + } else { + var actemojick = false + } + //絵文字があれば + if (actemojick) { + Object.keys(json.emojis).forEach(function(key5) { + var emoji = json.emojis[key5] + var shortcode = emoji.shortcode + var emoji_url = '' + var regExp = new RegExp(':' + shortcode + ':', 'g') + dis_name = dis_name.replace(regExp, emoji_url) + note = note.replace(regExp, emoji_url) + }) + } + //noteの解析 + //var tags = '#$1'; + //var mens = '@$1'; + //note=note.replace(/#(\S+)/gi, tags) + //note=note.replace(/\s@([a-zA-Z_0-9@.-]+)/gi, mens) + $('#his-name').html(dis_name) + $('#his-acct').text(json.acct) + $('#his-acct').attr('fullname', fullname) + $('#his-prof').attr('src', json.avatar) + $('#util-add').removeClass('hide') + const title = $('.column-first').html() + $('#my-data-nav .anc-link').removeClass('active-back') + $('.column-first').addClass('active-back') + $('#his-data-title').html(title) + $('#his-data').css('background-image', 'url(' + json.header + ')') + $('#his-sta').text(json.statuses_count) + $('#his-follow').text(json.following_count) + var flerc = json.followers_count + if (flerc < 0) { + flerc = '-' + } + $('#his-follower').text(flerc) + $('#his-since').text(crat(json.created_at)) + $('#his-openin').attr('data-href', json.url) + if (json.fields) { + var table = '' + if (json.fields.length > 0) { + $('#his-des').css('max-height', '250px') + table = '' + for (var i = 0; i < json.fields.length; i++) { + var fname = json.fields[i].name + var fval = json.fields[i].value + if (json.fields[i].verified_at) { + var when = lang.lang_showontl_verified + ':' + crat(json.fields[i].verified_at) + var color = 'rgba(121,189,154,.25);' + } else { + var when = '' + var color = 'inherit' + } + table = + table + + '' + } + table = table + '
' + + escapeHTML(fname) + + '' + + fval + + '
' + $('#his-des').html(twemoji.parse(note)) + } else { + $('#his-des').css('max-height', '400px') + } + $('#his-table').html(twemoji.parse(table)) + } else { + $('#his-des').css('max-height', '400px') + } + $('#his-des').html(twemoji.parse(note)) + if (json.bot) { + $('#his-bot').html(lang.lang_showontl_botacct) + $('#his-bot').removeClass('hide') + } + $('#his-des').attr('data-acct', acct_id) + $('#his-data').css('background-size', 'cover') + $('#his-float-timeline').css('height', $('#his-data-show').height() + 'px') + localStorage.setItem('history', user) + //自分の時 + if (json.acct == localStorage.getItem('user_' + acct_id)) { + showFav('', acct_id) + showBlo('', acct_id) + showMut('', acct_id) + showDom('', acct_id) + showReq('', acct_id) + showFrl('', acct_id) + $('#his-name-val').val(json.display_name) + if (json.fields.length > 0) { + if (json.fields[0]) { + $('#his-f1-name').val(json.fields[0].name) + $('#his-f1-val').val($.strip_tags(json.fields[0].value)) + } + if (json.fields[1]) { + $('#his-f2-name').val(json.fields[1].name) + $('#his-f2-val').val($.strip_tags(json.fields[1].value)) + } + if (json.fields[2]) { + $('#his-f3-name').val(json.fields[2].name) + $('#his-f3-val').val($.strip_tags(json.fields[2].value)) + } + if (json.fields[3]) { + $('#his-f4-name').val(json.fields[3].name) + $('#his-f4-val').val($.strip_tags(json.fields[3].value)) + } + } + var des = json.note + des = des.replace(/
/g, '\n') + des = $.strip_tags(des) + $('#his-des-val').val(des) + $('#his-follow-btn').hide() + $('#his-block-btn').hide() + $('#his-mute-btn').hide() + $('#his-notf-btn').hide() + $('#his-domain-btn').hide() + $('#his-emp-btn').hide() + $('.only-my-data').show() + $('.only-his-data').hide() + if (localStorage.getItem('main') == acct_id) { + $('#his-main-acct').hide() + } + } else { + relations(user, acct_id) + $('.only-my-data').hide() + $('.only-his-data').show() + } + todc() + if (json.locked) { + $('#his-data').addClass('locked') + } else { + $('#his-data').removeClass('locked') + } + //外部データ取得(死かもしれないので) + udAdd(acct_id, user, json.url) + }) +} + function misskeyUdg(user, acct_id) { - reset() - if (!user) { - user = localStorage.getItem("user-id_" + acct_id) - } - todo("User Data Loading...") - var domain = localStorage.getItem("domain_" + acct_id) - if (localStorage.getItem("mode_" + domain) != "misskey") { - udg(user, acct_id) - return - } - var at = localStorage.getItem("acct_" + acct_id + "_at") - var start = "https://" + domain + "/api/users/show" - fetch(start, { - method: "POST", - headers: { - "content-type": "application/json" - }, - body: JSON.stringify({ - i: at, - userId: user - }) - }) - .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 (!localStorage.getItem("history")) { - $("#his-history-btn").prop("disabled", true) - } else { - $("#his-history-btn").prop("disabled", false) - $("#his-data").attr("history", localStorage.getItem("history")) - } - $("#his-data").modal("open") - $("#his-data").attr("user-id", user) - $("#his-data").attr("use-acct", acct_id) - if (json.host) { - //Remote - $("#his-data").attr("remote", "false") - var fullname = json.username + "@" + json.host - } else { - $("#his-data").attr("remote", "false") - var fullname = json.acct + "@" + domain - } - utlShow(json.id, "", acct_id) - flw(json.id, "", acct_id) - fer(json.id, "", acct_id) - if (json.name) { - var dis_name = escapeHTML(json.name) - dis_name = twemoji.parse(dis_name) - } else { - var dis_name = json.name - } - $("#his-name").html(dis_name) - $("#his-acct").text(json.username) - $("#his-acct").attr("fullname", fullname) - $("#his-prof").attr("src", json.avatarUrl) - $("#his-data").css("background-image", "url(" + json.bannerUrl + ")") - $("#his-sta").text(json.notesCount) - $("#his-follow").text(json.followingCount) - $("#his-follower").text(json.followersCount) - $("#his-since").text(crat(json.createdAt)) - var note = escapeHTML(json.description) - $("#his-des").html(twemoji.parse(note)) - if (json.isCat) { - $("#his-bot").html("Cat" + twemoji.parse("😺")) - } - $("#his-data").css("background-size", "cover") - localStorage.setItem("history", user) - //自分の時 - if (json.username == localStorage.getItem("user_" + acct_id) && !json.host) { - //showFav('', acct_id); - //showMut('', acct_id); - //showReq('', acct_id); - showFrl("", acct_id) - $("#his-name-val").val(json.name) - var des = json.note - des = nl2br(des) - des = $.strip_tags(des) - $("#his-des-val").val(des) - $("#his-follow-btn").hide() - $("#his-block-btn").hide() - $("#his-mute-btn").hide() - $("#his-notf-btn").hide() - $("#his-domain-btn").hide() - $("#his-emp-btn").hide() - $(".only-my-data").show() - $(".only-his-data").hide() - if (localStorage.getItem("main") == acct_id) { - $("#his-main-acct").hide() - } - } else { - if (json.isFollowing) { - //自分がフォローしている - $("#his-data").addClass("following") - $("#his-follow-btn-text").text(lang.lang_status_unfollow) - hisList(user, acct_id) - } else { - $("#his-follow-btn-text").text(lang.lang_status_follow) - } - if (json.isFollowed) { - //フォローされてる - $("#his-relation").text(lang.lang_showontl_followed) - } - $("#his-block-btn").hide() - if (json.isMuted) { - $("#his-data").addClass("muting") - $("#his-mute-btn-text").text(lang.lang_status_unmute) - } else { - $("#his-mute-btn-text").text(lang.lang_status_mute) - } - $(".only-my-data").hide() - $(".only-his-data").show() - } - todc() - }) + reset() + if (!user) { + user = localStorage.getItem('user-id_' + acct_id) + } + todo('User Data Loading...') + var domain = localStorage.getItem('domain_' + acct_id) + if (localStorage.getItem('mode_' + domain) != 'misskey') { + udg(user, acct_id) + return + } + var at = localStorage.getItem('acct_' + acct_id + '_at') + var start = 'https://' + domain + '/api/users/show' + fetch(start, { + method: 'POST', + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify({ + i: at, + userId: user, + }), + }) + .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 (!localStorage.getItem('history')) { + $('#his-history-btn').prop('disabled', true) + } else { + $('#his-history-btn').prop('disabled', false) + $('#his-data').attr('history', localStorage.getItem('history')) + } + $('#his-data').modal('open') + $('#his-data').attr('user-id', user) + $('#his-data').attr('use-acct', acct_id) + if (json.host) { + //Remote + $('#his-data').attr('remote', 'false') + var fullname = json.username + '@' + json.host + } else { + $('#his-data').attr('remote', 'false') + var fullname = json.acct + '@' + domain + } + utlShow(json.id, '', acct_id) + flw(json.id, '', acct_id) + fer(json.id, '', acct_id) + if (json.name) { + var dis_name = escapeHTML(json.name) + dis_name = twemoji.parse(dis_name) + } else { + var dis_name = json.name + } + $('#his-name').html(dis_name) + $('#his-acct').text(json.username) + $('#his-acct').attr('fullname', fullname) + $('#his-prof').attr('src', json.avatarUrl) + $('#his-data').css('background-image', 'url(' + json.bannerUrl + ')') + $('#his-sta').text(json.notesCount) + $('#his-follow').text(json.followingCount) + $('#his-follower').text(json.followersCount) + $('#his-since').text(crat(json.createdAt)) + var note = escapeHTML(json.description) + $('#his-des').html(twemoji.parse(note)) + if (json.isCat) { + $('#his-bot').html('Cat' + twemoji.parse('😺')) + } + $('#his-data').css('background-size', 'cover') + localStorage.setItem('history', user) + //自分の時 + if (json.username == localStorage.getItem('user_' + acct_id) && !json.host) { + //showFav('', acct_id); + //showMut('', acct_id); + //showReq('', acct_id); + showFrl('', acct_id) + $('#his-name-val').val(json.name) + var des = json.note + des = nl2br(des) + des = $.strip_tags(des) + $('#his-des-val').val(des) + $('#his-follow-btn').hide() + $('#his-block-btn').hide() + $('#his-mute-btn').hide() + $('#his-notf-btn').hide() + $('#his-domain-btn').hide() + $('#his-emp-btn').hide() + $('.only-my-data').show() + $('.only-his-data').hide() + if (localStorage.getItem('main') == acct_id) { + $('#his-main-acct').hide() + } + } else { + if (json.isFollowing) { + //自分がフォローしている + $('#his-data').addClass('following') + $('#his-follow-btn-text').text(lang.lang_status_unfollow) + hisList(user, acct_id) + } else { + $('#his-follow-btn-text').text(lang.lang_status_follow) + } + if (json.isFollowed) { + //フォローされてる + $('#his-relation').text(lang.lang_showontl_followed) + } + $('#his-block-btn').hide() + if (json.isMuted) { + $('#his-data').addClass('muting') + $('#his-mute-btn-text').text(lang.lang_status_unmute) + } else { + $('#his-mute-btn-text').text(lang.lang_status_mute) + } + $('.only-my-data').hide() + $('.only-his-data').show() + } + todc() + }) } //一つ前のユーザーデータ表示 function historyShow() { - var acct_id = $("#his-data").attr("use-acct") - var user = $("#his-data").attr("history") - udg(user, acct_id, "true") + var acct_id = $('#his-data').attr('use-acct') + var user = $('#his-data').attr('history') + udg(user, acct_id, 'true') } //選択アカウントのプロフ function profShow() { - var acct_id = $("#post-acct-sel").val() - var user = localStorage.getItem("user-id_" + acct_id) - udg(user, acct_id) - hide() + var acct_id = $('#post-acct-sel').val() + var user = localStorage.getItem('user-id_' + acct_id) + udg(user, acct_id) + hide() } //FF関係取得 function relations(user, acct_id) { - var domain = localStorage.getItem("domain_" + acct_id) - var at = localStorage.getItem("acct_" + acct_id + "_at") - var start = "https://" + domain + "/api/v1/accounts/relationships?id=" + user - 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 (json) { - var json = json[0] - if (json.requested) { - //フォロリク中 - $('#his-data').addClass('following') - $("#his-follow-btn-text").text(lang.lang_status_requesting) - } - if (json.following) { - //自分がフォローしている - $("#his-data").addClass("following") - $("#his-follow-btn-text").text(lang.lang_status_unfollow) - hisList(user, acct_id) - } else { - $("#his-follow-btn-text").text(lang.lang_status_follow) - } - if (json.followed_by) { - //フォローされてる - $("#his-relation").text(lang.lang_showontl_followed) - } - if (json.blocking) { - $("#his-data").addClass("blocking") - $("#his-block-btn-text").text(lang.lang_status_unblock) - } else { - $("#his-block-btn-text").text(lang.lang_status_block) - } - if (json.muting) { - $("#his-data").addClass("muting") - $("#his-mute-btn-text").text(lang.lang_status_unmute) - } else { - $("#his-mute-btn-text").text(lang.lang_status_mute) - } - if (json.muting_notifications) { - $("#his-data").addClass("mutingNotf") - $("#his-notf-btn-text").text(lang.lang_showontl_notf + lang.lang_status_unmute) - } else { - $("#his-notf-btn-text").text(lang.lang_showontl_notf + lang.lang_status_mute) - } - if (json.domain_blocking) { - $("#his-data").addClass("blockingDom") - $("#his-domain-btn-text").text(lang.lang_showontl_domain + lang.lang_status_unblock) - } else { - $("#his-domain-btn-text").text(lang.lang_showontl_domain + lang.lang_status_block) - } - //Endorsed - if (json.endorsed) { - $("#his-end-btn").addClass("endorsed") - $("#his-end-btn-text").text(lang.lang_status_unendorse) - } else { - $("#his-end-btn").removeClass("endorsed") - $("#his-end-btn-text").text(lang.lang_status_endorse) - } - //Blocked - if (json.blocked_by) { - $("#my-data-nav .btn").addClass("disabled") - $(".his-var-content").hide() - $("#his-float-blocked").show() - $("#his-follow-btn").hide() - } - }) + var domain = localStorage.getItem('domain_' + acct_id) + var at = localStorage.getItem('acct_' + acct_id + '_at') + var start = 'https://' + domain + '/api/v1/accounts/relationships?id=' + user + 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(json) { + var json = json[0] + if (json.requested) { + //フォロリク中 + $('#his-data').addClass('following') + $('#his-follow-btn-text').text(lang.lang_status_requesting) + } + if (json.following) { + //自分がフォローしている + $('#his-data').addClass('following') + $('#his-follow-btn-text').text(lang.lang_status_unfollow) + hisList(user, acct_id) + } else { + $('#his-follow-btn-text').text(lang.lang_status_follow) + } + if (json.followed_by) { + //フォローされてる + $('#his-relation').text(lang.lang_showontl_followed) + } + if (json.blocking) { + $('#his-data').addClass('blocking') + $('#his-block-btn-text').text(lang.lang_status_unblock) + } else { + $('#his-block-btn-text').text(lang.lang_status_block) + } + if (json.muting) { + $('#his-data').addClass('muting') + $('#his-mute-btn-text').text(lang.lang_status_unmute) + } else { + $('#his-mute-btn-text').text(lang.lang_status_mute) + } + if (json.muting_notifications) { + $('#his-data').addClass('mutingNotf') + $('#his-notf-btn-text').text(lang.lang_showontl_notf + lang.lang_status_unmute) + } else { + $('#his-notf-btn-text').text(lang.lang_showontl_notf + lang.lang_status_mute) + } + if (json.domain_blocking) { + $('#his-data').addClass('blockingDom') + $('#his-domain-btn-text').text(lang.lang_showontl_domain + lang.lang_status_unblock) + } else { + $('#his-domain-btn-text').text(lang.lang_showontl_domain + lang.lang_status_block) + } + //Endorsed + if (json.endorsed) { + $('#his-end-btn').addClass('endorsed') + $('#his-end-btn-text').text(lang.lang_status_unendorse) + } else { + $('#his-end-btn').removeClass('endorsed') + $('#his-end-btn-text').text(lang.lang_status_endorse) + } + //Blocked + if (json.blocked_by) { + $('#my-data-nav .btn').addClass('disabled') + $('.his-var-content').hide() + $('#his-float-blocked').show() + $('#his-follow-btn').hide() + } + }) } + function profbrws() { - var url = $("#his-openin").attr("data-href") - postMessage(["openUrl", url], "*") + var url = $('#his-openin').attr('data-href') + postMessage(['openUrl', url], '*') } + function setMain() { - var acct_id = $("#his-data").attr("use-acct") - localStorage.setItem("main", acct_id) - multiSelector(true) - M.toast({ html: lang.lang_manager_mainAcct, displayLength: 3000 }) + var acct_id = $('#his-data').attr('use-acct') + localStorage.setItem('main', acct_id) + multiSelector(true) + M.toast({ html: lang.lang_manager_mainAcct, displayLength: 3000 }) } //オールリセット function hisclose() { - $("#his-data").modal("close") - reset() - $("#his-data").attr("history", "") - localStorage.removeItem("history") + $('#his-data').modal('close') + reset() + $('#his-data').attr('history', '') + localStorage.removeItem('history') } + function reset() { - $(".his-var-content:eq(0)").show() - $(".his-var-content:gt(0)").hide() - $("#my-data-nav .btn").removeClass("disabled") - $(".active-back").removeClass("active-back") - $(".column-first").addClass("active-back") - $("#his-name").text("Loading") - $("#his-acct").text("") - $("#his-prof").attr("src", "../../img/loading.svg") - $("#his-data").css("background-image", "url(../../img/loading.svg)") - $("#his-sta").text("") - $("#his-follow").text("") - $("#his-follower").text("") - $("#his-des").html("") - $("#his-data").css("background-size", "cover") - $("#his-since").text("") - $("#his-data").removeClass("following") - $("#his-data").removeClass("muting") - $("#his-data").removeClass("blocking") - $("#his-data").removeClass("mutingNotf") - $("#his-data").removeClass("blockingDom") - $("#his-end-btn").removeClass("endorsed") - $("#his-des").css("max-height", "250px") - $("#his-bot").html("") - $("#his-bot").addClass("hide") - $("#his-follow-btn").show() - $("#his-block-btn").show() - $("#his-mute-btn").show() - $("#his-notf-btn").show() - $("#his-domain-btn").show() - $("#his-emp-btn").show() - $("#his-follow-btn-text").text(lang.lang_status_follow) - $("#his-mute-btn-text").text(lang.lang_status_mute) - $("#his-block-btn-text").text(lang.lang_status_block) - $("#his-notf-btn").text(lang.lang_showontl_notf + lang.lang_status_mute) - $("#his-domain-btn").text(lang.lang_showontl_domain + lang.lang_status_block) - $("#his-relation").text("") - $(".cont-series").html("") - $("#domainblock").val("") - $("#his-lists-a").html(lang.lang_showontl_listwarn) - $("#his-lists-b").html("") - $("#his-name-val").val("") - $("#his-des-val").val("") - $("#his-f1-name").val("") - $("#his-f1-val").val("") - $("#his-f2-name").val("") - $("#his-f2-val").val("") - $("#his-f3-name").val("") - $("#his-f3-val").val("") - $("#his-f4-name").val("") - $("#his-f4-val").val("") - $("#his-endorse").html("") - $("#his-openin").attr("data-href", "") - $("#his-float-timeline").show() - $("#his-float-blocked").hide() - $("#his-main-acct").show() - $("#his-proof-prof").html("") - $('#his-data').removeClass('locked') - $('#his-data').removeClass('requesting') + $('.his-var-content:eq(0)').show() + $('.his-var-content:gt(0)').hide() + $('#my-data-nav .btn').removeClass('disabled') + $('.active-back').removeClass('active-back') + $('.column-first').addClass('active-back') + $('#his-name').text('Loading') + $('#his-acct').text('') + $('#his-prof').attr('src', '../../img/loading.svg') + $('#his-data').css('background-image', 'url(../../img/loading.svg)') + $('#his-sta').text('') + $('#his-follow').text('') + $('#his-follower').text('') + $('#his-des').html('') + $('#his-data').css('background-size', 'cover') + $('#his-since').text('') + $('#his-data').removeClass('following') + $('#his-data').removeClass('muting') + $('#his-data').removeClass('blocking') + $('#his-data').removeClass('mutingNotf') + $('#his-data').removeClass('blockingDom') + $('#his-end-btn').removeClass('endorsed') + $('#his-des').css('max-height', '250px') + $('#his-bot').html('') + $('#his-bot').addClass('hide') + $('#his-follow-btn').show() + $('#his-block-btn').show() + $('#his-mute-btn').show() + $('#his-notf-btn').show() + $('#his-domain-btn').show() + $('#his-emp-btn').show() + $('#his-follow-btn-text').text(lang.lang_status_follow) + $('#his-mute-btn-text').text(lang.lang_status_mute) + $('#his-block-btn-text').text(lang.lang_status_block) + $('#his-notf-btn').text(lang.lang_showontl_notf + lang.lang_status_mute) + $('#his-domain-btn').text(lang.lang_showontl_domain + lang.lang_status_block) + $('#his-relation').text('') + $('.cont-series').html('') + $('#domainblock').val('') + $('#his-lists-a').html(lang.lang_showontl_listwarn) + $('#his-lists-b').html('') + $('#his-name-val').val('') + $('#his-des-val').val('') + $('#his-f1-name').val('') + $('#his-f1-val').val('') + $('#his-f2-name').val('') + $('#his-f2-val').val('') + $('#his-f3-name').val('') + $('#his-f3-val').val('') + $('#his-f4-name').val('') + $('#his-f4-val').val('') + $('#his-endorse').html('') + $('#his-openin').attr('data-href', '') + $('#his-float-timeline').show() + $('#his-float-blocked').hide() + $('#his-main-acct').show() + $('#his-proof-prof').html('') + $('#his-data').removeClass('locked') + $('#his-data').removeClass('requesting') } -$("#my-data-nav .anc-link").on("click", function () { - var target = $(this).attr("go") - if (target) { - let title = $(this).html() - if (target === '#his-tl') $("#util-add").removeClass("hide") - if (target != '#his-tl') $("#util-add").addClass("hide") - $('#his-data-title').html(title) - $("#my-data-nav .anc-link").removeClass("active-back") - $(this).addClass("active-back") - $(target).show() - $(".his-var-content:not(" + target + ")").hide() - } -}) +$('#my-data-nav .anc-link').on('click', function() { + var target = $(this).attr('go') + if (target) { + let title = $(this).html() + if (target === '#his-tl') $('#util-add').removeClass('hide') + if (target != '#his-tl') $('#util-add').addClass('hide') + $('#his-data-title').html(title) + $('#my-data-nav .anc-link').removeClass('active-back') + $(this).addClass('active-back') + $(target).show() + $('.his-var-content:not(' + target + ')').hide() + } +}) \ No newline at end of file diff --git a/app/view/pl-PL/index.html b/app/view/pl-PL/index.html index 38b82b57..36ba490c 100644 --- a/app/view/pl-PL/index.html +++ b/app/view/pl-PL/index.html @@ -27,7 +27,7 @@