Skip to content

Commit 9b022ee

Browse files
committed
fix: P could not open the direct access save button
closes #3
1 parent b090a41 commit 9b022ee

1 file changed

Lines changed: 37 additions & 7 deletions

File tree

user script/yt-playlist-filter.user.js

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name YouTube Save to Playlist filter
33
// @namespace fred.vatin.yt-playlists-filter
4-
// @version 1.1.0
4+
// @version 1.1.1
55
// @description Tap P key to open the “save to playlist” menu where your can type to filter
66
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
77
// @author Fred Vatin, Flemming Steffensen
@@ -25,10 +25,12 @@
2525
const SHORTKEY = "KeyP"; // if you want to set a modifier key shortcut, edit the handlePlaylistKey function
2626

2727
// Add your language for the Save menu entry name
28-
// 1. Play a video
29-
// 2. Click the menu button where there is the "save to playlist" menu entry
30-
// 3. In the dev tool > inspector, search for the selector: yt-button-shape > button[aria-label]
31-
// It should be around the 7th match. Copy the [aria-label] value.
28+
// - Play a video
29+
30+
// First case scenario: the "save to playlist" button is in the "…" sub-menu
31+
// 1. Click the "…" menu button where there is the "save to playlist" menu entry
32+
// 2. In the dev tool > inspector, search for the selector: yt-button-shape > button[aria-label]
33+
// It should be around the 7th match. Copy the [aria-label] value and add it here.
3234
const MoreActionsButtonText = [
3335
"More actions",
3436
"Autres actions",
@@ -37,10 +39,24 @@
3739
"Altre azioni",
3840
"Mais ações",
3941
];
40-
// 4. search for the selector: #items > ytd-menu-service-item-renderer yt-formatted-string
42+
// 3. search for the selector: #items > ytd-menu-service-item-renderer yt-formatted-string
4143
// copy the text content
4244
const SaveButtonText = ["Save", "Enregistrer", "Speichern", "Guardar", "Salva"];
4345

46+
// Second case scenario, the "Save" to playlist button is in direct access
47+
// 1. In the dev tool > inspector, search for the selector: .ytSpecButtonViewModelHost button[aria-label]
48+
// until your find the one for the save to playlist.
49+
// 2. It should be around the 7th match. Copy the [aria-label] value and add it here.
50+
const DirectSaveButtonText = [
51+
"Save to playlist",
52+
"Enregistrer dans une playlist",
53+
"Zu Playlist hinzufügen",
54+
"Añadir a lista de reproducción",
55+
"Salva in una playlist",
56+
"Salvar na playlist",
57+
"Guardar na playlist",
58+
];
59+
4460
/**==========================================================================
4561
* ℹ GLOBAL DEFINITION
4662
===========================================================================*/
@@ -467,10 +483,23 @@
467483
* @returns {void}
468484
*/
469485
function openSaveToPlaylistDialog() {
470-
const directSaveButton = document.querySelector('yt-button-shape button[aria-label="Save to playlist"]');
486+
let directSaveButton = null;
487+
for (const text of DirectSaveButtonText) {
488+
const selector = `.ytSpecButtonViewModelHost button[aria-label="${text}"]`;
489+
directSaveButton = document.querySelector(selector);
490+
if (directSaveButton) {
491+
break;
492+
}
493+
}
494+
471495
if (directSaveButton) {
496+
console.log("✅ openSaveToPlaylistDialog(), direct save button found. Click it");
472497
directSaveButton.click();
473498
} else {
499+
console.log(
500+
"❌ openSaveToPlaylistDialog(), direct save button NOT found. Search for More Actions menu"
501+
);
502+
474503
let moreActionsButton = null;
475504
for (const text of MoreActionsButtonText) {
476505
const selector = `yt-button-shape > button[aria-label="${text}"]`;
@@ -481,6 +510,7 @@
481510
}
482511

483512
if (moreActionsButton) {
513+
console.log("✅ openSaveToPlaylistDialog(), More Actions menu found. Click it");
484514
moreActionsButton.click();
485515
setTimeout(() => {
486516
const submenuItems = document.querySelectorAll(

0 commit comments

Comments
 (0)