console.tweet({
screen_name: "3846masa",
user_id: "3846masa",
tweet_text: "consoleでTwitterとかウケる",
thumbnail_url: "https://twitter.com/3846masa/profile_image?size=bigger",
tweet_url: "https://twitter.com/3846masa/status/618075724637822976"
});
Last active
September 8, 2016 13:21
-
-
Save 3846masa/60c5bcb499d4cf56b717 to your computer and use it in GitHub Desktop.
なんか産まれたのであげとく.
This file contains 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
console.tweet = function(tweet) { | |
if (typeof tweet !== "object") return; | |
var keys = ["screen_name", "user_id", "tweet_text", "thumbnail_url", "tweet_url"]; | |
var isValid = true; | |
keys.forEach(function(key){ | |
isValid &= tweet.hasOwnProperty(key); | |
}); | |
if (!isValid) return; | |
tweet.tweet_id = tweet.tweet_url.split('/').reverse()[0]; | |
var thumbnail_css = | |
"padding:10px 0 15px 45px;" + | |
"line-height:30px;" + | |
"background:" + | |
"linear-gradient(to top, transparent, transparent)," + | |
"url('"+ tweet.thumbnail_url +"');" + | |
"background-size:40px 40px;" + | |
"background-repeat:no-repeat;"; | |
tweet.tweet_text = tweet.tweet_text.replace(/pic\.twitter\.com\/\w*/g, ''); | |
tweet.tweet_imgs = tweet.tweet_imgs || []; | |
tweet.tweet_imgs.forEach(function(url, i){ | |
var css = | |
"padding:10px 0 20px 1000px;" + | |
"line-height:40px;" + | |
"background:" + | |
"linear-gradient(to top, transparent, transparent)," + | |
"url('"+ url +"');" + | |
"background-size:40px;" + | |
"background-repeat:no-repeat;"; | |
tweet.tweet_imgs[i] = css; | |
}); | |
var query = "%c %c%s %c@%s\n%c \n%c%s\n"; | |
for (var _i = 0; _i < tweet.tweet_imgs.length; _i++) { | |
query += "%c %c\n"; | |
} | |
query += "\nURL:%o\n%c★Fav. %s"; | |
var args_array = [].concat([ | |
query, | |
thumbnail_css, | |
"color:black; line-height:30px;", | |
tweet.screen_name, | |
"color:gray; line-height:30px;", | |
tweet.user_id, | |
"line-height:15px;", | |
"", | |
tweet.tweet_text, | |
]); | |
tweet.tweet_imgs.forEach(function(css){ | |
args_array.push(css); | |
args_array.push(""); | |
}); | |
args_array = args_array.concat([ | |
tweet.tweet_url, | |
"background-color:yellow; line-height:1.5em;", | |
"https://twitter.com/intent/favorite?tweet_id=" + tweet.tweet_id, | |
]); | |
console.log.apply(console, args_array); | |
}; |
This file contains 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
// 公式Twitterで上のconsole.tweetと一緒に実行すると,consoleに流れる. | |
function showTweetInConsole() { | |
var $tweet_list = $($('.js-stream-item').get().reverse()); | |
$tweet_list.each(function(){ | |
if ($(this).data('consoled') === $('.js-original-tweet', this).length) return; | |
if ($('.js-original-tweet', this).length > 1) { | |
console.group(); | |
$('.js-original-tweet', this).each(function(){ | |
showTweetInConsoleFromElem($(this)); | |
}); | |
console.groupEnd(); | |
} else { | |
showTweetInConsoleFromElem($('.js-original-tweet', this)); | |
} | |
$(this).attr('data-consoled', $('.js-original-tweet', this).length); | |
}); | |
} | |
function showTweetInConsoleFromElem($tweet_elem) { | |
var tweet = {}; | |
tweet.user_id = $('.username > b', $tweet_elem).text(); | |
tweet.screen_name = $('.fullname', $tweet_elem).text(); | |
tweet.tweet_text = $('.tweet-text', $tweet_elem).text(); | |
tweet.thumbnail_url = $('.avatar', $tweet_elem).attr('src'); | |
tweet.tweet_url = location.origin + $('.tweet-timestamp', $tweet_elem).attr('href'); | |
if ($('.js-media-container', $tweet_elem).length > 0) { | |
tweet.tweet_imgs = []; | |
var $imgs = $('.js-media-container img', $tweet_elem); | |
$imgs.each(function(){ | |
tweet.tweet_imgs.push($(this).attr('src')); | |
}); | |
} | |
console.tweet(tweet); | |
} | |
showTweetInConsole(); | |
setTimeout(function watchNewTweet(){ | |
if ($('.new-tweets-bar').data('item-count') > 0) { | |
$('.new-tweets-bar').click(); | |
setTimeout(showTweetInConsole, 1000); | |
} | |
setTimeout(watchNewTweet, 500); | |
}, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment