Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tweetdeckで片思い"⇦"、片思われ"⇨'"、相互フォロー"☺"を名前の先頭に表示するUserScript
// ==UserScript==
// @name Tweetdeck MARKING Friends and Followers
// @include https://tweetdeck.twitter.com/*
// @version 1.1
// @license MIT License
// ==/UserScript==
(function(w) {
var TD = w.TD;
TD.services.TwitterClient.prototype.followers = null;
TD.services.TwitterClient.prototype.getFollowersIDs = function(cursor) {
if (!cursor) this.followers = {};
this.makeTwitterCall(
'https://api.twitter.com/1.1/followers/ids.json',
{
user_id : this.oauth.account.getUserID(),
cursor : cursor ? cursor : -1,
stringify_ids : true
},
'GET',
function(response) {
for (var i = 0; i < response.ids.length; i++) {
this.followers[response.ids[i]] = true;
}
if (response.next_cursor_str !== '0') {
this.getFollowersIDs(response.next_cursor_str);
}
},
function(){},
function(){}
);
};
TD.services.TwitterClient.prototype.getFriendMark = function(following, followed_by, userId){
var isFriend = following || this.friends[userId];
var isFollower = followed_by || this.followers[userId];
if (isFollower) {
if (isFriend) {
return '🙂 ';
} else {
return '⇨ ';
}
} else {
if (isFriend) {
return '⇦ ';
} else {
return '';
}
}
};
TD.services.TwitterClient.prototype.addFriendMark = function(following, followed_by, userId, name) {
var mark = this.getFriendMark(following, followed_by, userId);
if (mark !== '' && name.indexOf(mark) !== 0) {
name = mark + name;
}
return name;
};
TD.services.TwitterClient.prototype.loadCaches_prev = TD.services.TwitterClient.prototype.loadCaches;
TD.services.TwitterClient.prototype.loadCaches = function() {
this.getFollowersIDs();
this.loadCaches_prev();
};
TD.services.TwitterClient.prototype.processTweet_prev = TD.services.TwitterClient.prototype.processTweet;
TD.services.TwitterClient.prototype.processTweet = function(e){
e.user.name = this.addFriendMark(e.user.following, e.user.followed_by, e.user.id, e.user.name);
var tweet = this.processTweet_prev(e);
if (tweet.retweetedStatus) {
var reTweetUser = tweet.retweetedStatus.user;
reTweetUser.name = this.addFriendMark(reTweetUser.following, reTweetUser.followed_by, reTweetUser.id, reTweetUser.name);
}
return tweet;
};
TD.services.TwitterClient.prototype.processMessages_prev = TD.services.TwitterClient.prototype.processMessages;
TD.services.TwitterClient.prototype.processMessages = function(e, t) {
for (var i = 0; i < e.length; i++) {
var sender = e[i].sender;
sender.name = this.addFriendMark(sender.following, sender.followed_by, sender.id, sender.name);
}
return this.processMessages_prev(e, t);
};
TD.services.TwitterClient.prototype.processActions_prev = TD.services.TwitterClient.prototype.processActions;
TD.services.TwitterClient.prototype.processActions = function(e) {
for (var i = 0; i < e.length; i++) {
var n = e[i];
if (n.sources_size > 0 ) {
var src = n.sources[0];
src.name = this.addFriendMark(src.following, src.followed_by, src.id, src.name);
}
if (n.targets_size > 0 ) {
var tgt = n.targets[0];
if (tgt.name) {
tgt.name = this.addFriendMark(tgt.following, tgt.followed_by, tgt.id, tgt.name);
}
if (tgt.user) {
tgt.user.name = this.addFriendMark(tgt.user.following, tgt.user.followed_by, tgt.user.id, tgt.user.name);
}
}
}
return this.processActions_prev(e);
};
TD.services.TwitterClient.prototype.processUser_prev = TD.services.TwitterClient.prototype.processUser;
TD.services.TwitterClient.prototype.processUser = function(e) {
e.name = this.addFriendMark(e.following, e.followed_by, e.id, e.name);
return this.processUser_prev(e);
};
TD.services.TwitterAction.processStreamAction_prev = TD.services.TwitterAction.processStreamAction;
TD.services.TwitterAction.processStreamAction = function(e, t) {
var client = TD.controller.clients.getClient(t.getKey());
var src = e.source;
var tgt = e.target;
src.name = client.addFriendMark(src.following, src.followed_by, src.id, src.name);
tgt.name = client.addFriendMark(tgt.following, tgt.followed_by, tgt.id, tgt.name);
if (e.target_object) {
var tgtobj = e.target_object.user;
tgtobj.name = client.addFriendMark(tgtobj.following, tgtobj.followed_by, tgtobj.id, tgtobj.name);
}
return TD.services.TwitterAction.processStreamAction_prev(e, t);
};
})(unsafeWindow);
@nirvash

This comment has been minimized.

Copy link
Owner Author

nirvash commented Aug 24, 2017

Timeline に対してアイコンをつける処理がなかったので追加

@nirvash

This comment has been minimized.

Copy link
Owner Author

nirvash commented Aug 28, 2017

会話リストなどでアイコンが多重に付与されていたのでその対策

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.