Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme swiching continued, this time working :) #2076

Merged
merged 5 commits into from
Mar 9, 2024
Merged

Theme swiching continued, this time working :) #2076

merged 5 commits into from
Mar 9, 2024

Conversation

raszpl
Copy link
Contributor

@raszpl raszpl commented Mar 7, 2024

  • Update themes.js

fixing theme switching, it was totally borked for as long as I remember

  • Update themes.js

formatting

  • Update core.js

fixing theme switching

  • Update core.js

found another typo caused by bunched up code

  • Update core.js

rewritten for readability

  • Update init.js

redundant call

  • functions.js formatting, indentation, added setPrefCookieValueByName

added safe setPrefCookieValueByName(name, value) for setting Cookie PREF parameters without manually grepping and messing things up. Called with empty "value" deletes "name" from PREF. Makes sure to preserve & where needed, sanitizes PREF removing broken elements.

  • Update themes.js

switching PREF cookie handling to safe setPrefCookieValueByName()

  • Update settings.js

formatting, youtubeLanguage switched to safe setPrefCookieValueByName() and fixed #2082

* Update themes.js

fixing theme switching, it was totally borked for as long as I remember

* Update themes.js

formatting

* Update core.js

fixing theme switching

* Update core.js

found another typo caused by bunched up code

* Update core.js

rewritten for readability

* Update init.js

redundant call
@ImprovedTube
Copy link
Member

Last time I tried I think a year ago I couldnt switch from dark back to default without reloading page, now fixed.

yay 👍🏿

Also Themes dont change color of Comment field background.

what css selector?

redundant call

otherwise it is only called by shortcut or when changing settings. https://github.com/search?q=repo%3Acode-charity%2Fyoutube%20myColors()&type=code

caused by bunched up code

by not using debugger ;;)

Im guessing a ton of users have corrupted cookie

with what side-effect/s?
dark mode works by the cookie only in both directions(?)
( At need we could 🤔 try to read / click the top right menu of youtube, or considered whats set there in a different way. )

Shortcut switching to dark mode is also super janky. I dont think it works.

while 🤔 permanent & shortcut can use the same code / fixes..?

// FEEDBACK WHEN THE USER CHANGED A SETTING

// FEEDBACK WHEN THE USER CHANGES A SETTING (Not needed for pure CSS features, automated already)

Some themes are weird or broken, like Desert - is it supposed to be blue yellow? because its only blue and white.

always was 😃 (one interpretation: it's white /faint with a grey-green header, kinda like desert, while the designer didn't like the bright 'cartoon colors' from the preview on the whole screen)

@raszpl
Copy link
Contributor Author

raszpl commented Mar 7, 2024

Also Themes dont change color of Comment field background.

what css selector?

the box with comments, all themes leave it while

otherwise it is only called by shortcut

shortcut are broken, im fixing them now

or when changing settings.

this patch fixes that

https://github.com/search?q=repo%3Acode-charity%2Fyoutube%20myColors()&type=code

I combined it with theme switching

caused by bunched up code

by not using debugger ;;)

no, its spaghetti code. Seriously read Linux Coding Style guidebook https://www.kernel.org/doc/html/v4.10/process/coding-style.html It was designed to minimize errors and ease code review and is used by hundreds of thousands of coders beyond Linux project.

Im guessing a ton of users have corrupted cookie

with what side-effect/s?

I didnt notice any, but this code as it is now or at some point in the past was copying whole PREF cookie into itself, my PREF cookie was 7 copies when I just looked, and had no F6 at all. Cookie ended with "...000&f5=30030&400" Its a big fail.

dark mode works by the cookie only in both directions(?) ( At need we could 🤔 try to read / click the top right menu of youtube, or considered whats set there in a different way. )

Are you sure F6 does anything? like I said I tried setting it manually and reloading YT watch page with no effect on colors in Chrome/Vivaldi.

Some themes are weird or broken, like Desert - is it supposed to be blue yellow? because its only blue and white.

always was 😃 (one interpretation: it's white /faint with a grey-green header, kinda like desert, while the designer didn't like the bright 'cartoon colors' from the preview on the whole screen)

Its certainly an acquired taste.

@ImprovedTube
Copy link
Member

the box with comments, all themes leave it while

not yet here

shortcut are broken, im fixing them now

👍🏿

I combined it with theme switching

where?

spaghetti code

long lines !== spaghetti

certainly an acquired taste.

(we can add another theme and sync previews with the colors to be on YouTube)

@raszpl
Copy link
Contributor Author

raszpl commented Mar 7, 2024

shortcut are broken, im fixing them now

for example

