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

Refactor main JS code & split code.js into multiple files

This commit is contained in:
chylex 2020-06-06 09:01:50 +02:00
parent a834e8b6a2
commit 0c3d9ae46a
12 changed files with 1611 additions and 1563 deletions

View File

@ -7,6 +7,7 @@ namespace TweetDuck.Browser.Handling{
class ResourceRequestHandlerBrowser : ResourceRequestHandlerBase{
private const string UrlVendorResource = "/dist/vendor";
private const string UrlLoadingSpinner = "/backgrounds/spinner_blue";
private const string UrlVersionCheck = "/web/dist/version.json";
protected override CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback){
if (request.ResourceType == ResourceType.MainFrame){
@ -30,6 +31,12 @@ protected override CefReturnValue OnBeforeResourceLoad(IWebBrowser browserContro
request.SetHeaderByName("Accept-Encoding", "identity", overwrite: true);
}
}
else if (request.ResourceType == ResourceType.Xhr){
if (request.Url.Contains(UrlVersionCheck)){
callback.Dispose();
return CefReturnValue.Cancel;
}
}
return base.OnBeforeResourceLoad(browserControl, browser, frame, request, callback);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
<div id="tweetduck-conn-issues" class="Layer NotificationListLayer">
<ul class="NotificationList">
<li class="Notification Notification--red" style="height:63px;">
<div class="Notification-inner">
<div class="Notification-icon"><span class="Icon Icon--medium Icon--circleError"></span></div>
<div class="Notification-content"><div class="Notification-body">Experiencing connection issues</div></div>
<button type="button" class="Notification-closeButton" aria-label="Close"><span class="Icon Icon--smallest Icon--close" aria-hidden="true"></span></button>
</div>
</li>
</ul>
</div>

View File

@ -0,0 +1,667 @@
(function(){
//
// Function: Event callback for a new tweet.
//
const onNewTweet = (function(){
const recentMessages = new Set();
const recentTweets = new Set();
let recentTweetTimer = null;
const resetRecentTweets = () => {
recentTweetTimer = null;
recentTweets.clear();
};
const startRecentTweetTimer = () => {
recentTweetTimer && window.clearTimeout(recentTweetTimer);
recentTweetTimer = window.setTimeout(resetRecentTweets, 20000);
};
const checkTweetCache = (set, id) => {
return true if set.has(id);
if (set.size > 50){
set.clear();
}
set.add(id);
return false;
};
const isSensitive = (tweet) => {
const main = tweet.getMainTweet && tweet.getMainTweet();
return true if main && main.possiblySensitive; // TODO these don't show media badges when hiding sensitive media
const related = tweet.getRelatedTweet && tweet.getRelatedTweet();
return true if related && related.possiblySensitive;
const quoted = tweet.quotedTweet;
return true if quoted && quoted.possiblySensitive;
return false;
};
const fixMedia = (html, media) => {
return html.find("a[data-media-entity-id='" + media.mediaId + "'], .media-item").first().removeClass("is-zoomable").css("background-image", 'url("' + media.small() + '")');
};
return function(column, tweet){
if (tweet instanceof TD.services.TwitterConversation || tweet instanceof TD.services.TwitterConversationMessageEvent){
return if checkTweetCache(recentMessages, tweet.id);
}
else{
return if checkTweetCache(recentTweets, tweet.id);
}
startRecentTweetTimer();
if (column.model.getHasNotification()){
const sensitive = isSensitive(tweet);
const previews = $TDX.notificationMediaPreviews && (!sensitive || TD.settings.getDisplaySensitiveMedia());
// TODO new cards don't have either previews or links
const html = $(tweet.render({
withFooter: false,
withTweetActions: false,
withMediaPreview: true,
isMediaPreviewOff: !previews,
isMediaPreviewSmall: previews,
isMediaPreviewLarge: false,
isMediaPreviewCompact: false,
isMediaPreviewInQuoted: previews,
thumbSizeClass: "media-size-medium",
mediaPreviewSize: "medium"
}));
html.find("footer").last().remove(); // apparently withTweetActions breaks for certain tweets, nice
html.find(".js-quote-detail").removeClass("is-actionable margin-b--8"); // prevent quoted tweets from changing the cursor and reduce bottom margin
if (previews){
html.find(".reverse-image-search").remove();
const container = html.find(".js-media");
for(let media of tweet.getMedia()){
fixMedia(container, media);
}
if (tweet.quotedTweet){
for(let media of tweet.quotedTweet.getMedia()){
fixMedia(container, media).addClass("media-size-medium");
}
}
}
else if (tweet instanceof TD.services.TwitterActionOnTweet){
html.find(".js-media").remove();
}
html.find("a[data-full-url]").each(function(){ // bypass t.co on all links
this.href = this.getAttribute("data-full-url");
});
html.find("a[href='#']").each(function(){ // remove <a> tags around links that don't lead anywhere (such as account names the tweet replied to)
this.outerHTML = this.innerHTML;
});
html.find("p.link-complex-target").filter(function(){
return $(this).text() === "Show this thread";
}).first().each(function(){
this.id = "tduck-show-thread";
const moveBefore = html.find(".tweet-body > .js-media, .tweet-body > .js-media-preview-container, .quoted-tweet");
if (moveBefore){
$(this).css("margin-top", "5px").removeClass("margin-b--5").parent("span").detach().insertBefore(moveBefore);
}
});
if (tweet.quotedTweet){
html.find("p.txt-mute").filter(function(){
return $(this).text() === "Show this thread";
}).first().remove();
}
const type = tweet.getChirpType();
if (type === "follow"){
html.find(".js-user-actions-menu").parent().remove();
html.find(".account-bio").removeClass("padding-t--5").css("padding-top", "2px");
}
else if ((type.startsWith("favorite") || type.startsWith("retweet")) && tweet.isAboutYou()){
html.children().first().addClass("td-notification-padded");
}
else if (type.includes("list_member")){
html.children().first().addClass("td-notification-padded td-notification-padded-alt");
html.find(".activity-header").css("margin-top", "2px");
html.find(".avatar").first().css("margin-bottom", "0");
}
if (sensitive){
html.find(".media-badge").each(function(){
$(this)[0].lastChild.textContent += " (possibly sensitive)";
});
}
const source = tweet.getRelatedTweet();
const duration = source ? source.text.length + (source.quotedTweet ? source.quotedTweet.text.length : 0) : tweet.text.length;
const chirpId = source ? source.id : "";
const tweetUrl = source ? source.getChirpURL() : "";
const quoteUrl = source && source.quotedTweet ? source.quotedTweet.getChirpURL() : "";
$TD.onTweetPopup(column.model.privateState.apiid, chirpId, window.TDGF_getColumnName(column), html.html(), duration, tweetUrl, quoteUrl);
}
if (column.model.getHasSound()){
$TD.onTweetSound();
}
};
})();
//
// Block: Enable popup notifications.
//
execSafe(function hookDesktopNotifications(){
ensurePropertyExists(TD, "controller", "notifications");
TD.controller.notifications.hasNotifications = function(){
return true;
};
TD.controller.notifications.isPermissionGranted = function(){
return true;
};
$.subscribe("/notifications/new", function(obj){
for(let index = obj.items.length - 1; index >= 0; index--){
onNewTweet(obj.column, obj.items[index]);
}
});
});
//
// Block: Fix DM notifications not showing if the conversation is open.
//
if (checkPropertyExists(TD, "vo", "Column", "prototype", "mergeMissingChirps")){
TD.vo.Column.prototype.mergeMissingChirps = prependToFunction(TD.vo.Column.prototype.mergeMissingChirps, function(e){
const model = this.model;
if (model && model.state && model.state.type === "privateMe" && !this.notificationsDisabled && e.poller.feed.managed){
const unread = [];
for(let chirp of e.chirps){
if (Array.isArray(chirp.messages)){
Array.prototype.push.apply(unread, chirp.messages.filter(message => message.read === false));
}
}
if (unread.length > 0){
if (checkPropertyExists(TD, "util", "chirpReverseColumnSort")){
unread.sort(TD.util.chirpReverseColumnSort);
}
for(let message of unread){
onNewTweet(this, message);
}
// TODO sound notifications are borked as well
// TODO figure out what to do with missed notifications at startup
}
}
});
}
})();
//
// Block: Mute sound notifications.
//
HTMLAudioElement.prototype.play = prependToFunction(HTMLAudioElement.prototype.play, function(){
return $TDX.muteNotifications;
});
//
// Block: Add additional link information to context menu.
//
execSafe(function setupLinkContextMenu(){
$(document.body).delegate("a", "contextmenu", function(){
const me = $(this)[0];
if (me.classList.contains("js-media-image-link")){
const hovered = getHoveredTweet();
return if !hovered;
const tweet = hovered.obj.hasMedia() ? hovered.obj : hovered.obj.quotedTweet;
const media = tweet.getMedia().find(media => media.mediaId === me.getAttribute("data-media-entity-id"));
if ((media.isVideo && media.service === "twitter") || media.isAnimatedGif){
$TD.setRightClickedLink("video", media.chooseVideoVariant().url);
}
else{
$TD.setRightClickedLink("image", media.large());
}
}
else if (me.classList.contains("js-gif-play")){
$TD.setRightClickedLink("video", $(this).closest(".js-media-gif-container").find("video").attr("src"));
}
else if (me.hasAttribute("data-full-url")){
$TD.setRightClickedLink("link", me.getAttribute("data-full-url"));
}
});
});
//
// Block: Add tweet-related options to context menu.
//
execSafe(function setupTweetContextMenu(){
ensurePropertyExists(TD, "controller", "columnManager", "get");
ensurePropertyExists(TD, "services", "ChirpBase", "TWEET");
ensurePropertyExists(TD, "services", "TwitterActionFollow");
const processMedia = function(chirp){
return chirp.getMedia().filter(item => !item.isAnimatedGif).map(item => item.entity.media_url_https + ":small").join(";");
};
app.delegate("section.js-column", "contextmenu", function(){
const hovered = getHoveredTweet();
return if !hovered;
const tweet = hovered.obj;
const quote = tweet.quotedTweet;
if (tweet.chirpType === TD.services.ChirpBase.TWEET){
const tweetUrl = tweet.getChirpURL();
const quoteUrl = quote && quote.getChirpURL();
const chirpAuthors = quote ? [ tweet.getMainUser().screenName, quote.getMainUser().screenName ].join(";") : tweet.getMainUser().screenName;
const chirpImages = tweet.hasImage() ? processMedia(tweet) : quote && quote.hasImage() ? processMedia(quote) : "";
$TD.setRightClickedChirp(tweetUrl || "", quoteUrl || "", chirpAuthors, chirpImages);
}
else if (tweet instanceof TD.services.TwitterActionFollow){
$TD.setRightClickedLink("link", tweet.following.getProfileURL());
}
});
});
//
// Block: Expand shortened links on hover or display tooltip.
//
execSafe(function setupLinkExpansionOrTooltip(){
let prevMouseX = -1, prevMouseY = -1;
let tooltipTimer, tooltipDisplayed;
$(document.body).delegate("a[data-full-url]", {
mouseenter: function(){
const me = $(this);
const text = me.text();
return if text.charCodeAt(text.length - 1) !== 8230 && text.charCodeAt(0) !== 8230; // horizontal ellipsis
if ($TDX.expandLinksOnHover){
tooltipTimer = window.setTimeout(function(){
me.attr("td-prev-text", text);
me.text(me.attr("data-full-url").replace(/^https?:\/\/(www\.)?/, ""));
}, 200);
}
else{
tooltipTimer = window.setTimeout(function(){
$TD.displayTooltip(me.attr("data-full-url"));
tooltipDisplayed = true;
}, 400);
}
},
mouseleave: function(){
const me = $(this)[0];
if (me.hasAttribute("td-prev-text")){
me.innerText = me.getAttribute("td-prev-text");
}
window.clearTimeout(tooltipTimer);
if (tooltipDisplayed){
tooltipDisplayed = false;
$TD.displayTooltip(null);
}
},
mousemove: function(e){
if (tooltipDisplayed && (prevMouseX !== e.clientX || prevMouseY !== e.clientY)){
$TD.displayTooltip($(this).attr("data-full-url"));
prevMouseX = e.clientX;
prevMouseY = e.clientY;
}
}
});
});
//
// Block: Support for extra mouse buttons.
//
execSafe(function supportExtraMouseButtons(){
const tryClickSelector = function(selector, parent){
return $(selector, parent).click().length;
};
const tryCloseModal1 = function(){
const modal = $("#open-modal");
return modal.is(":visible") && tryClickSelector("a.mdl-dismiss", modal);
};
const tryCloseModal2 = function(){
const modal = $(".js-modals-container");
return modal.length && tryClickSelector("a.mdl-dismiss", modal);
};
const tryCloseHighlightedColumn = function(){
const column = getHoveredColumn();
return false if !column;
const ele = $(column.ele);
return ((ele.is(".is-shifted-2") && tryClickSelector(".js-tweet-social-proof-back", ele)) || (ele.is(".is-shifted-1") && tryClickSelector(".js-column-back", ele)));
};
window.TDGF_onMouseClickExtra = function(button){
if (button === 1){ // back button
tryClickSelector(".is-shifted-2 .js-tweet-social-proof-back", ".js-modal-panel") ||
tryClickSelector(".is-shifted-1 .js-column-back", ".js-modal-panel") ||
tryCloseModal1() ||
tryCloseModal2() ||
tryClickSelector(".js-inline-compose-close") ||
tryCloseHighlightedColumn() ||
tryClickSelector(".js-app-content.is-open .js-drawer-close:visible") ||
tryClickSelector(".is-shifted-2 .js-tweet-social-proof-back, .is-shifted-2 .js-dm-participants-back") ||
$(".is-shifted-1 .js-column-back").click();
}
else if (button === 2){ // forward button
const hovered = getHoveredTweet();
if (hovered){
$(hovered.ele).children().first().click();
}
}
};
});
//
// Block: Allow drag & drop behavior for dropping links on columns to open their detail view.
//
execSafe(function supportDragDropOverColumns(){
const regexTweet = /^https?:\/\/twitter\.com\/[A-Za-z0-9_]+\/status\/(\d+)\/?\??/;
const regexAccount = /^https?:\/\/twitter\.com\/(?!signup$|tos$|privacy$|search$|search-)([^/?]+)\/?$/;
let dragType = false;
const events = {
dragover: function(e){
e.originalEvent.dataTransfer.dropEffect = dragType ? "all" : "none";
e.preventDefault();
e.stopPropagation();
},
drop: function(e){
const url = e.originalEvent.dataTransfer.getData("URL");
if (dragType === "tweet"){
const match = regexTweet.exec(url);
if (match.length === 2){
const column = TD.controller.columnManager.get($(this).attr("data-column"));
if (column){
TD.controller.clients.getPreferredClient().show(match[1], function(chirp){
TD.ui.updates.showDetailView(column, chirp, column.findChirp(chirp) || chirp);
$(document).trigger("uiGridClearSelection");
}, function(){
alert("error|Could not retrieve the requested tweet.");
});
}
}
}
else if (dragType === "account"){
const match = regexAccount.exec(url);
if (match.length === 2){
$(document).trigger("uiShowProfile", { id: match[1] });
}
}
e.preventDefault();
e.stopPropagation();
}
};
const selectors = {
tweet: "section.js-column",
account: app
};
window.TDGF_onGlobalDragStart = function(type, data){
if (dragType){
app.undelegate(selectors[dragType], events);
dragType = null;
}
if (type === "link"){
dragType = regexTweet.test(data) ? "tweet" : regexAccount.test(data) ? "account": null;
app.delegate(selectors[dragType], events);
}
};
});
//
// Block: Make middle click on tweet reply icon open the compose drawer, retweet icon trigger a quote, and favorite icon open a 'Like from accounts...' modal.
//
execSafe(function supportMiddleClickTweetActions(){
app.delegate(".tweet-action,.tweet-detail-action", "auxclick", function(e){
return if e.which !== 2;
const column = TD.controller.columnManager.get($(this).closest("section.js-column").attr("data-column"));
return if !column;
const ele = $(this).closest("article");
const tweet = column.findChirp(ele.attr("data-tweet-id")) || column.findChirp(ele.attr("data-key"));
return if !tweet;
switch($(this).attr("rel")){
case "reply":
const main = tweet.getMainTweet();
$(document).trigger("uiDockedComposeTweet", {
type: "reply",
from: [ tweet.account.getKey() ],
inReplyTo: {
id: tweet.id,
htmlText: main.htmlText,
user: {
screenName: main.user.screenName,
name: main.user.name,
profileImageURL: main.user.profileImageURL
}
},
mentions: tweet.getReplyUsers(),
element: ele
});
break;
case "favorite":
$(document).trigger("uiShowFavoriteFromOptions", { tweet });
break;
case "retweet":
TD.controller.stats.quoteTweet();
$(document).trigger("uiComposeTweet", {
type: "tweet",
from: [ tweet.account.getKey() ],
quotedTweet: tweet.getMainTweet(),
element: ele // triggers reply-account plugin
});
break;
default:
return;
}
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
});
});
//
// Block: Add a pin icon to make tweet compose drawer stay open.
//
execSafe(function setupStayOpenPin(){
$(document).on("tduckOldComposerActive", function(e){
const ele = $(`#import "markup/pin.html"`).appendTo(".js-docked-compose .js-compose-header");
ele.click(function(){
if (TD.settings.getComposeStayOpen()){
ele.css("transform", "rotate(0deg)");
TD.settings.setComposeStayOpen(false);
}
else{
ele.css("transform", "rotate(90deg)");
TD.settings.setComposeStayOpen(true);
}
});
if (TD.settings.getComposeStayOpen()){
ele.css("transform", "rotate(90deg)");
}
});
});
//
// Block: Make submitting search queries while holding Ctrl or middle-clicking the search icon open the search externally.
//
onAppReady.push(function setupSearchTriggerHook(){
const openSearchExternally = function(event, input){
$TD.openBrowser("https://twitter.com/search/?q=" + encodeURIComponent(input.val() || ""));
event.preventDefault();
event.stopPropagation();
input.val("").blur();
app.click(); // unfocus everything
};
$$(".js-app-search-input").keydown(function(e){
(e.ctrlKey && e.keyCode === 13) && openSearchExternally(e, $(this)); // enter
});
$$(".js-perform-search").on("click auxclick", function(e){
(e.ctrlKey || e.button === 1) && openSearchExternally(e, $(".js-app-search-input:visible"));
}).each(function(){
window.TDGF_prioritizeNewestEvent($(this)[0], "click");
});
$$("[data-action='show-search']").on("click auxclick", function(e){
(e.ctrlKey || e.button === 1) && openSearchExternally(e, $());
});
});
//
// Block: Setup video player hooks.
//
execSafe(function setupVideoPlayer(){
const getGifLink = function(ele){
return ele.attr("src") || ele.children("source[video-src]").first().attr("video-src");
};
const getVideoTweetLink = function(obj){
let parent = obj.closest(".js-tweet").first();
let link = (parent.hasClass("tweet-detail") ? parent.find("a[rel='url']") : parent.find("time").first().children("a")).first();
return link.attr("href");
};
const getUsername = function(tweet){
return tweet && (tweet.quotedTweet || tweet).getMainUser().screenName;
};
app.delegate(".js-gif-play", {
click: function(e){
let src = !e.ctrlKey && getGifLink($(this).closest(".js-media-gif-container").find("video"));
let tweet = getVideoTweetLink($(this));
if (src){
let hovered = getHoveredTweet();
window.TDGF_playVideo(src, tweet, getUsername(hovered && hovered.obj));
}
else{
$TD.openBrowser(tweet);
}
e.stopPropagation();
},
mousedown: function(e){
if (e.button === 1){
e.preventDefault();
}
},
mouseup: function(e){
if (e.button === 1){
$TD.openBrowser(getVideoTweetLink($(this)));
e.preventDefault();
}
}
});
window.TDGF_injectMustache("status/media_thumb.mustache", "append", "is-gif", " is-paused");
TD.mustaches["media/native_video.mustache"] = '<div class="js-media-gif-container media-item nbfc is-video" style="background-image:url({{imageSrc}})"><video class="js-media-gif media-item-gif full-width block {{#isPossiblySensitive}}is-invisible{{/isPossiblySensitive}}" loop src="{{videoUrl}}"></video><a class="js-gif-play pin-all is-actionable">{{> media/video_overlay}}</a></div>';
ensurePropertyExists(TD, "components", "MediaGallery", "prototype", "_loadTweet");
ensurePropertyExists(TD, "components", "BaseModal", "prototype", "setAndShowContainer");
ensurePropertyExists(TD, "ui", "Column", "prototype", "playGifIfNotManuallyPaused");
let cancelModal = false;
TD.components.MediaGallery.prototype._loadTweet = appendToFunction(TD.components.MediaGallery.prototype._loadTweet, function(){
const media = this.chirp.getMedia().find(media => media.mediaId === this.clickedMediaEntityId);
if (media && media.isVideo && media.service === "twitter"){
window.TDGF_playVideo(media.chooseVideoVariant().url, this.chirp.getChirpURL(), getUsername(this.chirp));
cancelModal = true;
}
});
TD.components.BaseModal.prototype.setAndShowContainer = prependToFunction(TD.components.BaseModal.prototype.setAndShowContainer, function(){
if (cancelModal){
cancelModal = false;
return true;
}
});
TD.ui.Column.prototype.playGifIfNotManuallyPaused = function(){};
});
//
// Block: Detect and notify about connection issues.
//
(function(){
const onConnectionError = function(){
return if $("#tweetduck-conn-issues").length;
const ele = $(`#import "markup/offline.html"`).appendTo(document.body);
ele.find("button").click(function(){
ele.fadeOut(200);
});
};
const onConnectionFine = function(){
const ele = $("#tweetduck-conn-issues");
ele.fadeOut(200, function(){
ele.remove();
});
};
window.addEventListener("offline", onConnectionError);
window.addEventListener("online", onConnectionFine);
})();

View File

@ -0,0 +1,279 @@
//
// Functions: Responds to updating $TDX properties.
//
(function(){
let callbacks = [];
window.TDGF_registerPropertyUpdateCallback = function(callback){
callbacks.push(callback);
};
window.TDGF_onPropertiesUpdated = function(){
callbacks.forEach(func => func($TDX));
};
})();
//
// Function: Injects custom HTML into mustache templates.
//
window.TDGF_injectMustache = function(name, operation, search, custom){
let replacement;
switch(operation){
case "replace": replacement = custom; break;
case "append": replacement = search + custom; break;
case "prepend": replacement = custom + search; break;
default: throw "Invalid mustache injection operation. Only 'replace', 'append', 'prepend' are supported.";
}
const prev = TD.mustaches && TD.mustaches[name];
if (!prev){
crashDebug("Mustache injection is referencing an invalid mustache: " + name);
return false;
}
TD.mustaches[name] = prev.replace(search, replacement);
if (prev === TD.mustaches[name]){
crashDebug("Mustache injection had no effect: " + name);
return false;
}
return true;
};
//
// Function: Pushes the newest jQuery event to the beginning of the event handler list.
//
window.TDGF_prioritizeNewestEvent = function(element, event){
const events = $._data(element, "events");
const handlers = events[event];
const newHandler = handlers[handlers.length - 1];
for(let index = handlers.length - 1; index > 0; index--){
handlers[index] = handlers[index - 1];
}
handlers[0] = newHandler;
};
//
// Function: Returns a display name for a column object.
//
window.TDGF_getColumnName = (function(){
const titles = {
"icon-home": "Home",
"icon-mention": "Mentions",
"icon-message": "Messages",
"icon-notifications": "Notifications",
"icon-follow": "Followers",
"icon-activity": "Activity",
"icon-favorite": "Likes",
"icon-user": "User",
"icon-search": "Search",
"icon-list": "List",
"icon-custom-timeline": "Timeline",
"icon-dataminr": "Dataminr",
"icon-play-video": "Live video",
"icon-schedule": "Scheduled"
};
return function(column){
return titles[column._tduck_icon] || "";
};
})();
//
// Function: Adds a search column with the specified query.
//
onAppReady.push(() => execSafe(function setupSearchFunction(){
const context = $._data(document, "events")["uiSearchInputSubmit"][0].handler.context;
window.TDGF_performSearch = function(query){
context.performSearch({ query, tduckResetInput: true });
};
}, function(){
window.TDGF_performSearch = function(){
alert("error|This feature is not available due to an internal error.");
};
}));
//
// Function: Plays sound notification.
//
window.TDGF_playSoundNotification = function(){
document.getElementById("update-sound").play();
};
//
// Function: Plays video using the internal player.
//
window.TDGF_playVideo = function(videoUrl, tweetUrl, username){
return if !videoUrl;
$TD.playVideo(videoUrl, tweetUrl || videoUrl, username || null, function(){
$('<div id="td-video-player-overlay" class="ovl" style="display:block"></div>').on("click contextmenu", function(){
$TD.stopVideo();
}).appendTo(app);
});
};
//
// Function: Shows tweet detail, used in notification context menu.
//
execSafe(function setupShowTweetDetail(){
ensurePropertyExists(TD, "ui", "updates", "showDetailView");
ensurePropertyExists(TD, "controller", "columnManager", "showColumn");
ensurePropertyExists(TD, "controller", "columnManager", "getByApiid");
ensurePropertyExists(TD, "controller", "clients", "getPreferredClient");
const showTweetDetailInternal = function(column, chirp){
TD.ui.updates.showDetailView(column, chirp, column.findChirp(chirp) || chirp);
TD.controller.columnManager.showColumn(column.model.privateState.key);
$(document).trigger("uiGridClearSelection");
};
window.TDGF_showTweetDetail = function(columnId, chirpId, fallbackUrl){
if (!TD.ready){
onAppReady.push(function(){
window.TDGF_showTweetDetail(columnId, chirpId, fallbackUrl);
});
return;
}
const column = TD.controller.columnManager.getByApiid(columnId);
if (!column){
if (confirm("error|The column which contained the tweet no longer exists. Would you like to open the tweet in your browser instead?")){
$TD.openBrowser(fallbackUrl);
}
return;
}
const chirp = column.findMostInterestingChirp(chirpId);
if (chirp){
showTweetDetailInternal(column, chirp);
}
else{
TD.controller.clients.getPreferredClient().show(chirpId, function(chirp){
showTweetDetailInternal(column, chirp);
}, function(){
if (confirm("error|Could not retrieve the requested tweet. Would you like to open the tweet in your browser instead?")){
$TD.openBrowser(fallbackUrl);
}
});
}
};
}, function(){
window.TDGF_showTweetDetail = function(){
alert("error|This feature is not available due to an internal error.");
};
});
//
// Function: Screenshots tweet to clipboard.
//
execSafe(function setupTweetScreenshot(){
window.TDGF_triggerScreenshot = function(){
const hovered = getHoveredTweet();
return if !hovered;
const columnWidth = $(hovered.column.ele).width();
const tweet = hovered.wrap || hovered.obj;
const html = $(tweet.render({
withFooter: false,
withTweetActions: false,
isInConvo: false,
isFavorite: false,
isRetweeted: false, // keeps retweet mark above tweet
isPossiblySensitive: false,
mediaPreviewSize: hovered.column.obj.getMediaPreviewSize()
}));
html.find("footer").last().remove(); // apparently withTweetActions breaks for certain tweets, nice
html.find(".td-screenshot-remove").remove();
html.find("p.link-complex-target,p.txt-mute").filter(function(){
return $(this).text() === "Show this thread";
}).remove();
html.addClass($(document.documentElement).attr("class"));
html.addClass($(document.body).attr("class"));
html.css("background-color", getClassStyleProperty("stream-item", "background-color"));
html.css("border", "none");
for(let selector of [ ".js-quote-detail", ".js-media-preview-container", ".js-media" ]){
const ele = html.find(selector);
if (ele.length){
ele[0].style.setProperty("margin-bottom", "2px", "important");
break;
}
}
const gif = html.find(".js-media-gif-container");
if (gif.length){
gif.css("background-image", 'url("'+tweet.getMedia()[0].small()+'")');
}
const type = tweet.getChirpType();
if ((type.startsWith("favorite") || type.startsWith("retweet")) && tweet.isAboutYou()){
html.addClass("td-notification-padded");
}
$TD.screenshotTweet(html[0].outerHTML, columnWidth);
};
}, function(){
window.TDGF_triggerScreenshot = function(){
alert("error|This feature is not available due to an internal error.");
};
});
//
// Function: Apply ROT13 to input selection.
//
window.TDGF_applyROT13 = function(){
const ele = document.activeElement;
return if !ele || !ele.value;
const selection = ele.value.substring(ele.selectionStart, ele.selectionEnd);
return if !selection;
document.execCommand("insertText", false, selection.replace(/[a-zA-Z]/g, function(chr){
const code = chr.charCodeAt(0);
const start = code <= 90 ? 65 : 97;
return String.fromCharCode(start + (code - start + 13) % 26);
}));
};
//
// Function: Reloads all columns.
//
if (checkPropertyExists(TD, "controller", "columnManager", "getAll")){
window.TDGF_reloadColumns = function(){
Object.values(TD.controller.columnManager.getAll()).forEach(column => column.reloadTweets());
};
}
else{
window.TDGF_reloadColumns = function(){};
}
//
// Function: Reloads the website with memory cleanup.
//
window.TDGF_reload = function(){
window.gc && window.gc();
window.location.reload();
window.TDGF_reload = function(){}; // redefine to prevent reloading multiple times
};

View File

@ -0,0 +1,468 @@
//
// Block: Paste images when tweeting.
//
onAppReady.push(function supportImagePaste(){
const uploader = $._data(document, "events")["uiComposeAddImageClick"][0].handler.context;
app.delegate(".js-compose-text,.js-reply-tweetbox,.td-detect-image-paste", "paste", function(e){
for(let item of e.originalEvent.clipboardData.items){
if (item.type.startsWith("image/")){
if (!$(this).closest(".rpl").find(".js-reply-popout").click().length){ // popout direct messages
return if $(".js-add-image-button").is(".is-disabled"); // tweetdeck does not check upload count properly
}
uploader.addFilesToUpload([ item.getAsFile() ]);
break;
}
}
});
});
//
// Block: Allow changing first day of week in date picker.
//
if (checkPropertyExists($, "tools", "dateinput", "conf", "firstDay")){
$.tools.dateinput.conf.firstDay = $TDX.firstDayOfWeek;
onAppReady.push(function setupDatePickerFirstDayCallback(){
window.TDGF_registerPropertyUpdateCallback(function($TDX){
$.tools.dateinput.conf.firstDay = $TDX.firstDayOfWeek;
});
});
}
//
// Block: Override language used for translations.
//
if (checkPropertyExists(TD, "languages", "getSystemLanguageCode")){
const prevFunc = TD.languages.getSystemLanguageCode;
TD.languages.getSystemLanguageCode = function(returnShortCode){
return returnShortCode ? ($TDX.translationTarget || "en") : prevFunc.apply(this, arguments);
};
}
//
// Block: Add missing languages for Bing Translator (Bengali, Icelandic, Tagalog, Tamil, Telugu, Urdu).
//
execSafe(function addMissingTranslationLanguages(){
ensurePropertyExists(TD, "languages", "getSupportedTranslationSourceLanguages");
const newCodes = [ "bn", "is", "tl", "ta", "te", "ur" ];
const codeSet = new Set(TD.languages.getSupportedTranslationSourceLanguages());
for(const lang of newCodes){
codeSet.add(lang);
}
const codeList = [...codeSet];
TD.languages.getSupportedTranslationSourceLanguages = function(){
return codeList;
};
});
//
// Block: Bypass t.co when clicking/dragging links, media, and in user profiles.
//
execSafe(function setupShortenerBypass(){
$(document.body).delegate("a[data-full-url]", "click auxclick", function(e){
// event.which seems to be borked in auxclick
// tweet links open directly in the column
if ((e.button === 0 || e.button === 1) && $(this).attr("rel") !== "tweet"){
$TD.openBrowser($(this).attr("data-full-url"));
e.preventDefault();
}
});
$(document.body).delegate("a[data-full-url]", "dragstart", function(e){
const url = $(this).attr("data-full-url");
const data = e.originalEvent.dataTransfer;
data.clearData();
data.setData("text/uri-list", url);
data.setData("text/plain", url);
data.setData("text/html", `<a href="${url}">${url}</a>`);
});
if (checkPropertyExists(TD, "services", "TwitterStatus", "prototype", "_generateHTMLText")){
TD.services.TwitterStatus.prototype._generateHTMLText = prependToFunction(TD.services.TwitterStatus.prototype._generateHTMLText, function(){
const card = this.card;
const entities = this.entities;
return if !(card && entities);
const urls = entities.urls;
return if !(urls && urls.length);
const shortUrl = card.url;
const urlObj = entities.urls.find(obj => obj.url === shortUrl && obj.expanded_url);
if (urlObj){
const expandedUrl = urlObj.expanded_url;
card.url = expandedUrl;
const values = card.binding_values;
if (values && values.card_url){
values.card_url.string_value = expandedUrl;
}
}
});
}
if (checkPropertyExists(TD, "services", "TwitterMedia", "prototype", "fromMediaEntity")){
const prevFunc = TD.services.TwitterMedia.prototype.fromMediaEntity;
TD.services.TwitterMedia.prototype.fromMediaEntity = function(){
const obj = prevFunc.apply(this, arguments);
const e = arguments[0];
if (e.expanded_url){
if (obj.url === obj.shortUrl){
obj.shortUrl = e.expanded_url;
}
obj.url = e.expanded_url;
}
return obj;
};
}
if (checkPropertyExists(TD, "services", "TwitterUser", "prototype", "fromJSONObject")){
const prevFunc = TD.services.TwitterUser.prototype.fromJSONObject;
TD.services.TwitterUser.prototype.fromJSONObject = function(){
const obj = prevFunc.apply(this, arguments);
const e = arguments[0].entities;
if (e && e.url && e.url.urls && e.url.urls.length && e.url.urls[0].expanded_url){
obj.url = e.url.urls[0].expanded_url;
}
return obj;
};
}
});
//
// Block: Fix youtu.be previews not showing up for https links.
//
execSafe(function fixYouTubePreviews(){
ensurePropertyExists(TD, "services", "TwitterMedia");
const media = TD.services.TwitterMedia;
ensurePropertyExists(media, "YOUTUBE_TINY_RE");
ensurePropertyExists(media, "YOUTUBE_LONG_RE");
ensurePropertyExists(media, "YOUTUBE_RE");
ensurePropertyExists(media, "SERVICES", "youtube");
media.YOUTUBE_TINY_RE = new RegExp(media.YOUTUBE_TINY_RE.source.replace("http:", "https?:"));
media.YOUTUBE_RE = new RegExp(media.YOUTUBE_LONG_RE.source + "|" + media.YOUTUBE_TINY_RE.source);
media.SERVICES["youtube"] = media.YOUTUBE_RE;
});
//
// Block: Refocus the textbox after switching accounts.
//
onAppReady.push(function setupAccountSwitchRefocus(){
const refocusInput = function(){
document.querySelector(".js-docked-compose .js-compose-text").focus();
};
const accountItemClickEvent = function(e){
setTimeout(refocusInput, 0);
};
$(document).on("tduckOldComposerActive", function(e){
$$(".js-account-list", ".js-docked-compose").delegate(".js-account-item", "click", accountItemClickEvent);
});
});
//
// Block: Fix docked composer not re-focusing after Alt+Tab & image upload.
//
onAppReady.push(function fixDockedComposerRefocus(){
$(document).on("tduckOldComposerActive", function(e){
const ele = $$(".js-compose-text", ".js-docked-compose");
const node = ele[0];
let cancelBlur = false;
ele.on("blur", function(e){
cancelBlur = true;
setTimeout(function(){ cancelBlur = false; }, 0);
});
window.TDGF_prioritizeNewestEvent(node, "blur");
node.blur = prependToFunction(node.blur, function(){
return cancelBlur;
});
});
ensureEventExists(document, "uiComposeImageAdded");
$(document).on("uiComposeImageAdded", function(){
document.querySelector(".js-docked-compose .js-compose-text").focus();
});
});
//
// Block: Fix DM reply input box not getting focused after opening a conversation.
//
if (checkPropertyExists(TD, "components", "ConversationDetailView", "prototype", "showChirp")){
TD.components.ConversationDetailView.prototype.showChirp = appendToFunction(TD.components.ConversationDetailView.prototype.showChirp, function(){
return if !$TDX.focusDmInput;
setTimeout(function(){
document.querySelector(".js-reply-tweetbox").focus();
}, 100);
});
}
//
// Block: Hold Shift to restore cleared column.
//
execSafe(function supportShiftToClearColumn(){
ensurePropertyExists(TD, "vo", "Column", "prototype", "clear");
let holdingShift = false;
const updateShiftState = (pressed) => {
if (pressed != holdingShift){
holdingShift = pressed;
$("button[data-action='clear']").children("span").text(holdingShift ? "Restore" : "Clear");
}
};
const resetActiveFocus = () => {
document.activeElement.blur();
};
document.addEventListener("keydown", function(e){
if (e.shiftKey && (document.activeElement === null || !("value" in document.activeElement))){
updateShiftState(true);
}
});
document.addEventListener("keyup", function(e){
if (!e.shiftKey){
updateShiftState(false);
}
});
TD.vo.Column.prototype.clear = prependToFunction(TD.vo.Column.prototype.clear, function(){
window.setTimeout(resetActiveFocus, 0); // unfocuses the Clear button, otherwise it steals keyboard input
if (holdingShift){
this.model.setClearedTimestamp(0);
this.reloadTweets();
return true;
}
});
});
//
// Block: Make temporary search column appear as the first one and clear the input box.
//
execSafe(function setupSearchColumnHook(){
ensurePropertyExists(TD, "controller", "columnManager", "_columnOrder");
ensurePropertyExists(TD, "controller", "columnManager", "move");
$(document).on("uiSearchNoTemporaryColumn", function(e, data){
if (data.query && data.searchScope !== "users" && !data.columnKey){
if ($TDX.openSearchInFirstColumn){
const order = TD.controller.columnManager._columnOrder;
if (order.length > 1){
const columnKey = order[order.length - 1];
order.splice(order.length - 1, 1);
order.splice(1, 0, columnKey);
TD.controller.columnManager.move(columnKey, "left");
}
}
if (!("tduckResetInput" in data)){
$(".js-app-search-input").val("");
$(".js-perform-search").blur();
}
}
});
});
//
// Block: Reorder search results to move accounts above hashtags.
//
onAppReady.push(function reorderSearchResults(){
const container = $(".js-search-in-popover");
const hashtags = $$(".js-typeahead-topic-list", container);
$$(".js-typeahead-user-list", container).insertBefore(hashtags);
hashtags.addClass("list-divider");
});
//
// Block: Revert Like/Follow dialogs being closed after clicking an action.
//
execSafe(function setupLikeFollowDialogRevert(){
const prevSetTimeout = window.setTimeout;
const overrideState = function(){
return if !$TDX.keepLikeFollowDialogsOpen;
window.setTimeout = function(func, timeout){
return timeout !== 500 && prevSetTimeout.apply(this, arguments);
};
};
const restoreState = function(context, key){
window.setTimeout = prevSetTimeout;
if ($TDX.keepLikeFollowDialogsOpen && key in context.state){
context.state[key] = false;
}
};
$(document).on("uiShowFavoriteFromOptions", function(){
$(".js-btn-fav", ".js-modal-inner").each(function(){
let event = $._data(this, "events").click[0];
let handler = event.handler;
event.handler = function(){
overrideState();
handler.apply(this, arguments);
restoreState($._data(document, "events").dataFavoriteState[0].handler.context, "stopSubsequentLikes");
};
});
});
$(document).on("uiShowFollowFromOptions", function(){
$(".js-component", ".js-modal-inner").each(function(){
let event = $._data(this, "events").click[0];
let handler = event.handler;
let context = handler.context;
event.handler = function(){
overrideState();
handler.apply(this, arguments);
restoreState(context, "stopSubsequentFollows");
};
});
});
});
//
// Block: Fix broken horizontal scrolling of column container when holding Shift.
//
if (checkPropertyExists(TD, "ui", "columns", "setupColumnScrollListeners")){
TD.ui.columns.setupColumnScrollListeners = appendToFunction(TD.ui.columns.setupColumnScrollListeners, function(column){
const ele = document.querySelector(".js-column[data-column='" + column.model.getKey() + "']");
return if ele == null;
$(ele).off("onmousewheel").on("mousewheel", ".scroll-v", function(e){
e.stopImmediatePropagation();
});
window.TDGF_prioritizeNewestEvent(ele, "mousewheel");
});
}
//
// Block: Fix DM image previews and GIF thumbnails not loading due to new URLs.
//
if (checkPropertyExists(TD, "services", "TwitterMedia", "prototype", "getTwitterPreviewUrl")){
const prevFunc = TD.services.TwitterMedia.prototype.getTwitterPreviewUrl;
TD.services.TwitterMedia.prototype.getTwitterPreviewUrl = function(){
const url = prevFunc.apply(this, arguments);
if (url.startsWith("https://ton.twitter.com/1.1/ton/data/dm/") || url.startsWith("https://pbs.twimg.com/tweet_video_thumb/")){
const format = url.match(/\?.*format=(\w+)/);
if (format && format.length === 2){
const fix = `.${format[1]}?`;
if (!url.includes(fix)){
return url.replace("?", fix);
}
}
}
return url;
};
}
//
// Block: Fix DMs not being marked as read when replying to them.
//
execSafe(function markRepliedDMsAsRead(){
ensurePropertyExists(TD, "controller", "clients", "getClient");
ensurePropertyExists(TD, "services", "Conversations", "prototype", "getConversation");
$(document).on("dataDmSent", function(e, data){
const client = TD.controller.clients.getClient(data.request.accountKey);
return if !client;
const conversation = client.conversations.getConversation(data.request.conversationId);
return if !conversation;
conversation.markAsRead();
});
});
//
// Block: Limit amount of loaded DMs to avoid massive lag from re-opening them several times.
//
if (checkPropertyExists(TD, "services", "TwitterConversation", "prototype", "renderThread")){
const prevFunc = TD.services.TwitterConversation.prototype.renderThread;
TD.services.TwitterConversation.prototype.renderThread = function(){
const prevMessages = this.messages;
this.messages = prevMessages.slice(0, 100);
const result = prevFunc.apply(this, arguments);
this.messages = prevMessages;
return result;
};
}
//
// Block: Fix scheduled tweets not showing up sometimes.
//
execSafe(function fixScheduledTweets(){
ensurePropertyExists(TD, "controller", "columnManager", "getAll");
ensureEventExists(document, "dataTweetSent");
$(document).on("dataTweetSent", function(e, data){
if (data.response.state && data.response.state === "scheduled"){
const column = Object.values(TD.controller.columnManager.getAll()).find(column => column.model.state.type === "scheduled");
return if !column;
setTimeout(function(){
column.reloadTweets();
}, 1000);
}
});
});
//
// Block: Let's make retweets lowercase again.
//
window.TDGF_injectMustache("status/tweet_single.mustache", "replace", "{{_i}} Retweeted{{/i}}", "{{_i}} retweeted{{/i}}");
if (checkPropertyExists(TD, "services", "TwitterActionRetweet", "prototype", "generateText")){
TD.services.TwitterActionRetweet.prototype.generateText = appendToFunction(TD.services.TwitterActionRetweet.prototype.generateText, function(){
this.text = this.text.replace(" Retweeted", " retweeted");
this.htmlText = this.htmlText.replace(" Retweeted", " retweeted");
});
}
if (checkPropertyExists(TD, "services", "TwitterActionRetweetedInteraction", "prototype", "generateText")){
TD.services.TwitterActionRetweetedInteraction.prototype.generateText = appendToFunction(TD.services.TwitterActionRetweetedInteraction.prototype.generateText, function(){
this.htmlText = this.htmlText.replace(" Retweeted", " retweeted").replace(" Retweet", " retweet");
});
}

View File

@ -17,10 +17,10 @@
let obj;
try{
obj = eval("("+contents+")");
obj = eval("(" + contents + ")");
}catch(err){
if (!(onFailure && onFailure(err))){
$TD.alert("warning", "Problem loading '"+fileName+"' file for '"+identifier+"' plugin, the JavaScript syntax is invalid: "+err.message);
$TD.alert("warning", "Problem loading '" + fileName + "' file for '" + identifier + "' plugin, the JavaScript syntax is invalid: " + err.message);
}
return;
@ -29,12 +29,12 @@
onSuccess && onSuccess(obj);
}).catch(err => {
if (!(onFailure && onFailure(err))){
$TD.alert("warning", "Problem loading '"+fileName+"' file for '"+identifier+"' plugin: "+err.message);
$TD.alert("warning", "Problem loading '" + fileName + "' file for '" + identifier + "' plugin: " + err.message);
}
});
}).catch(err => {
if (!(onFailure && onFailure(err))){
$TD.alert("warning", "Problem checking '"+fileNameUser+"' file for '"+identifier+"' plugin: "+err.message);
$TD.alert("warning", "Problem checking '" + fileNameUser + "' file for '" + identifier + "' plugin: " + err.message);
}
});
};
@ -44,7 +44,7 @@
//
window.TDPF_createCustomStyle = function(pluginObject){
let element = document.createElement("style");
element.id = "plugin-"+pluginObject.$id+"-"+Math.random().toString(36).substring(2, 7);
element.id = "plugin-" + pluginObject.$id + "-"+Math.random().toString(36).substring(2, 7);
document.head.appendChild(element);
return {

View File

@ -1,10 +1,11 @@
(function(){
$(document).one("TD.ready", function(){
let css = $(`<style>#import "styles/introduction.css"</style>`).appendTo(document.head);
let ele = $(`#import "markup/introduction.html"`).appendTo(".js-app");
const css = $(`<style>#import "styles/introduction.css"</style>`).appendTo(document.head);
const ele = $(`#import "markup/introduction.html"`).appendTo(".js-app");
let tdUser = null;
let loadTweetDuckUser = (onSuccess, onError) => {
const loadTweetDuckUser = (onSuccess, onError) => {
if (tdUser !== null){
onSuccess(tdUser);
}
@ -28,8 +29,8 @@
});
ele.find("button, a.mdl-dismiss").click(function(){
let showGuide = $(this)[0].hasAttribute("data-guide");
let allowDataCollection = $("#td-anonymous-data").is(":checked");
const showGuide = $(this)[0].hasAttribute("data-guide");
const allowDataCollection = $("#td-anonymous-data").is(":checked");
ele.fadeOut(200, function(){
$TD.onIntroductionClosed(showGuide, allowDataCollection);

View File

@ -19,13 +19,13 @@
(function(){
const onLinkClick = function(e){
if (e.button === 0 || e.button === 1){
let ele = e.currentTarget;
const ele = e.currentTarget;
$TD.openBrowser(ele.href);
e.preventDefault();
if ($TDX.skipOnLinkClick){
let parentClasses = ele.parentNode.classList;
const parentClasses = ele.parentNode.classList;
if (parentClasses.contains("js-tweet-text") || parentClasses.contains("js-quoted-tweet-text") || parentClasses.contains("js-timestamp")){
$TD.loadNextNotification();
@ -46,12 +46,12 @@
let tooltipTimer, tooltipDisplayed;
addEventListener(links, "mouseenter", function(e){
let me = e.currentTarget;
const me = e.currentTarget;
let url = me.getAttribute("data-full-url");
const url = me.getAttribute("data-full-url");
return if !url;
let text = me.textContent;
const text = me.textContent;
return if text.charCodeAt(text.length-1) !== 8230 && text.charCodeAt(0) !== 8230; // horizontal ellipsis
if ($TDX.expandLinksOnHover){
@ -72,7 +72,7 @@
return if !e.currentTarget.hasAttribute("data-full-url");
if ($TDX.expandLinksOnHover){
let prevText = e.currentTarget.getAttribute("td-prev-text");
const prevText = e.currentTarget.getAttribute("td-prev-text");
if (prevText){
e.currentTarget.innerHTML = prevText;
@ -89,7 +89,7 @@
addEventListener(links, "mousemove", function(e){
if (tooltipDisplayed && (prevMouseX !== e.clientX || prevMouseY !== e.clientY)){
let url = e.currentTarget.getAttribute("data-full-url");
const url = e.currentTarget.getAttribute("data-full-url");
return if !url;
$TD.displayTooltip(url);
@ -138,7 +138,7 @@
//
// Block: Work around clipboard HTML formatting.
//
document.addEventListener("copy", function(e){
document.addEventListener("copy", function(){
window.setTimeout($TD.fixClipboard, 0);
});
@ -146,7 +146,7 @@
// Block: Setup a handler for 'Show this thread'.
//
(function(){
let btn = document.getElementById("tduck-show-thread");
const btn = document.getElementById("tduck-show-thread");
return if !btn;
btn.addEventListener("click", function(){

View File

@ -1,15 +1,15 @@
(function($TD){
let ele = document.getElementsByTagName("article")[0];
const ele = document.getElementsByTagName("article")[0];
ele.style.width = "{width}px";
ele.style.position = "absolute";
let contentHeight = ele.offsetHeight;
const contentHeight = ele.offsetHeight;
ele.style.position = "static";
let avatar = ele.querySelector(".tweet-avatar");
let avatarBottom = avatar ? avatar.getBoundingClientRect().bottom : 0;
const avatar = ele.querySelector(".tweet-avatar");
const avatarBottom = avatar ? avatar.getBoundingClientRect().bottom : 0;
$TD.setHeight(Math.floor(Math.max(contentHeight, avatarBottom+9))).then(() => {
$TD.setHeight(Math.floor(Math.max(contentHeight, avatarBottom + 9))).then(() => {
let framesLeft = {frames}; // basic render is done in 1 frame, large media take longer
let onNextFrame = function(){

View File

@ -11,7 +11,7 @@
return;
}
let link = document.createElement("link");
const link = document.createElement("link");
link.rel = "stylesheet";
link.href = "https://abs.twimg.com/tduck/css";
@ -32,7 +32,7 @@
//
const triggerWhenExists = function(query, callback){
let id = window.setInterval(function(){
let ele = document.querySelector(query);
const ele = document.querySelector(query);
if (ele && callback(ele)){
window.clearInterval(id);

View File

@ -37,7 +37,7 @@
// notification
let ele = document.getElementById("tweetduck-update");
let existed = !!ele;
const existed = !!ele;
if (existed){
ele.remove();
@ -141,11 +141,11 @@
};
try{
throw false if !($._data(document, "events").TD.some(obj => obj.namespace === "ready"));
throw "Missing jQuery or TD.ready event" if !($._data(document, "events").TD.some(obj => obj.namespace === "ready"));
$(document).one("TD.ready", triggerCheck);
}catch(err){
console.warn("Missing jQuery or TD.ready event");
console.warn(err);
setTimeout(triggerCheck, 500);
}