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

Fix twitter login page after it was migrated and broke detection

This commit is contained in:
chylex 2020-05-16 18:02:37 +02:00
parent 418388b0ab
commit cf7029037e
2 changed files with 41 additions and 85 deletions
Resources/Scripts

View File

@ -68,22 +68,13 @@ button[type='submit'] {
/* General per-page styling */
/****************************/
html[mobile][login] div[tweetduck-login-wrapper] {
html[login] div[tweetduck-login-wrapper] {
/* vertically center page & fix colors */
margin-top: calc(50vh - 200px);
padding: 26px 1.1vw;
background-color: white;
}
html[mobile][login] #tweetduck-helper:hover {
html[login] #tweetduck-helper:hover {
text-decoration: underline;
}
html[desktop][login] #tweetduck-helper {
margin-top: 15px !important;
font-weight: bold !important;
}
html[mobile][logout] div[role="button"] {
border: 1px solid rgba(0, 0, 0, 0.3) !important;
}

View File

@ -1,7 +1,6 @@
(function(){
const isLogin = location.pathname === "/login";
const isLogout = location.pathname === "/logout";
const isMobile = location.host === "mobile.twitter.com";
//
// Function: Inject custom CSS into the page.
@ -24,13 +23,6 @@
else if (isLogout){
document.documentElement.setAttribute("logout", "");
}
if (isMobile){
document.documentElement.setAttribute("mobile", "");
}
else{
document.documentElement.setAttribute("desktop", "");
}
};
setTimeout(injectCSS, 1);
@ -53,84 +45,57 @@
//
if (isLogin){
document.addEventListener("DOMContentLoaded", function(){
if (isMobile){
triggerWhenExists("main h1", function(heading){
heading.parentNode.setAttribute("tweetduck-login-wrapper", "");
return true;
});
triggerWhenExists("main h1", function(heading){
heading.parentNode.setAttribute("tweetduck-login-wrapper", "");
return true;
});
triggerWhenExists("a[href='/i/flow/signup']", function(texts){
texts = texts.parentNode;
triggerWhenExists("a[href='/i/flow/signup']", function(texts){
texts = texts.parentNode;
let link = texts.childNodes[0];
let separator = texts.childNodes[1];
if (link && separator){
texts.classList.add("tweetduck-login-links");
link = link.cloneNode(false);
link.id = "tweetduck-helper";
link.href = "#";
link.innerText = "Import TweetDuck profile";
texts.appendChild(separator.cloneNode(true));
texts.appendChild(link);
link.addEventListener("click", function(){
$TD.openProfileImport();
});
return true;
}
else{
return false;
}
});
}
else{
const openLinkExternally = function(e){
let href = e.currentTarget.getAttribute("href");
$TD.openBrowser(href[0] === '/' ? location.origin+href : href);
e.preventDefault();
e.stopPropagation();
};
let link = texts.childNodes[0];
let separator = texts.childNodes[1];
for(let link of document.getElementsByTagName("A")){
link.addEventListener("click", openLinkExternally);
}
let texts = document.querySelector(".page-canvas > div:last-child");
if (texts){
texts.insertAdjacentHTML("beforeend", `<p id="tweetduck-helper">Used the TweetDuck app before? <a href="#">Import your profile »</a></p>`);
if (link && separator){
texts.classList.add("tweetduck-login-links");
texts.querySelector("#tweetduck-helper > a").addEventListener("click", function(){
link = link.cloneNode(false);
link.id = "tweetduck-helper";
link.href = "#";
link.innerText = "Import TweetDuck profile";
texts.appendChild(separator.cloneNode(true));
texts.appendChild(link);
link.addEventListener("click", function(){
$TD.openProfileImport();
});
return true;
}
}
else{
return false;
}
});
});
}
//
// Block: Hide cookie crap.
//
if (isMobile){
document.addEventListener("DOMContentLoaded", function(){
triggerWhenExists("a[href^='https://help.twitter.com/rules-and-policies/twitter-cookies']", function(cookie){
while(!!cookie){
if (cookie.offsetHeight > 30){
cookie.remove();
return true;
}
else{
cookie = cookie.parentNode;
}
document.addEventListener("DOMContentLoaded", function(){
triggerWhenExists("a[href^='https://help.twitter.com/rules-and-policies/twitter-cookies']", function(cookie){
while(!!cookie){
if (cookie.offsetHeight > 30){
cookie.remove();
return true;
}
return false;
});
else{
cookie = cookie.parentNode;
}
}
return false;
});
}
});
})();