-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
More performant YouTube Logo hide option. #135
Conversation
Is it possible to just inject a stylesheet that hides the CSS class instead of re-applying the style change every X seconds? Does YouTube allow 'unsafe-inline' for style tags in its CSP header? |
I don't think I'm applying anything X seconds unless I'm missing something. |
Apologies. I've misinterpreted the code in my haste. Regardless, my question still stands out of curiosity at the very least. |
It'd probably be possible, but I think making the logo container opaque directly in the JavaScript is the simplest. Unless there is already a mechanism that loads stylesheets based on config options. |
Is it really necessary to call I'm assuming this is from the first call:
|
We already achieve the same goal of waiting for an element to be added before doing something to it here. |
That makes a lot more sense to me. Why does it look at attributes though? |
This works for me. async function logoHideShow() {
const logo = await waitForChildAdd(
document.getElementById('container'),
(node) => node.nodeName === 'YTLR-REDUX-CONNECT-YTLR-LOGO-ENTITY'
);
logo.style.opacity = configRead('hideLogo') ? '0' : '1';
}
logoHideShow();
I also disabled the attribute stuff in |
If the Mutation Observer doesn't fire on attribute change, one must carefully craft the predicate to only rely on properties that exist when the node is added. It's not worth trading the principle of least surprise for a handful of milliseconds faster startup. |
The name and description of In the single existing use of I might feel differently if anyone were actually using the attribute functionality. If it's not removed, it should at least be made optional. I'm not sure whether it should be enabled by default though. |
I'm not actually seeing a The version I'm currently using is based on |
In a perfect world, we would do this: body:has(#__hide_logo:checked) .ytlr-redux-connect-ytlr-logo-entity {
visibility: hidden !important;
} Which would mean we wouldn't need JS at all for this functionality. But too bad we're not in a perfect world because Method 1: toggle entire stylesheetCreate a new CSS file: .ytlr-redux-connect-ytlr-logo-entity {
visibility: hidden !important;
} And use it like so: const ele = document.createElement('link')
ele.rel = 'stylesheet'
// URL asset: https://webpack.js.org/guides/asset-modules/#url-assets
ele.href = new URL('./hide-ytlogo.css', import.meta.url)
document.head.appendChild(ele)
// `disabled` is available on `link[rel="stylesheet"]`
// See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#disabled
ele.disabled = !configRead('hideLogo') Method 2: toggle class on body
body.logo-hidden .ytlr-redux-connect-ytlr-logo-entity {
visibility: hidden !important;
} import './hide-ytlogo.css'
if (configRead('hideLogo'))
document.body.classList.add('logo-hidden')
else
document.body.classList.remove('logo-hidden') |
I don't think a separate CSS file is necessary. This seems to work in my testing: /**
* Initialize ability to hide YouTube logo in top right corner.
*/
function initHideLogo() {
const style = document.createElement('style');
document.head.appendChild(style);
/** @type {(hide: boolean) => void} */
const setHide = (hide) => {
const opacity = hide ? '0' : '1';
style.textContent = `ytlr-redux-connect-ytlr-logo-entity { opacity: ${opacity}; }`;
};
setHide(configRead('hideLogo'));
configAddChangeListener('hideLogo', (evt) => {
setHide(evt.detail.newValue);
});
} |
That also works too. Though visibility should be used instead of opacity so the element isn't interactable. |
Any objections to closing this in favor of #149? |
Looks good to me, happy to see this feature finally making it after all this time. |
This pull request adds an option to hide the YouTube logo from the top right corner of the app.
Me and the creator of youtube-webos-cobalt modified the code of #56 a while ago to work without the deprecated DOMNodeInserted event, thus making it more performant and up to date.