1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-28 09:15:46 +02:00

Rewrite screenshot rendering to fix current and future visual issues

This commit is contained in:
chylex 2018-04-03 02:05:22 +02:00
parent 217535a3ba
commit ffd0f5e986

View File

@ -660,85 +660,65 @@
// Block: Screenshot tweet to clipboard. // Block: Screenshot tweet to clipboard.
// //
(function(){ (function(){
var selectedTweet;
const setImportantProperty = function(obj, property, value){
if (obj.length === 1){
obj[0].style.setProperty(property, value, "important");
}
};
app.delegate("article.js-stream-item", "contextmenu", function(){
selectedTweet = $(this);
});
window.TDGF_triggerScreenshot = function(){ window.TDGF_triggerScreenshot = function(){
if (selectedTweet){ return if !highlightedTweetObj || !highlightedColumnObj;
let tweetWidth = Math.floor(selectedTweet.width());
let parent = selectedTweet.parent();
let isDetail = parent.hasClass("js-tweet-detail"); let chirp = highlightedColumnObj.findChirp(highlightedTweetEle.attr("data-key")) || highlightedTweetObj;
let isReply = !isDetail && (parent.hasClass("js-replies-to") || parent.hasClass("js-replies-before"));
selectedTweet = selectedTweet.clone(); let columnWidth = highlightedColumnEle.width();
let container = selectedTweet.children().first(); let html = $(chirp.render({
container.addClass($(document.documentElement).attr("class")); withFooter: false,
container.addClass($(document.body).attr("class")); withTweetActions: false,
container.css("padding-bottom", "0"); isInConvo: false,
isFavorite: false,
isRetweeted: false, // keeps retweet mark above tweet
isPossiblySensitive: false,
mediaPreviewSize: highlightedColumnObj.getMediaPreviewSize()
}));
setImportantProperty(selectedTweet.find(".js-tweet-text"), "margin-bottom", "8px"); html.find("footer").last().remove(); // apparently withTweetActions breaks for certain tweets, nice
setImportantProperty(selectedTweet.find(".js-quote-detail"), "margin-bottom", "10px"); html.find(".td-screenshot-remove").remove();
setImportantProperty(selectedTweet.find(".js-poll-link").next(), "margin-bottom", "8px");
if (isDetail){ html.find("p.link-complex-target").filter(function(){
if (selectedTweet.find("[class*='media-grid-']").length > 0){
setImportantProperty(selectedTweet.find(".js-tweet-media"), "margin-bottom", "10px");
}
else{
setImportantProperty(selectedTweet.find(".js-tweet-media"), "margin-bottom", "6px");
}
setImportantProperty(selectedTweet.find(".js-media-preview-container"), "margin-bottom", "4px");
selectedTweet.find(".js-translate-call-to-action").first().remove();
selectedTweet.find(".js-tweet").first().nextAll().remove();
selectedTweet.find("footer").last().prevUntil(":not(.txt-mute)").addBack().remove(); // footer, date, location
}
else{
setImportantProperty(selectedTweet.find(".js-media-preview-container").filter(function(){
return $(this).closest(".js-quote-detail").length === 0;
}), "margin-bottom", "10px");
selectedTweet.find("footer").last().remove();
}
if (isReply){
selectedTweet.find(".is-conversation").removeClass("is-conversation");
selectedTweet.find(".thread").remove();
}
selectedTweet.find("p.link-complex-target").filter(function(){
return $(this).text() === "Show this thread"; return $(this).text() === "Show this thread";
}).first().remove(); }).first().remove();
selectedTweet.find(".js-poll-link").remove(); html.addClass($(document.documentElement).attr("class"));
selectedTweet.find(".td-screenshot-remove").remove(); html.addClass($(document.body).attr("class"));
let testTweet = selectedTweet.clone().css({ html.css("background-color", getClassStyleProperty("column", "background-color"));
html.css("border", "none");
for(let selector of [ ".js-quote-detail", ".js-media-preview-container", ".js-media" ]){
let ele = html.find(selector);
if (ele.length){
ele[0].style.setProperty("margin-bottom", "2px", "important");
break;
}
}
let type = chirp.getChirpType();
if ((type.startsWith("favorite") || type.startsWith("retweet")) && chirp.isAboutYou()){
html.addClass("td-notification-padded");
}
let testTweet = html.clone().css({
position: "absolute", position: "absolute",
left: "-999px", left: "-999px",
width: tweetWidth+"px" width: columnWidth+"px"
}).appendTo(document.body); }).appendTo(document.body);
let testTweetAvatar = testTweet.find(".tweet-avatar").first(); let testTweetAvatar = testTweet.find(".tweet-avatar").first();
let avatarBottom = testTweetAvatar.offset().top+testTweetAvatar.height(); let avatarBottom = testTweetAvatar.length === 1 ? testTweetAvatar.offset().top+testTweetAvatar.height() : 0;
let realHeight = Math.floor(Math.max(testTweet.height(), avatarBottom+10)); let realHeight = Math.floor(Math.max(testTweet.height(), avatarBottom+9));
testTweet.remove(); testTweet.remove();
selectedTweet.find(".js-stream-item-content").first().css("height", "100vh"); html.find(".js-stream-item-content").first().css("height", "100vh");
$TD.screenshotTweet(selectedTweet.html(), tweetWidth, realHeight); $TD.screenshotTweet(html[0].outerHTML, columnWidth, realHeight);
}
}; };
})(); })();