AO3 Length Comparator

Categorize fics and series by length as though they were published books. Additionally, categorize very long works by an equivalent published work.

目前為 2024-08-13 提交的版本,檢視 最新版本

// ==UserScript==
// @name         AO3 Length Comparator
// @namespace    http://tampermonkey.net/
// @version      2024-07-28
// @description  Categorize fics and series by length as though they were published books. Additionally, categorize very long works by an equivalent published work.
// @author       threeqc
// @license      GNU GPLv3
// @match        *://archiveofourown.org/*
// @match        *://www.archiveofourown.org/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant        none
// ==/UserScript==

// Settings
// =========
const show_comparison = true;
const comparison_lower_cutoff = 150000;
const comparison_upper_cutoff = 4500000;
// =========

function checkLength (length) {
    const examples = {
        "38000": "The Lion, The Witch, and The Wardrobe",
        "46118": "Fahrenheit 451",
        "59900": "Lord of the Flies",
        "60175": "The Color of Magic",
        "63766": "Brave New World",
        "66950": "Treasure Island",
        "67707": "The Sun Also Rises",
        "78462": "The Picture of Dorian Gray",
        "88942": "Nineteen Eighty-Four",
        "97364": "Anne of Green Gables",
        "100388": "To Kill A Mockingbird",
        "100609": "Ender's Game",
        "107945": "Wuthering Heights",
        "109185": "Good Omens",
        "109571": "The Adventures of Huckleberry Finn",
        "119394": "Sense and Sensibility",
        "129443": "The Odyssey",
        "134710": "Schindler's List",
        "138138": "20000 Leagues Under the Sea",
        "144523": "One Hundred Years of Solitude.",
        "147317": "The Iliad",
        "155960": "Oliver Twist",
        "156154": "Watership Down",
        "169481": "The Grapes of Wrath",
        "183149": "Great Expectations",
        "187240": "Dune",
        "188623": "American Gods",
        "206052": "Moby Dick",
        "211591": "Crime and Punishment",
        "257154": "The Goblet of Fire",
        "265000": "Ulysses",
        "292727": "A Game of Thrones",
        "301583": "Hunger Games Trilogy",
        "329150": "The Earthsea Cycle",
        "344000": "Chronicles of Narnia",
        "418453": "Gone With the Wind",
        "421080": "Percy Jackson Series",
        "439736": "Anna Karenina",
        "464162": "The Count of Monte Cristo",
        "483994": "Infinite Jest",
        "530982": "Les Miserables",
        "561996": "Atlas Shrugged",
        "563675": "To Green Angel Tower",
        "587246": "Twilight Series",
        "587287": "War and Peace",
        // Big gap
        "706574": "LoTR [w/ Silmarillion]",
        "790678": "Bible [KJV]",
        "838240": "Dune Series",
        "874557": "Homestuck [Text]", // adjusted estimates are all over the place
        "970000": "Clarissa",
        "1084625": "Harry Potter Series",
        "1100000": "Sironia, Texas",
        "1154971": "Umineko", // https://www.reddit.com/r/umineko/comments/ccvs6n/another_estimate_of_uminekos_word_count/
        "1267069": "In Search of Lost Time",
        "1736054": "A Song of Ice and Fire [1-5]",
        "1800000": "Mahabharata [est.]",
        "2000000": "Baldur's Gate 3", // you'd think guiness could get the precise number
        "2060240": "A Song of Ice and Fire [All]",
        "2363036": "Dresden Files Series",
        "2400000": "A Chronicle of Ancient Sunlight",
        "3327215": "Discworld Series",
        "3786250": "In the Realms of the Unreal",
        "4108915": "Riftwar Series",
        "4287886": "Wheel of Time Series",
    };

    length = length.replaceAll(',', '');
    let examplesarr = Object.keys(examples);
    const closest = examples[examplesarr.reduce((a, b) => {
        return Math.abs(b - length) < Math.abs(a - length) ? b : a;
    })];

    let designation;

    if (length <= 500) {
        designation = "Drabble";
    } else if (length <= 1500) {
        designation = "Flash Fiction";
    } else if (length <= 7500) {
        designation = "Short Story";
    } else if (length <= 17500) {
        designation = "Novelette";
    } else if (length <= 40000) {
        designation = "Novella";
    } else if (length <= 60000) {
        designation = "Short Novel";
    } else if (length <= 110000) {
        designation = "Novel";
    } else {
        designation = "Series: " + Math.max(Math.round(length/85000), 2) + "x Volumes" // different sources claim average novel length is 90000 or 80000. playing it safe.
    }

    if (show_comparison & (comparison_upper_cutoff >= length) & (length >= comparison_lower_cutoff)) {
        designation += ", " + closest;
    }

    return designation;
}

(function() {
    const wces = Array.from(document.querySelectorAll('dd.words'));
    var wcs = {};
    for (const [index, wc] of wces.entries()) {
        wc.innerText = wc.innerText + " (" + checkLength(wc.innerText) + ")";
    };
})();