Skip to content

Instantly share code, notes, and snippets.

@Vaviloff
Last active May 5, 2024 18:09
Show Gist options
  • Select an option

  • Save Vaviloff/e339f5a45016fcaaed61028fc717b401 to your computer and use it in GitHub Desktop.

Select an option

Save Vaviloff/e339f5a45016fcaaed61028fc717b401 to your computer and use it in GitHub Desktop.
// ==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