ImprovedTube.shortcutReport = function () {

just does this for me

Failed to load resource: net::ERR_NAME_NOT_RESOLVED
shortcuts.js:599 '...' failed
shortcuts.js:600 '...' failed2
shortcuts.js:603 report failed
shortcuts.js:604 report failed2
shortcuts.js:604 Uncaught TypeError: Cannot read properties of null (reading 'closest')
    at shortcuts.js:604:107

because its doing risky stuff in the catch and not try scope.

  • Old shortcuts are being triggered even after disabling, there is something seriously wrong there.
  • when using themes, for example Night one, shortcut letters are readable in the list, but become white on white in the "press key to configure it" popup

@raszpl
Copy link
Contributor Author

raszpl commented Mar 7, 2024

Also Themes dont change color of Comment field background.

what css selector?

<ytd-comments id="comments" class="style-scope ytd-watch-flexy">

@raszpl
Copy link
Contributor Author

raszpl commented Mar 8, 2024

Are you sure F6 does anything? like I said I tried setting it manually and reloading YT watch page with no effect on colors in Chrome/Vivaldi.

Im gonna correct myself. F6 does indeed work. Its all clear after manually Fixing PREF cookie
&f6=80000 = Google light theme
&f6=400 = Google dark theme
no F6 = Device theme

This is why I was seeing:

Also Themes dont change color of Comment field background.

what css selector?

<ytd-comments id="comments" class="style-scope ytd-watch-flexy">

By switching Youtube theme with cookie this gets taken care of with YT CSS, but:

Im guessing a ton of users have corrupted cookie

with what side-effect/s?

I didnt notice any

so my corrupted cookie was preventing YT from applying dark theme properly

@ImprovedTube ImprovedTube added the Knowledge Base / Documentation for contributors We should repurpose this for future reference / Wiki / Education / Introduction label Mar 8, 2024
@ImprovedTube
Copy link
Member

thank you!

... search ... shortcuts ... fixing

#1565

(of course this post is extensive since i'm an extension)


corrupted cookie

(Maybe we could fix cookies)

@raszpl raszpl mentioned this pull request Mar 8, 2024
@raszpl
Copy link
Contributor Author

raszpl commented Mar 8, 2024

Cookie is regenerated by YT when switching themes. We can totally also fix it when switching our themes.
edit: heh, switching themes a couple times in a row I just ended with PREF = 400&hl=en&gl=.....&400&400&400&f6=400

source of cookie bug:

cookieValue = pref.replace(/(f6=)[^\&]+/, cookieValue);

"hl=en&f100=30&f6=400".replace(/(f6=)[^\&]+/, "400")
'hl=en&f100=30&400'

fix is ".replace(/([&]?f6=)[^\&]+/,'')". I suspect this started out as part of bigger code that was also setting cookieValue='' as that would make some sense.

and this is how whole cookie thing should be handled in the first place

var hl = this.getParam(pref, 'hl');
if (hl) {
this.setCookie('PREF', pref.replace('hl=' + hl, 'hl=' + value));
} else {
this.setCookie('PREF', pref + '&hl=' + value);
}

raszpl added 4 commits March 8, 2024 18:48
added setPrefCookieValueByName(name, value) for setting Cookie PREF parameters without manually grepping and messing things up.
Called with empty "value" deletes "name" from PREF. Makes sure to preserve & where needed, sanitizes PREF removing broken elements.
switching PREF cookie handling to safe setPrefCookieValueByName()
formatting, youtubeLanguage switched to safe setPrefCookieValueByName() and fixed #2082
@raszpl
Copy link
Contributor Author

raszpl commented Mar 8, 2024

Added whole new ImprovedTube.setPrefCookieValueByName = function (name, value)
It doesnt include regexes and is safe to cookies. Wont corrupt and will automagically sanitize previously broken ones.
Calling ImprovedTube.setPrefCookieValueByName('f6', 400)
edits or creates new f6
Calling ImprovedTube.setPrefCookieValueByName('f6', null) or ('f6', '')
removes f6.
Current implementation in master is broken, leaves &400 or 400& in PREF cookie, and has potential of creating PREF starting with "&f6=400".

@Anoaxx
Copy link

Anoaxx commented Mar 9, 2024

Tbh @raszpl i wasnt here for only a week and u did more work then entire extension for month xD

@ImprovedTube ImprovedTube merged commit fa32a1b into code-charity:master Mar 9, 2024
@ImprovedTube
Copy link
Member

i think we can test all your changes with many/all users tomorrow.

( btw, this handler & observer optimization attempt is currently undone in the chrome store, because we couldn't be sure, if it increased uninstalls (unless that was just YouTube's big experiment moving video details to the right sidebar) . so i guess i will just undo it again to test your changes alone.

mutation handler

mutation observer

)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Knowledge Base / Documentation for contributors We should repurpose this for future reference / Wiki / Education / Introduction
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cant set Youtube language back to default
3 participants