1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-06-15 09:39:55 +02:00

Prepare login/logout page scripts and styles for Twitter redesign & minor fixes

This commit is contained in:
chylex 2019-10-07 03:01:17 +02:00
parent 7f6cc0da01
commit 1eb1f9848a
3 changed files with 124 additions and 80 deletions
Resources/Scripts
lib/TweetLib.Core/Features/Twitter

View File

@ -40,78 +40,50 @@
/* General styling */ /* General styling */
/*******************/ /*******************/
* {
border-radius: 0 !important;
}
body { body {
/* remove scrollbar */
overflow: hidden !important; overflow: hidden !important;
} }
.page-canvas { .page-canvas, div[tweetduck-login-wrapper], body.ResponsiveLayout > div.PageContainer > div.Section {
/* tweak page shadow */
box-shadow: 0 0 150px rgba(255, 255, 255, 0.3) !important; box-shadow: 0 0 150px rgba(255, 255, 255, 0.3) !important;
} }
.topbar, .TopNav { .topbar, .TopNav {
/* hide top bar */
display: none !important; display: none !important;
} }
.page-canvas, .buttons, .btn, input {
/* sharpen borders */
border-radius: 0 !important;
}
input { input {
/* tweak input padding */
padding: 5px 8px 4px !important; padding: 5px 8px 4px !important;
} }
button[type='submit'] { button[type='submit'] {
/* style buttons */
border: 1px solid rgba(0, 0, 0, 0.3) !important; border: 1px solid rgba(0, 0, 0, 0.3) !important;
border-radius: 0 !important;
} }
.tweetduck-helper { /****************************/
/* custom login text */ /* General per-page styling */
/****************************/
html[mobile][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 {
text-decoration: underline;
}
html[desktop][login] #tweetduck-helper {
margin-top: 15px !important; margin-top: 15px !important;
font-weight: bold !important; font-weight: bold !important;
} }
/********************************************/ html[mobile][logout] div[role="button"] {
/* Fix min width and margins on logout page */
/********************************************/
html[logout] .page-canvas {
width: auto !important;
max-width: 888px;
}
html[logout] .signout-wrapper {
width: auto !important;
margin: 0 auto !important;
}
html[logout] .signout {
margin: 60px 0 54px !important;
}
html[logout] .buttons {
padding-bottom: 0 !important;
}
/*******************************/
/* General logout page styling */
/*******************************/
html[logout] .aside {
/* hide elements around dialog */
display: none;
}
html[logout] .buttons button, html[logout] .buttons a {
/* style buttons */
display: inline-block;
margin: 0 4px !important;
border: 1px solid rgba(0, 0, 0, 0.3) !important; border: 1px solid rgba(0, 0, 0, 0.3) !important;
border-radius: 0 !important;
} }

View File

@ -1,4 +1,8 @@
(function(){ (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. // Function: Inject custom CSS into the page.
// //
@ -14,18 +18,76 @@
document.head.appendChild(link); document.head.appendChild(link);
if (location.pathname === "/logout"){ if (isLogin){
document.documentElement.setAttribute("login", "");
}
else if (isLogout){
document.documentElement.setAttribute("logout", ""); document.documentElement.setAttribute("logout", "");
} }
if (isMobile){
document.documentElement.setAttribute("mobile", "");
}
else{
document.documentElement.setAttribute("desktop", "");
}
}; };
setTimeout(injectCSS, 1); setTimeout(injectCSS, 1);
// //
// Block: Make login page links external. // Function: Trigger once element exists.
// //
if (location.pathname === "/login"){ const triggerWhenExists = function(query, callback){
let id = window.setInterval(function(){
let ele = document.querySelector(query);
if (ele && callback(ele)){
window.clearInterval(id);
}
}, 5);
};
//
// Block: Add profile import button & enable custom styling, make page links external on old login page.
//
if (isLogin){
document.addEventListener("DOMContentLoaded", function(){ document.addEventListener("DOMContentLoaded", function(){
if (isMobile){
triggerWhenExists("main h1", function(heading){
heading.parentNode.setAttribute("tweetduck-login-wrapper", "");
return true;
});
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){ const openLinkExternally = function(e){
let href = e.currentTarget.getAttribute("href"); let href = e.currentTarget.getAttribute("href");
$TD.openBrowser(href[0] === '/' ? location.origin+href : href); $TD.openBrowser(href[0] === '/' ? location.origin+href : href);
@ -41,24 +103,34 @@
let texts = document.querySelector(".page-canvas > div:last-child"); let texts = document.querySelector(".page-canvas > div:last-child");
if (texts){ if (texts){
texts.insertAdjacentHTML("beforeend", `<p class="tweetduck-helper">Used the TweetDuck app before? <a href="#">Import your profile »</a></p>`); texts.insertAdjacentHTML("beforeend", `<p id="tweetduck-helper">Used the TweetDuck app before? <a href="#">Import your profile »</a></p>`);
texts.querySelector(".tweetduck-helper > a").addEventListener("click", function(){ texts.querySelector("#tweetduck-helper > a").addEventListener("click", function(){
$TD.openProfileImport(); $TD.openProfileImport();
}); });
} }
}
}); });
} }
//
// 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/"; // 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;
}
}
return false;
});
}); });
} }
})(); })();

View File

@ -14,11 +14,11 @@ public static bool IsTweetDeck(string url){
} }
public static bool IsTwitter(string url){ public static bool IsTwitter(string url){
return url.Contains("//twitter.com/"); return url.Contains("//twitter.com/") || url.Contains("//mobile.twitter.com/");
} }
public static bool IsTwitterLogin2Factor(string url){ public static bool IsTwitterLogin2Factor(string url){
return url.Contains("//twitter.com/account/login_verification"); return url.Contains("//twitter.com/account/login_verification") || url.Contains("//mobile.twitter.com/account/login_verification");
} }
public static string? GetFileNameFromUrl(string url){ public static string? GetFileNameFromUrl(string url){