From 2b3feb40ad67c29cdeb0423330584b641c182a67 Mon Sep 17 00:00:00 2001 From: cutls Date: Sat, 16 Nov 2019 04:58:37 +0900 Subject: [PATCH] Add bookmark TL --- app/css/tl.css | 1 + app/js/post/status.js | 10 +- app/js/tl/parse.js | 9 +- app/js/tl/tl.js | 81 +++++++++-- app/js/ui/layout.js | 181 ++++++++++++------------- app/view/make/index.sample.html | 3 + app/view/make/language/en/index.json | 1 + app/view/make/language/en/main.json | 1 + app/view/make/language/en/setting.json | 1 + app/view/make/language/ja/index.json | 1 + app/view/make/language/ja/main.json | 3 +- app/view/make/language/ja/setting.json | 1 + app/view/make/setting.sample.js | 11 ++ 13 files changed, 197 insertions(+), 107 deletions(-) diff --git a/app/css/tl.css b/app/css/tl.css index 736db6a4..b7841626 100644 --- a/app/css/tl.css +++ b/app/css/tl.css @@ -446,6 +446,7 @@ iframe, } .contextMenu .btn-flat { text-transform: none !important; + width: 100%; } .gray { diff --git a/app/js/post/status.js b/app/js/post/status.js index fb63d9fb..fa0b45ab 100644 --- a/app/js/post/status.js +++ b/app/js/post/status.js @@ -116,7 +116,7 @@ function boostWith(vis) { rt(id, acct_id, false, vis) } //ブックマーク -function bkm(id, acct_id, remote) { +function bkm(id, acct_id, tlid) { if ($('#pub_' + id).hasClass('bkmed')) { var flag = 'unbookmark' } else { @@ -140,8 +140,7 @@ function bkm(id, acct_id, remote) { if (json.reblog) { json = json.reblog } - if (remote != 'remote') { - var fav = json.favourites_count + var fav = json.favourites_count $('[toot-id=' + id + '] .fav_ct').text(fav) $('[toot-id=' + id + '] .rt_ct').text(json.reblogs_count) if (flag == 'unbookmark') { @@ -153,9 +152,8 @@ function bkm(id, acct_id, remote) { $('.bkm_' + id).addClass('red-text') $('[toot-id=' + id + ']').addClass('bkmed') } - } else { - M.toast({ html: lang.lang_status_favWarn, displayLength: 1000 }) - } + var tlidTar = $(`.bookmark-timeline[data-acct=${acct_id}]`).attr('tlid') + columnReload(tlidTar,'bookmark') } } } diff --git a/app/js/tl/parse.js b/app/js/tl/parse.js index f5932ac1..35b06b5e 100644 --- a/app/js/tl/parse.js +++ b/app/js/tl/parse.js @@ -948,7 +948,7 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type) { ` } //menuは何個? - var menuct = 1 + var menuct = 2 if (viashow != 'hide') { menuct++ } @@ -1106,6 +1106,13 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type) { ${trans} +
+ + + ${lang.lang_parse_link} + +
` diff --git a/app/js/tl/tl.js b/app/js/tl/tl.js index 642c5530..563ef182 100644 --- a/app/js/tl/tl.js +++ b/app/js/tl/tl.js @@ -56,14 +56,15 @@ function tl(type, data, acct_id, tlid, delc, voice, mode) { ) $('#notice_icon_' + tlid).text('notifications') return - } /*else if (type == "dm") { - //DMなら飛ばす - dm(acct_id, tlid, "plus",delc,voice); - $("#notice_" + tlid).text(cap(type, data, acct_id) + "(" + localStorage.getItem( - "user_" + acct_id) + "@" + domain + ")"); - $("#notice_icon_" + tlid).text("mail_outline"); - return; - }*/ + } else if (type == 'bookmark') { + //ブックマークなら飛ばす + getBookmark(acct_id, tlid) + $('#notice_' + tlid).text( + cap(type, data, acct_id) + '(' + localStorage.getItem('user_' + acct_id) + '@' + domain + ')' + ) + $('#notice_icon_' + tlid).text('bookmark') + return + } localStorage.setItem('now', type) todo(cap(type) + ' TL Loading...') var at = localStorage.getItem('acct_' + acct_id + '_at') @@ -387,6 +388,9 @@ function moreload(type, tlid) { var data = obj[tlid].data moreTs(tlid, data) return + } else if (type == 'bookmark') { + getBookmark(acct_id, tlid, true) + return } moreloading = true localStorage.setItem('now', type) @@ -708,6 +712,8 @@ function cap(type, data, acct_id) { var response = 'Twitter' } else if (type == 'tootsearch') { var response = 'tootsearch(' + escapeHTML(data) + ')' + } else if (type == 'bookmark') { + var response = 'Bookmarks' } return response } @@ -730,6 +736,8 @@ function com(type, data) { return 'list/' + data + '?' } else if (type == 'dm') { return 'direct?' + } else if (type == 'bookmark') { + return 'bookmarks?' } } //Misskey @@ -800,6 +808,8 @@ function icon(type) { var response = 'language' } else if (type == 'tootsearch') { var response = 'search' + } else if (type == 'bookmark') { + var response = 'bookmark' } return response } @@ -835,6 +845,9 @@ function reconnector(tlid, type, acct_id, data, mode) { function columnReload(tlid, type) { $('#notice_icon_' + tlid).addClass('red-text') $('#unread_' + tlid + ' .material-icons').removeClass('teal-text') + var multi = localStorage.getItem('column') + var obj = JSON.parse(multi) + var acct_id = obj[tlid].domain if (type == 'mix' || type == 'integrated' || type == 'plus') { if (localStorage.getItem('voice_' + tlid)) { var voice = true @@ -850,6 +863,9 @@ function columnReload(tlid, type) { } else if (type == 'notf') { $('#notice_icon_' + tlid).removeClass('red-text') notfColumn(acct_id, tlid, '') + } else if (type == 'bookmark') { + $('#notice_icon_' + tlid).removeClass('red-text') + getBookmark(acct_id, tlid, false) } else { var wss = localStorage.getItem('wss_' + tlid) websocket[wss].close() @@ -1102,3 +1118,52 @@ function asReadEnd() { postMessage(['asReadComp', ''], '*') } } +//ブックマーク +function getBookmark(acct_id, tlid, more) { + moreloading = true + console.log(acct_id, tlid, more) + if (more) { + var sid = $('#timeline_' + tlid + ' .notif-marker') + .last() + .attr('data-maxid') + var ad = '?max_id=' + sid + } else { + var ad = '' + } + var at = localStorage.getItem('acct_' + acct_id + '_at') + var domain = localStorage.getItem('domain_' + acct_id) + var start = 'https://' + domain + '/api/v1/bookmarks' + ad + var httpreq = new XMLHttpRequest() + httpreq.open('GET', 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) + } + var max_ids = httpreq.getResponseHeader('link') + var max_id = 0 + if (max_ids) { + max_ids = max_ids.match(/[?&]{1}max_id=([0-9]+)/) + if (max_ids) { + max_id = max_ids[1] + } + } + var templete = parse(json, 'bookmark', acct_id, tlid, -1, null) + templete = templete + '
' + if (more) { + $('#timeline_' + tlid).append(templete) + } else { + $('#timeline_' + tlid).html(templete) + } + $('#landing_' + tlid).hide() + jQuery('time.timeago').timeago() + moreloading = false + todc() + } + } +} diff --git a/app/js/ui/layout.js b/app/js/ui/layout.js index 0bab310f..4af4020d 100644 --- a/app/js/ui/layout.js +++ b/app/js/ui/layout.js @@ -202,7 +202,29 @@ function parseColumn(target, dontclose) { animecss, acct.data ) - } else { + } else if (acct.type == 'bookmark') { + if (!acct.left_fold) { + basekey = key + } + + var anime = localStorage.getItem('animation') + if (anime == 'yes' || !anime) { + var animecss = 'box-anime' + } else { + var animecss = '' + } + unstreamingTL( + acct.type, + key, + basekey, + insert, + icnsert, + acct.left_fold, + css, + animecss, + acct.domain + ) + }else { var anime = localStorage.getItem('animation') if (anime == 'yes' || !anime) { var animecss = 'box-anime' @@ -728,105 +750,73 @@ function webviewParse(url, key, insert, icnsert, css) { ` return html } -function unstreamingTL(type, key, basekey, insert, icnsert, left_fold, css, animecss, q) { +function unstreamingTL(type, key, basekey, insert, icnsert, left_fold, css, animecss, data) { + //type名が関数名 if (!left_fold) { var basehtml = - '
' + `
` $('#timeline-container').append(basehtml) var left_hold = - 'view_agenda' + - lang.lang_layout_leftFold + - '
' + ` + view_agenda + + ${lang.lang_layout_leftFold} +
` } else { var left_hold = - 'view_column' + - lang.lang_layout_leftUnfold + - '
' + ` + view_column + + ${lang.lang_layout_leftUnfold} +
` } var html = - '
' + - '
' + - left_hold + - 'perm_mediaOn' + - lang.lang_layout_mediafil + - '
' + - lang.lang_layout_headercolor + - '
' + - lang.lang_layout_nodata + - '
' + `
+ +
+ ${left_hold} + + perm_media + On + + ${lang.lang_layout_mediafil}
+ ${lang.lang_layout_headercolor}
+
+
+
+
+
+ ${lang.lang_layout_nodata} +
+
+
` $('#timeline_box_' + basekey + '_parentBox').append(html) - tootsearch(key, q) + if(type == 'tootsearch'){ + tootsearch(key, data) + }else if(type == 'bookmark'){ + console.log(key, data) + bookmark(key, data) + } cardCheck(key) ebtCheck(key) mediaCheck(key) @@ -834,6 +824,15 @@ function unstreamingTL(type, key, basekey, insert, icnsert, left_fold, css, anim voiceCheck(key) return true } +function bookmark(key, data){ + console.log(key, data) + if (localStorage.getItem('voice_' + key)) { + var voice = true + } else { + var voice = false + } + tl('bookmark', '', data, key, 'false', voice, '') +} function leftFoldSet(key) { var multi = localStorage.getItem('column') var obj = JSON.parse(multi) diff --git a/app/view/make/index.sample.html b/app/view/make/index.sample.html index 32efb400..ab7cd920 100644 --- a/app/view/make/index.sample.html +++ b/app/view/make/index.sample.html @@ -927,6 +927,9 @@
notifications
@@notf@@
+
+
bookmark
@@bookmark@@ +
@@showThisTL@@ diff --git a/app/view/make/language/en/index.json b/app/view/make/language/en/index.json index c8de0b93..bad568d1 100644 --- a/app/view/make/language/en/index.json +++ b/app/view/make/language/en/index.json @@ -125,6 +125,7 @@ "integratedTLDes":"Integrated(Local/Home)", "localPlusDes":"LTL+Reply+BT", "notf":"Notifications", + "bookmark": "Bookmarks", "showThisTL":"Show this TL:", "webviewWarn":"TweetDeck with customed TJDeck(Code/TJDeck). Keyboard shortcuts will irritate you. When you feel so, you check 'Prefer WebView' on top of the column.", "add":"Add", diff --git a/app/view/make/language/en/main.json b/app/view/make/language/en/main.json index 0797e569..8d8fd49a 100644 --- a/app/view/make/language/en/main.json +++ b/app/view/make/language/en/main.json @@ -187,6 +187,7 @@ "lang_parse_del": "Delete this", "lang_parse_pin": "Pin this", "lang_parse_unpin": "Unpin this", + "lang_parse_link": "Open in a browser", "lang_parse_det": "Details via your main account.", "lang_parse_redraft": "Delete & re-draft", "lang_parse_followed": "Followed you", diff --git a/app/view/make/language/en/setting.json b/app/view/make/language/en/setting.json index 786f1f3d..96012548 100644 --- a/app/view/make/language/en/setting.json +++ b/app/view/make/language/en/setting.json @@ -127,6 +127,7 @@ "full": "URL, text and acct(mention to the user)", "notqt": "Disabled(Hide buttons on TLs)", "apiQuote": "API(only some instances)", + "showBookmarkAction": "Show a bookmarking toot button", "main": "Default accounts of actions", "mainwarn": "Main account can be set on Account Manager.", "lastacct": "Account you used recently", diff --git a/app/view/make/language/ja/index.json b/app/view/make/language/ja/index.json index c7c1d8c1..222e07a4 100644 --- a/app/view/make/language/ja/index.json +++ b/app/view/make/language/ja/index.json @@ -125,6 +125,7 @@ "integratedTLDes":"統合(ローカルとホーム)", "localPlusDes":"統合(LTL+BT+返信)", "notf":"通知", + "bookmark": "ブックマーク", "showThisTL":"表示するタイムライン", "webviewWarn":"TweetDeckを表示します。TJDeckをカスタムしたものが読み込まれます(Code/TJDeck)。キーボードショートカットが邪魔をするので、文字入力時はカラムの「WebView優先」にチェックを入れてください。", "add":"追加", diff --git a/app/view/make/language/ja/main.json b/app/view/make/language/ja/main.json index f22ba389..88ebcbdf 100644 --- a/app/view/make/language/ja/main.json +++ b/app/view/make/language/ja/main.json @@ -187,8 +187,9 @@ "lang_parse_del": "削除", "lang_parse_pin": "ピン留めする", "lang_parse_unpin": "ピン留めを解除する", + "lang_parse_link": "ブラウザで開く", "lang_parse_det": "詳細(メインアカウント経由)", - "lang_parse_redraft": "このトゥートを削除して再編集", + "lang_parse_redraft": "削除して再編集", "lang_parse_followed": "フォローされました。", "lang_parse_clientop": "クライアント操作", "lang_parse_clienttxt": " に対する処理を選択してください。", diff --git a/app/view/make/language/ja/setting.json b/app/view/make/language/ja/setting.json index f63183f4..e6b3a9f6 100644 --- a/app/view/make/language/ja/setting.json +++ b/app/view/make/language/ja/setting.json @@ -127,6 +127,7 @@ "full": "本文・URL・アカウント名", "notqt": "使わない(TL上にボタンも表示されません)", "apiQuote": "パラメーター(対応インスタンス)", + "showBookmarkAction": "アクションボタンとしてブックマークを表示する", "main": "投稿後や起動時のアカウント", "mainwarn": "メインアカウントはアカウント設定で指定できます。投稿以外のアカウント選択にも影響します。", "lastacct": "最後に使用したアカウント", diff --git a/app/view/make/setting.sample.js b/app/view/make/setting.sample.js index 64f56f25..13984b2c 100644 --- a/app/view/make/setting.sample.js +++ b/app/view/make/setting.sample.js @@ -371,6 +371,17 @@ var tlConstruction = [ checkbox: yesno } }, + { + id: 'bkm', + storage: 'bookmark', + checkbox: true, + setValue: 'no', + text: { + head: '@@showBookmarkAction@@', + desc: '', + checkbox: yesno + } + }, { id: 'replySound', storage: 'replySound',