TweetDeckのツイートにクライアント名を表示するUserScript。
TweetDeckが保持しているデータを参照しているのでAPIは叩いていません。
Chrome拡張のTampermonkeyで動作確認済み。
とりあえず動くレベルなので無駄な処理が多いです。気になった場合は適当に弄ってください。
Last active
September 12, 2020 18:20
-
-
Save Getaji/5686c6564f35c812b616052922bb4414 to your computer and use it in GitHub Desktop.
TweetDeckのツイートにクライアント名を表示するUserScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name TweetDeckCustomize | |
| // @namespace https://twitter.com/Getaji | |
| // @version 0.1 | |
| // @description TweetDeckのツイートにクライアント名を表示したりする | |
| // @author Getaji | |
| // @match https://tweetdeck.twitter.com/ | |
| // @grant none | |
| // ==/UserScript== | |
| $(document).one('dataColumnsLoaded', () => { | |
| /* jshint esnext:true */ | |
| 'use strict'; | |
| const MutationObserver = window.WebKitMutationObserver || window.MozMutationObserver || window.MutationObserver; | |
| function getColumn(columnElement) { | |
| const columnID = columnElement.getAttribute('data-column'); | |
| return TD.controller.columnManager.getAll()[columnID]; | |
| } | |
| function getStatus(columnElement, statusID) { | |
| const column = getColumn(columnElement); | |
| if (column === undefined) throw 'Column not found: ' + columnID; | |
| const status = column.updateIndex[statusID]; | |
| if (status === undefined) throw 'Status not found: ' + statusID; | |
| if (status instanceof TD.services.TwitterActionMention || | |
| status instanceof TD.services.TwitterActionRetweet || | |
| status instanceof TD.services.TwitterActionFavorite) return status.targetTweet; | |
| return status; | |
| } | |
| function onTweet(tweet, column) { | |
| // クライアント名を表示する | |
| const status = getStatus(column, tweet.getAttribute('data-key')); | |
| if (status === undefined) return; | |
| if (status.sourceUrl === undefined) return; | |
| const jsTweet = $('.js-tweet', tweet); | |
| const viaHTML = `<div class="js-tweet-client tweet-client"><a href="${status.sourceUrl}" rel="url" target="_blank">via ${status.sourceNoHTML}</a></div>`; | |
| jsTweet.append(viaHTML); | |
| } | |
| // カラムの子要素の変更を検知して追加された要素をonTweetに渡す | |
| const moColumn = new MutationObserver((mutations) => { | |
| mutations.forEach(mutation => { | |
| mutation.addedNodes.forEach(node => onTweet(node, mutation.target)); | |
| }); | |
| }); | |
| $('.js-chirp-container').each((i, el) => { | |
| moColumn.observe(el, { childList: true }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment