Greasy Fork

Greasy Fork is available in English.

Goodreads, show only the standalones in lists

Add a checkbox to Goodreads list pages that allows you to hide books that belong to series

目前为 2023-10-29 提交的版本,查看 最新版本

// ==UserScript==
// @name         Goodreads, show only the standalones in lists
// @version      0.1
// @description  Add a checkbox to Goodreads list pages that allows you to hide books that belong to series
// @author       anothershm
// @match        *://*.goodreads.com/review/list/*
// @grant       GM_setValue
// @grant       GM_getValue
// @license     MIT
// @namespace http://greasyfork.icu/users/1206936
// ==/UserScript==

(function() {
'use strict';
    var newDiv = document.createElement('div');
    newDiv.innerHTML = '<input type="checkbox" id="showCore" name="showcb"> <label for="showCore">Show only standalones</label>';
    newDiv.style.display = 'inline';
    newDiv.style.paddingLeft = '10px';
    document.querySelector('#controls').appendChild(newDiv);
    var cb = newDiv.firstChild;
    cb.checked = GM_getValue('gr_showStandalone', false);
    showStandalone(cb.checked);
    cb.addEventListener('change', (evt) => {
        showStandalone(cb.checked);
        GM_setValue('gr_showStandalone', cb.checked);
    });

    function showStandalone(show) {
        var allRows = Array.from(document.querySelectorAll('.bookalike'));
        console.log('all rows', allRows);
        if (!show) {
            allRows.forEach((el) => { el.hidden = false; });
        } else {
            var notmatching = allRows.filter((el) => {
                console.log(el.querySelector('.title'));
                const pattern = /\(.*#(\d+)\)/; // Regular expression to match text with "#number" pattern
                return el.querySelector('.title').innerHTML.match(pattern)
            });
            //console.log('not matching', notmatching);
            if (notmatching.length !== allRows.length) {
                notmatching.forEach((el) => { el.hidden = true; });
            }
        }
    }
})();