1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-30 05:34:06 +02:00
TweetDuck/Resources/Scripts/twitter.js

57 lines
1.4 KiB
JavaScript

(function(){
//
// Function: Inject custom CSS into the page.
//
var injectCSS = function(){
if (!document.head){
setTimeout(injectCSS, 5);
return;
}
var style = document.createElement("style");
style.innerText = `#import "styles/twitter.base.css"`;
if (location.pathname === "/logout"){
style.innerText += `#import "styles/twitter.logout.css"`;
}
document.head.appendChild(style);
};
setTimeout(injectCSS, 1);
//
// Block: Make login page links external.
//
if (location.pathname === "/login"){
document.addEventListener("DOMContentLoaded", function(){
let openLinkExternally = function(e){
let href = e.currentTarget.getAttribute("href");
$TD.openBrowser(href[0] === '/' ? location.origin+href : href);
e.preventDefault();
e.stopPropagation();
};
let links = document.getElementsByTagName("A");
for(let index = 0; index < links.length; index++){
links[index].addEventListener("click", openLinkExternally);
}
});
}
//
// Block: Fix broken Cancel button on logout page.
//
else if (location.pathname === "/logout"){
document.addEventListener("DOMContentLoaded", function(){
let cancel = document.querySelector(".buttons .cancel");
if (cancel && cancel.tagName === "A"){
cancel.href = "https://tweetdeck.twitter.com/";
}
});
}
})();