diff options
Diffstat (limited to 'twittperator/twsidebar.tw')
-rw-r--r--[-rwxr-xr-x] | twittperator/twsidebar.tw | 69 |
1 files changed, 62 insertions, 7 deletions
diff --git a/twittperator/twsidebar.tw b/twittperator/twsidebar.tw index 0961c00..a9cc9ce 100755..100644 --- a/twittperator/twsidebar.tw +++ b/twittperator/twsidebar.tw @@ -38,6 +38,12 @@ liberator.modules.TWAnekoSB = ANekoSB = (function () { // リストの最大保持数 listMax: 100, + // リストの表示順(昇順/降順) + listAscendingOrder: true, + + // ツイートされる度に最新ツイート位置までスクロールする + listAutoScroll: true, + // 日本語だけ for filter stream jpOnly: true, @@ -48,7 +54,13 @@ liberator.modules.TWAnekoSB = ANekoSB = (function () { dontStop: true, // サイドバーが閉じていても、こっそり開始しておく - silentStart: false + silentStart: false, + + // 配列かオブジェクトを返すと、変更できる。 + // 文字列 "reject" を返すと、そもそもツイートが表示されなくなる。 + modifier: function (msg, tab, streamName) { + return [msg, tab, streamName]; + } }; // 日本語判定 @@ -158,6 +170,17 @@ liberator.modules.TWAnekoSB = ANekoSB = (function () { function append (t, tab, streamName) { tab = tab || 'home'; + let modified = Config.modifier && Config.modifier(t, tab, streamName); + if (modified) { + if (modified instanceof Array) { + [t, tab, streamName] = modified; + } if (modified === 'reject') { + return; + } else { + t = modified; + } + } + let now = JSON.stringify({name: t.name, text: t.text, tab: tab}); if (latest === now) { if (latestNode) @@ -172,13 +195,47 @@ liberator.modules.TWAnekoSB = ANekoSB = (function () { let cntr = getSidebarWindow().document.getElementById('tw-anekos-sb-' + tab + '-list'); let dom = xmlToDom(messageToXML(t)); let repDom = dom.cloneNode(true); + let visibleIndex = cntr.getIndexOfFirstVisibleRow(); let len = cntr.itemCount; - cntr.appendChild(repDom); + if (Config.listAscendingOrder) { + cntr.appendChild(repDom); + } else { + cntr.insertBefore(repDom, cntr.firstChild); + visibleIndex += 1; + } latestNode = repDom; - cntr.scrollToIndex(len - 1); - if (len > Config.listMax) - cntr.removeChild(cntr.firstChild); + if (len > Config.listMax) { + if (Config.listAscendingOrder) { + cntr.removeChild(cntr.firstChild); + visibleIndex -= 1; + } else { + cntr.removeChild(cntr.lastChild); + } + len -= 1; + } + + if (Config.listAutoScroll) { + if (Config.listAscendingOrder) { + cntr.scrollToIndex(len - 1); + } else { + cntr.scrollToIndex(0); + } + } else { + if (Config.listAscendingOrder) { + if (len - visibleIndex < 10) { // 10 = 絶妙な値!これでいいのか! + cntr.scrollToIndex(len - 1); + } else { + cntr.scrollToIndex(visibleIndex); + } + } else { + if (visibleIndex < 3) { // 3 = 絶妙な値!これでいいのか! + cntr.scrollToIndex(0); + } else { + cntr.scrollToIndex(visibleIndex); + } + } + } } return append; @@ -237,8 +294,6 @@ liberator.modules.TWAnekoSB = ANekoSB = (function () { type: 'favorite' }; appendTweet(t, 'home', streamName); - appendTweet(t, 'debug', streamName); - Config.sound.debug.play(); } } catch (e) { liberator.log(e); |