AO3 Filter Bookmarks By Length

Script to filter bookmarks based on word count. Edit min_len and max_len to taste.

目前為 2024-03-22 提交的版本,檢視 最新版本

// ==UserScript==
// @name         AO3 Filter Bookmarks By Length
// @namespace    https://greasyfork.org/en/users/296127-doleful-shades
// @version      0.1
// @description  Script to filter bookmarks based on word count. Edit min_len and max_len to taste.
// @author       dolefulshades
// @match      http://archiveofourown.org/*bookmarks*
// @match      https://archiveofourown.org/*bookmarks*
// @grant    none
// @license    MIT
// ==/UserScript==

// minimum length
var min_len = 0;

// maximum length
var max_len = Infinity;

var min_chap = 0;
var max_chap = Infinity;



(function($) {
    var words = $(".bookmarks-index .blurb .stats dt:contains('Words:')"); //all "Words:" descriptors before word count
    for(var i=0;i<$(words).length;i++){
        //loop through all 'word' descriptor html objs
        var len = $($(words)[i].nextElementSibling).text().replace(',',''); //get word count for each work as number
        var chap = $($(words)[i]).siblings("dt:contains('Chapters:')"); // get 'Chapters:" html object
        var numchaps = $(chap).next('dd').text().split('/')[0].replace(',',''); //get chapter count as number

        if (true && len < min_len||len > max_len) {
            //if the word count does not fall between min_len and max_len, hide the work
            $($(words)[i]).closest('.bookmarks-index .blurb').hide();
        }
        else if(numchaps && numchaps < min_chap|| numchaps > max_chap){
            //if chapter count does not fall btwn min and max chaps
            $($(words)[i]).closest('.bookmarks-index .blurb').hide();
        }
    }

})(window.jQuery);