|
751 | 751 | }); |
752 | 752 | }; |
753 | 753 |
|
754 | | - const titleId = unorderedList.querySelector('[data-film-id]')?.getAttribute('data-film-id'); |
| 754 | + let filmPosterSelector; |
| 755 | + |
| 756 | + let titleId = unorderedList.querySelector('[data-film-id]')?.getAttribute('data-film-id'); |
755 | 757 | log(DEBUG, 'titleId', titleId); |
756 | | - if (titleId) userscriptLink.setAttribute('data-film-id', titleId); |
757 | 758 |
|
758 | | - const filmPoster = document.querySelector(`[data-film-id='${titleId}'].film-poster`); |
| 759 | + if (titleId) { |
| 760 | + filmPosterSelector = `[data-film-id='${titleId}'].film-poster`; |
| 761 | + } else { |
| 762 | + const titleName = unorderedList.querySelector('[data-film-name]')?.getAttribute('data-film-name'); |
| 763 | + log(DEBUG, 'titleName', titleName); |
| 764 | + |
| 765 | + if (titleName) { |
| 766 | + filmPosterSelector = `[data-film-name='${titleName}'].film-poster`; |
| 767 | + } else { |
| 768 | + logError('No film id or name found in unordered list'); |
| 769 | + return; |
| 770 | + } |
| 771 | + } |
| 772 | + |
| 773 | + log(DEBUG, 'filmPosterSelector', filmPosterSelector); |
| 774 | + const filmPoster = document.querySelector(filmPosterSelector); |
759 | 775 | log(DEBUG, 'filmPoster', filmPoster); |
760 | 776 |
|
| 777 | + if (!titleId) { |
| 778 | + titleId = filmPoster?.getAttribute('data-film-id'); |
| 779 | + log(DEBUG, 'titleId', titleId); |
| 780 | + |
| 781 | + if (!titleId) { |
| 782 | + logError('No film id found on film poster'); |
| 783 | + return; |
| 784 | + } |
| 785 | + } |
| 786 | + |
| 787 | + userscriptLink.setAttribute('data-film-id', titleId); |
| 788 | + |
761 | 789 | if (!filmPoster) { |
762 | 790 | logError('No film poster found'); |
763 | 791 | log(INFO, 'unorderedList', unorderedList); |
764 | 792 | } |
765 | 793 |
|
766 | 794 | const titleSlug = |
767 | 795 | unorderedList.querySelector('[data-film-slug]')?.getAttribute('data-film-slug') |
768 | | - || filmPoster.getAttribute('data-film-slug'); |
| 796 | + || filmPoster?.getAttribute('data-film-slug'); |
769 | 797 | log(DEBUG, 'titleSlug', titleSlug); |
| 798 | + |
770 | 799 | if (titleSlug) userscriptLink.setAttribute('data-film-slug', titleSlug); |
771 | 800 |
|
772 | 801 | const titleName = unorderedList.querySelector('[data-film-name]')?.getAttribute('data-film-name'); |
|
0 commit comments