|
1 | 1 | // ==UserScript== |
2 | 2 | // @name YouTube Music Save to Playlist filter |
3 | 3 | // @namespace fred.vatin.ytm-playlists-filter |
4 | | -// @version 1.0.0 |
| 4 | +// @version 1.0.1 |
5 | 5 | // @description Tap P key to open the “save to playlist” menu where your can type to filter |
6 | 6 | // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com |
7 | 7 | // @author Fred Vatin |
|
345 | 345 | for (const mutation of mutationsList) { |
346 | 346 | const AriaHidden = mutation.target.ariaHidden; |
347 | 347 |
|
348 | | - // console.log( |
349 | | - // `mutation type: ${mutation.type}, AriaHidden: ${AriaHidden}, attribute changed: ${mutation.attributeName}`, |
350 | | - // mutation.target |
351 | | - // ); |
| 348 | + console.log( |
| 349 | + `callback_MenuOpen triggered. mutation type: ${mutation.type}, AriaHidden: ${AriaHidden}, attribute changed: ${mutation.attributeName}`, |
| 350 | + mutation.target |
| 351 | + ); |
352 | 352 |
|
353 | 353 | if (!AriaHidden) { |
354 | 354 | setFocus(InputId); |
|
562 | 562 |
|
563 | 563 | // Collect all items |
564 | 564 | listItems = Array.from(playlists.querySelectorAll(selector_ListItems)); |
565 | | - console.log("✅ autoTopList(playlist), listItems number: ", listItems.length); |
| 565 | + console.log("✅ autoTopList(playlists), listItems number: ", listItems.length); |
566 | 566 |
|
567 | 567 | // Separates the selected ones from the rest |
568 | 568 | const selected = listItems.filter((item) => item.querySelector(selector_SelItems)); |
569 | 569 | const unselected = listItems.filter((item) => !item.querySelector(selector_SelItems)); |
570 | 570 |
|
571 | 571 | if (selected.length > 0) { |
572 | | - console.log(`✅ autoTopList(playlist), this video belongs to ${selected.length} playlist(s)`); |
| 572 | + console.log(`✅ autoTopList(playlists), this video belongs to ${selected.length} playlist(s)`); |
573 | 573 | // Reinsert in the desired order |
574 | 574 | [...selected, ...unselected].forEach((item) => { |
575 | 575 | playlists.appendChild(item); |
576 | 576 | }); |
577 | 577 |
|
578 | | - console.log(`✅ autoTopList(playlist), playlists have been sorted.`); |
| 578 | + console.log(`✅ autoTopList(playlists), playlists have been sorted.`); |
579 | 579 |
|
580 | 580 | const sortedItems = Array.from(playlists.querySelectorAll(selector_ListItems)); |
581 | | - console.log("✅ autoTopList(playlist), sortedItems number: ", sortedItems.length); |
| 581 | + console.log("✅ autoTopList(playlists), sortedItems number: ", sortedItems.length); |
582 | 582 | } else { |
583 | 583 | console.log( |
584 | | - "❌ autoTopList(playlist): this video doesn’t belong to any existing playlist. Not sorting needed." |
| 584 | + "❌ autoTopList(playlists): this video doesn’t belong to any existing playlist. Not sorting needed." |
585 | 585 | ); |
586 | 586 | } |
587 | 587 | } |
|
593 | 593 | * |
594 | 594 | * @param {string} el - The ID of the input element to focus. |
595 | 595 | */ |
596 | | - function setFocus(el) { |
| 596 | + async function setFocus(el) { |
597 | 597 | const input = document.getElementById(el); |
598 | 598 | if (input) { |
599 | 599 | // reset filter |
|
610 | 610 | const timeout = 100; |
611 | 611 | console.log(`✅ "input" found. Set focus! Timeout = ${timeout}`); |
612 | 612 | // delay required to set the focus |
613 | | - setTimeout(() => { |
614 | | - input.focus(); |
615 | | - }, timeout); |
| 613 | + await sleep(timeout); |
| 614 | + input.focus(); |
616 | 615 | } else { |
617 | 616 | console.log(`❌ "input" not found. Focus not set!`); |
618 | 617 | } |
|
0 commit comments