Skip to content

Commit

Permalink
feat: use css :has() selector instead of JS detection (#123)
Browse files Browse the repository at this point in the history
* ♻️ Move podcast shelf and category logic to CSS

* Add VS Code launch configuration

* Add old style podcast genre selector for back-compat

* 🔥 Don't add podcast/audiobook i18n keys, since we don't use them anymore

* Add CSS to block "Your Episodes" in sidebar

* 🔥 Remove unused import

* Update deps

* Update `packageManager`

* ✨ Also hide other podcast-related search categories
  • Loading branch information
theRealPadster committed Jan 17, 2024
1 parent d3249a7 commit fa399de
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 186 deletions.
36 changes: 36 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "pnpm run watch",
"runtimeExecutable": "pnpm",
"runtimeArgs": [
"run",
"watch"
],
"internalConsoleOptions": "openOnSessionStart"
},
{
"type": "node",
"request": "launch",
"name": "spicetify watch -e",
"runtimeExecutable": "spicetify",
"runtimeArgs": [
"watch",
"-e"
],
"internalConsoleOptions": "openOnSessionStart"
}
],
"compounds": [
{
"name": "Watch app build and Spicetify",
"configurations": ["pnpm run watch", "spicetify watch -e"]
}
]
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"author": "theRealPadster",
"license": "GPL-3.0",
"packageManager": "pnpm@8.10.2",
"packageManager": "pnpm@8.14.1",
"scripts": {
"build": "spicetify-creator",
"build:local": "spicetify-creator --out=. --minify",
Expand All @@ -33,12 +33,12 @@
"devDependencies": {
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0",
"@typescript-eslint/eslint-plugin": "^6.17.0",
"@typescript-eslint/parser": "^6.17.0",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"eslint": "^8.56.0",
"eslint-plugin-react": "^7.33.2",
"husky": "^8.0.3",
"i18next": "^23.7.13",
"i18next": "^23.7.16",
"i18next-browser-languagedetector": "^7.1.0",
"react-i18next": "^14.0.0",
"spicetify-creator": "^1.0.17",
Expand Down
92 changes: 46 additions & 46 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 3 additions & 14 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,6 @@ async function main() {

console.debug('HidePodcasts: Loaded');

// Add translations for the "Podcasts" and "Audiobooks" genre card titles (for current language)
const podcastsTitle = Spicetify.Locale.get('search.title.shows');
const audiobooksTitle = Spicetify.Locale.get('search.title.audiobooks');
const lang = Spicetify.Locale.getLocale();
console.debug(`HidePodcasts: Adding translations for ${lang}:`, podcastsTitle, audiobooksTitle);
i18n.addResourceBundle(lang, 'translation',
{
'search.podcastsCardTitle': podcastsTitle,
'search.audiobooksCardTitle': audiobooksTitle,
}, true, true);

let isEnabled = getLocalStorageDataFromKey(SETTINGS_KEY, true);
let aggressiveMode = getLocalStorageDataFromKey(AGGRESSIVE_MODE_KEY, false);
let hideAudioBooks = getLocalStorageDataFromKey(AUDIOBOOKS_KEY, false);
Expand Down Expand Up @@ -139,8 +128,8 @@ async function main() {
// Run the app logic
function apply() {
setState({ podcasts: isEnabled, audiobooks: hideAudioBooks });
tagPodcasts(t);
tagAudioBooks(t);
tagPodcasts();
tagAudioBooks();
}

// Listen to page navigation and re-apply when DOM is ready
Expand All @@ -150,7 +139,7 @@ async function main() {
if (!mainElem) return; // ts protection

// Get the relevant selector to verify the current page has loaded
const appLoadedSelector = getPageLoadedSelector(t, pathname);
const appLoadedSelector = getPageLoadedSelector(pathname);
const app = mainElem.querySelector(appLoadedSelector);

if (app) {
Expand Down
72 changes: 61 additions & 11 deletions src/css/app.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,66 @@
// TODO: Need to add the queue-tabBar bit to block the Podcasts tab on the Your Library page
// Because it resets itself when the window resizes and it go in/out of the overflow menu
// Technically I should block the li.queue-tabBar-headerItem above it, but can't do that with just CSS
// TODO: Make a debug switch that just outlines everything it would block in red.

// General rules
.hide-podcasts-enabled .podcast-item {
display: none !important;
// The nearby shelves seem to freak out and constantly recalculate their positions if I use display: none
@mixin hide-visibility {
visibility: hidden;
height: 0;
min-height: unset;
margin: 0;
}
.hide-audiobooks-enabled .audiobook-item {

@mixin hide-display {
display: none !important;
}

// Podcasts tab in Your Library page
.hide-podcasts-enabled .queue-tabBar-header a[href="/collection/podcasts"] {
display: none !important;
};
.hide-podcasts-enabled {
// Items I've tagged via JS
.podcast-item {
@include hide-display();
}

// Podcasts tab in Your Library page
.queue-tabBar-header a[href="/collection/podcasts"] {
@include hide-display();
};

// Shelves that have podcasts in them
.main-shelf-shelf:has(a[href^="/episode/"]),
.main-shelf-shelf:has(a[href^="/show/"]) {
@include hide-visibility();
}

// Podcasts categories on search page
// Old style
.x-categoryCard-CategoryCard[href="/genre/podcasts-web"],
// == (Spotify 1.2.26.1187.g36b715a1) ==
// "Podcasts"
.x-categoryCard-CategoryCard[href="/genre/0JQ5DArNBzkmxXHCqFLx2J"],
// "Podcast Charts"
.x-categoryCard-CategoryCard[href="/genre/0JQ5DAB3zgCauRwnvdEQjJ"],
// "Educational"
.x-categoryCard-CategoryCard[href="/genre/0JQ5IMCbQBLl5gxKLgufp8"],
// "Documentary"
.x-categoryCard-CategoryCard[href="/genre/0JQ5IMCbQBLjfX9OdDrA5X"],
// "Comedy"
.x-categoryCard-CategoryCard[href="/genre/0JQ5IMCbQBLyUJhSxhaPc6"] {
@include hide-display();
}

// "Your Episodes" in sidebar
.main-yourLibraryX-listItem:has(#listrow-title-spotify\:collection\:your-episodes) {
@include hide-display();
}
}

.hide-audiobooks-enabled {
// Items I've tagged via JS
.audiobook-item {
@include hide-display();
}

// Audiobooks category on search page
// As of Spotify 1.2.26.1187.g36b715a1
.x-categoryCard-CategoryCard[href="/genre/0JQ5DAqbMKFETqK4t8f1n3"] {
@include hide-display();
}
}
Loading

0 comments on commit fa399de

Please sign in to comment.