1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-05 02:34:07 +02:00

Harness the incredible power of return-if statements

This commit is contained in:
chylex 2017-08-22 10:10:46 +02:00
parent d24b7bbcb9
commit 1293a2a533

View File

@ -112,9 +112,7 @@
}; };
let checkTweetCache = (set, id) => { let checkTweetCache = (set, id) => {
if (set.has(id)){ return true if set.has(id);
return true;
}
if (set.size > 50){ if (set.size > 50){
set.clear(); set.clear();
@ -130,12 +128,10 @@
return function(column, tweet){ return function(column, tweet){
if (tweet instanceof TD.services.TwitterConversation || tweet instanceof TD.services.TwitterConversationMessageEvent){ if (tweet instanceof TD.services.TwitterConversation || tweet instanceof TD.services.TwitterConversationMessageEvent){
if (checkTweetCache(recentMessages, tweet.id)){ return if checkTweetCache(recentMessages, tweet.id);
return;
}
} }
else if (checkTweetCache(recentTweets, tweet.id)){ else{
return; return if checkTweetCache(recentTweets, tweet.id);
} }
startRecentTweetTimer(); startRecentTweetTimer();
@ -430,26 +426,22 @@
app.delegate("article.js-stream-item", "mouseenter mouseleave", function(e){ app.delegate("article.js-stream-item", "mouseenter mouseleave", function(e){
if (e.type === "mouseenter"){ if (e.type === "mouseenter"){
let me = $(this); let me = $(this);
return if !me[0].hasAttribute("data-account-key") || (!highlightedColumnObj && !updateHighlightedColumn(me.closest("section.js-column")));
if (!me[0].hasAttribute("data-account-key") || (!highlightedColumnObj && !updateHighlightedColumn(me.closest("section.js-column")))){
return;
}
let tweet = highlightedColumnObj.findChirp(me.attr("data-tweet-id")) || highlightedColumnObj.findChirp(me.attr("data-key")); let tweet = highlightedColumnObj.findChirp(me.attr("data-tweet-id")) || highlightedColumnObj.findChirp(me.attr("data-key"));
return if !tweet;
if (tweet){ if (tweet.chirpType === TD.services.ChirpBase.TWEET){
if (tweet.chirpType === TD.services.ChirpBase.TWEET){ let link = tweet.getChirpURL();
let link = tweet.getChirpURL(); let embedded = tweet.quotedTweet ? tweet.quotedTweet.getChirpURL() : "";
let embedded = tweet.quotedTweet ? tweet.quotedTweet.getChirpURL() : ""; let username = tweet.getMainUser().screenName;
let username = tweet.getMainUser().screenName; let images = tweet.hasImage() ? tweet.getMedia().filter(item => !item.isAnimatedGif).map(item => item.entity.media_url_https+":small").join(";") : "";
let images = tweet.hasImage() ? tweet.getMedia().filter(item => !item.isAnimatedGif).map(item => item.entity.media_url_https+":small").join(";") : ""; // TODO maybe handle embedded images too?
// TODO maybe handle embedded images too?
updateHighlightedTweet(me, tweet, link || "", embedded || "", username, images);
updateHighlightedTweet(me, tweet, link || "", embedded || "", username, images); }
} else{
else{ updateHighlightedTweet(me, tweet, "", "", "", "");
updateHighlightedTweet(me, tweet, "", "", "", "");
}
} }
} }
else if (e.type === "mouseleave"){ else if (e.type === "mouseleave"){
@ -938,6 +930,12 @@
}; };
window.TDGF_tryRunCleanup = function(){ window.TDGF_tryRunCleanup = function(){
// no modals are visible
return false if $("#open-modal").is(":visible") || !$(".js-modals-container").is(":empty");
// all columns are in a default state
return false if $("section.js-column").is(".is-shifted-1,.is-shifted-2");
// all textareas are empty // all textareas are empty
if ($("textarea").is(function(){ if ($("textarea").is(function(){
return $(this).val().length > 0; return $(this).val().length > 0;
@ -945,16 +943,6 @@
return false; return false;
} }
// no modals are visible
if ($("#open-modal").is(":visible") || !$(".js-modals-container").is(":empty")){
return false;
}
// all columns are in a default state
if ($("section.js-column").is(".is-shifted-1,.is-shifted-2")){
return false;
}
// all columns are scrolled to top // all columns are scrolled to top
if ($(".js-column-scroller").is(function(){ if ($(".js-column-scroller").is(function(){
return $(this).scrollTop() > 0; return $(this).scrollTop() > 0;