Last active
May 5, 2024 18:09
-
-
Save Vaviloff/e339f5a45016fcaaed61028fc717b401 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Litres: remove owned books from a collection page | |
| // @namespace http://tampermonkey.net/ | |
| // @version 2024-05-05 | |
| // @description Remove already owned books from offers | |
| // @author Vaviloff | |
| // @match https://www.litres.ru/collections/* | |
| // @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net | |
| // @grant none | |
| // ==/UserScript== | |
| function filter() { | |
| const buttons = [...document.querySelectorAll('div[class^="Button_textContainer"]')].filter(btn => btn.innerText.includes('Слушать')); | |
| const parentArtWrappers = buttons.map(button => button.closest('.ArtsGrid_artWrapper__LXa0O')).filter(Boolean); | |
| console.log(`Found ${parentArtWrappers.length} owned books`); | |
| parentArtWrappers.forEach(parentArtWrapper => { | |
| parentArtWrapper.remove(); | |
| }); | |
| wait(); | |
| } | |
| function wait() { | |
| if(document.querySelectorAll('a[data-testid="art__title"]').length === 0) { | |
| setTimeout(wait, 1000); | |
| } else { | |
| filter(); | |
| } | |
| } | |
| (function() { | |
| 'use strict'; | |
| wait(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment