From 325e45582cbfb6bb63a8a4db4ef1d7142da0676b Mon Sep 17 00:00:00 2001 From: girst Date: Sun, 8 Sep 2019 04:46:49 +0200 Subject: [PATCH] WIP: welcome message on home page (#740) TODO: final text needs to be determined, then localized. --- assets/css/darktheme.css | 4 +++ assets/css/default.css | 30 ++++++++++++++++ assets/css/lighttheme.css | 4 +++ assets/js/welcome.js | 22 ++++++++++++ src/invidious.cr | 36 +++++++++++++++++++ src/invidious/helpers/helpers.cr | 3 +- src/invidious/users.cr | 1 + src/invidious/views/components/feed_menu.ecr | 6 +++- .../views/components/welcome_message.ecr | 18 ++++++++++ src/invidious/views/popular.ecr | 3 ++ src/invidious/views/template.ecr | 2 ++ 11 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 assets/js/welcome.js create mode 100644 src/invidious/views/components/welcome_message.ecr diff --git a/assets/css/darktheme.css b/assets/css/darktheme.css index 1b70956b..92090494 100644 --- a/assets/css/darktheme.css +++ b/assets/css/darktheme.css @@ -36,3 +36,7 @@ body { background-color: inherit; color: inherit; } + +.welcome-box { + background-image: linear-gradient(45deg, #111, #666); +} diff --git a/assets/css/default.css b/assets/css/default.css index 4daa9f16..159c4500 100644 --- a/assets/css/default.css +++ b/assets/css/default.css @@ -137,6 +137,12 @@ img.thumbnail { top: -0.7em; } +.infobox { + border: 1px solid #ccc; + border-radius: 5px; + padding: 1em ; +} + /* * Navbar */ @@ -255,6 +261,30 @@ input[type="search"]::-webkit-search-cancel-button { } } +/* + * Welcome Message + */ + +.welcome-outer { + margin: 0 1em; +} + +.welcome-box { + padding: 0 1em ; +} + +#dismiss_welcome { + font-size: small; + float: right; + margin: 1em 0; +} + +#call_to_action { + overflow: hidden; + text-overflow: ellipsis; + max-width: 100%; +} + /* * Footer */ diff --git a/assets/css/lighttheme.css b/assets/css/lighttheme.css index 73706bb7..7734bbff 100644 --- a/assets/css/lighttheme.css +++ b/assets/css/lighttheme.css @@ -14,3 +14,7 @@ a:not([data-id]) > .icon, .playlist-restricted > ol > li > a { color: #303030; } + +.welcome-box { + background-image: linear-gradient(45deg, #fff, #ccc); +} diff --git a/assets/js/welcome.js b/assets/js/welcome.js new file mode 100644 index 00000000..fba30f83 --- /dev/null +++ b/assets/js/welcome.js @@ -0,0 +1,22 @@ +var dismiss_welcome = document.getElementById('dismiss_welcome'); +dismiss_welcome.href = 'javascript:void(0);'; + +dismiss_welcome.addEventListener('click', function () { + var dark_mode = document.getElementById('dark_theme').media === 'none'; + + var url = '/dismiss_welcome?redirect=false'; + var xhr = new XMLHttpRequest(); + xhr.responseType = 'json'; + xhr.timeout = 10000; + xhr.open('GET', url, true); + + hide_welcome(); + window.localStorage.setItem('welcome_dismissed', true); + + xhr.send(); +}); + +function hide_welcome (bool) { + document.getElementById('feed-menu').classList.remove('hidden'); + document.getElementById('welcome-outer').classList.add('hidden'); +} diff --git a/src/invidious.cr b/src/invidious.cr index 8f7e1a63..fd4d74d2 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -1699,6 +1699,42 @@ get "/toggle_theme" do |env| end end +get "/dismiss_welcome" do |env| + locale = LOCALES[env.get("preferences").as(Preferences).locale]? + referer = get_referer(env, unroll: false) + + redirect = env.params.query["redirect"]? + redirect ||= "true" + redirect = redirect == "true" + + preferences = env.get("preferences").as(Preferences) + + preferences.welcome_dismissed = true + + preferences = preferences.to_json + + if Kemal.config.ssl || config.https_only + secure = true + else + secure = false + end + + if config.domain + env.response.cookies["PREFS"] = HTTP::Cookie.new(name: "PREFS", domain: "#{config.domain}", value: preferences, expires: Time.utc + 2.years, + secure: secure, http_only: true) + else + env.response.cookies["PREFS"] = HTTP::Cookie.new(name: "PREFS", value: preferences, expires: Time.utc + 2.years, + secure: secure, http_only: true) + end + + if redirect + env.redirect referer + else + env.response.content_type = "application/json" + "{}" + end +end + post "/watch_ajax" do |env| locale = LOCALES[env.get("preferences").as(Preferences).locale]? diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index 331f6360..faaa2dbe 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -151,6 +151,7 @@ struct ConfigPreferences unseen_only: {type: Bool, default: false}, video_loop: {type: Bool, default: false}, volume: {type: Int32, default: 100}, + welcome_dismissed: {type: Bool, default: false}, }) end @@ -215,7 +216,7 @@ struct Config hmac_key: String?, # HMAC signing key for CSRF tokens and verifying pubsub subscriptions domain: String?, # Domain to be used for links to resources on the site where an absolute URL is required use_pubsub_feeds: {type: Bool | Int32, default: false}, # Subscribe to channels using PubSubHubbub (requires domain, hmac_key) - default_home: {type: String, default: "Top"}, + default_home: {type: String, default: "Popular"}, feed_menu: {type: Array(String), default: ["Popular", "Top", "Trending", "Subscriptions"]}, top_enabled: {type: Bool, default: true}, captcha_enabled: {type: Bool, default: true}, diff --git a/src/invidious/users.cr b/src/invidious/users.cr index d3da28d7..1a998881 100644 --- a/src/invidious/users.cr +++ b/src/invidious/users.cr @@ -92,6 +92,7 @@ struct Preferences unseen_only: {type: Bool, default: CONFIG.default_user_preferences.unseen_only}, video_loop: {type: Bool, default: CONFIG.default_user_preferences.video_loop}, volume: {type: Int32, default: CONFIG.default_user_preferences.volume}, + welcome_dismissed: {type: Bool, default: CONFIG.default_user_preferences.welcome_dismissed}, }) end diff --git a/src/invidious/views/components/feed_menu.ecr b/src/invidious/views/components/feed_menu.ecr index 9867f56f..64423581 100644 --- a/src/invidious/views/components/feed_menu.ecr +++ b/src/invidious/views/components/feed_menu.ecr @@ -1,4 +1,8 @@ -
+<% if !(env.get? "user") && !env.get("preferences").as(Preferences).welcome_dismissed %> +