<commit_before>/*!
 *
 * # BiB/i Extension: FontSize
 *
 * - "FontSize Utility: Users can change font-size. Publishers can change default font-size."
 * - Copyright (c) <NAME> - http://bibi.epub.link or https://github.com/satorumurmur/bibi
 * - Licensed under the MIT license. - http://www.opensource.org/licenses/mit-license.php
 *
 */

Bibi.x({

    name: "FontSize",
    description: "Font Size Optimizer for BiB/i",
    author: "<NAME> (@satorumurmur)",
    version: "1.1.0",
    build: Bibi["build"]

})(function() {

    if(typeof X.Presets.FontSize["scale-per-step"] != "number" || X.Presets.FontSize["scale-per-step"] <= 1) X.Presets.FontSize["scale-per-step"] = 1.25;

    if(S["use-cookie"]) {
        var BibiCookie = O.Cookie.remember(O.RootPath);
        if(BibiCookie && BibiCookie.FontSize && BibiCookie.FontSize.Step != undefined) X.FontSize.Step = BibiCookie.FontSize.Step * 1;
    }
    if(typeof X.FontSize.Step != "number" || X.FontSize.Step < -2 || 2 < X.FontSize.Step) X.FontSize.Step = 0;

    O.appendStyleSheetLink({
        className: "bibi-extension-stylesheet",
        id: "bibi-extension-stylesheet_FontSize",
        href: O.RootPath + "extensions/fontsize/fontsize.css"
    });

    X.FontSize.changeItemFontSize = function(Item, FontSize) {
        if(Item.FontSizeStyleRule) sML.CSS.deleteRule(Item.FontSizeStyleRule, Item.contentDocument);
        Item.FontSizeStyleRule = sML.CSS.appendRule("html", "font-size: " + FontSize + "px !important;", Item.contentDocument);
    };
    X.FontSize.changeItemFontSizeStep = function(Item, Step) {
        X.FontSize.changeItemFontSize(Item, Item.FontSize.Base * Math.pow(X.Presets.FontSize["scale-per-step"], Step));
    };

    E.bind("bibi:postprocessed-item-content", function(Item) {
        Item.FontSize = {
            Default: getComputedStyle(Item.HTML).fontSize.replace(/[^\d]*$/, "") * 1
        };
        Item.FontSize.Base = Item.FontSize.Default;
        if(sML.UA.InternetExplorer && L.Preprocessed) {
            Array.prototype.forEach.call(Item.contentDocument.documentElement.querySelectorAll("body, body *"), function(Ele) {
                Ele.style.fontSize = parseInt(getComputedStyle(Ele).fontSize) / Item.FontSize.Base + "rem";
            });
        } else {
            O.editCSSRules(Item.contentDocument, function(CSSRule) {
                if(!CSSRule || !CSSRule.selectorText || /^@/.test(CSSRule.selectorText)) return;
                try { if(Item.contentDocument.querySelector(CSSRule.selectorText) == Item.HTML) return; } catch(Error) {}
                var REs = {
                    "pt": / font-size: (\d[\d\.]*)pt; /,
                    "px": / font-size: (\d[\d\.]*)px; /
                };
                if(REs["pt"].test(CSSRule.cssText)) CSSRule.style.fontSize = CSSRule.cssText.match(REs["pt"])[1] * (96/72) / Item.FontSize.Base + "rem";
                if(REs["px"].test(CSSRule.cssText)) CSSRule.style.fontSize = CSSRule.cssText.match(REs["px"])[1]           / Item.FontSize.Base + "rem";
            });
        }
        if(typeof X.Presets.FontSize["base"] == "number" && X.Presets.FontSize["base"] > 0) {
            var MostPopularFontSize = 0;
            var FontSizeCounter = {};
            sML.each(Item.Body.querySelectorAll("p, p *"), function() {
                if(!this.innerText.replace(/\s/g, "")) return;
                var FontSize = Math.round(getComputedStyle(this).fontSize.replace(/[^\d]*$/, "") * 100) / 100;
                if(!FontSizeCounter[FontSize]) FontSizeCounter[FontSize] = [];
                FontSizeCounter[FontSize].push(this);
            });
            var MostPopularFontSizeAmount = 0;
            for(var FontSize in FontSizeCounter) {
                if(FontSizeCounter[FontSize].length > MostPopularFontSizeAmount) {
                    MostPopularFontSizeAmount = FontSizeCounter[FontSize].length;
                    MostPopularFontSize = FontSize;
                }
            }<commit_msg>Fix an issue that zipped EPUBs can't be opened with Chrome 65+.<commit_after>/*!
 *
 * # BiB/i Extension: FontSize
 *
 * - "FontSize Utility: Users can change font-size. Publishers can change default font-size."
 * - Copyright (c) <NAME> - http://bibi.epub.link or https://github.com/satorumurmur/bibi
 * - Licensed under the MIT license. - http://www.opensource.org/licenses/mit-license.php
 *
 */

Bibi.x({

    name: "FontSize",
    description: "Font Size Optimizer for BiB/i",
    author: "<NAME> (@satorumurmur)",
    version: "1.1.0",
    build: Bibi["build"]

})(function() {

    if(typeof X.Presets.FontSize["scale-per-step"] != "number" || X.Presets.FontSize["scale-per-step"] <= 1) X.Presets.FontSize["scale-per-step"] = 1.25;

    if(S["use-cookie"]) {
        var BibiCookie = O.Cookie.remember(O.RootPath);
        if(BibiCookie && BibiCookie.FontSize && BibiCookie.FontSize.Step != undefined) X.FontSize.Step = BibiCookie.FontSize.Step * 1;
    }
    if(typeof X.FontSize.Step != "number" || X.FontSize.Step < -2 || 2 < X.FontSize.Step) X.FontSize.Step = 0;

    O.appendStyleSheetLink({
        className: "bibi-extension-stylesheet",
        id: "bibi-extension-stylesheet_FontSize",
        href: O.RootPath + "extensions/fontsize/fontsize.css"
    });

    X.FontSize.changeItemFontSize = function(Item, FontSize) {
        if(Item.FontSizeStyleRule) sML.CSS.deleteRule(Item.FontSizeStyleRule, Item.contentDocument);
        Item.FontSizeStyleRule = sML.CSS.appendRule("html", "font-size: " + FontSize + "px !important;", Item.contentDocument);
    };
    X.FontSize.changeItemFontSizeStep = function(Item, Step) {
        X.FontSize.changeItemFontSize(Item, Item.FontSize.Base * Math.pow(X.Presets.FontSize["scale-per-step"], Step));
    };

    E.bind("bibi:postprocessed-item-content", function(Item) {
        Item.FontSize = {
            Default: getComputedStyle(Item.HTML).fontSize.replace(/[^\d]*$/, "") * 1
        };
        Item.FontSize.Base = Item.FontSize.Default;
        if(L.Preprocessed && (sML.UA.Chrome || sML.UA.InternetExplorer)) {
            Array.prototype.forEach.call(Item.contentDocument.documentElement.querySelectorAll("body, body *"), function(Ele) {
                Ele.style.fontSize = parseInt(getComputedStyle(Ele).fontSize) / Item.FontSize.Base + "rem";
            });
        } else {
            O.editCSSRules(Item.contentDocument, function(CSSRule) {
                if(!CSSRule || !CSSRule.selectorText || /^@/.test(CSSRule.selectorText)) return;
                try { if(Item.contentDocument.querySelector(CSSRule.selectorText) == Item.HTML) return; } catch(Error) {}
                var REs = {
                    "pt": / font-size: (\d[\d\.]*)pt; /,
                    "px": / font-size: (\d[\d\.]*)px; /
                };
                if(REs["pt"].test(CSSRule.cssText)) CSSRule.style.fontSize = CSSRule.cssText.match(REs["pt"])[1] * (96/72) / Item.FontSize.Base + "rem";
                if(REs["px"].test(CSSRule.cssText)) CSSRule.style.fontSize = CSSRule.cssText.match(REs["px"])[1]           / Item.FontSize.Base + "rem";
            });
        }
        if(typeof X.Presets.FontSize["base"] == "number" && X.Presets.FontSize["base"] > 0) {
            var MostPopularFontSize = 0;
            var FontSizeCounter = {};
            sML.each(Item.Body.querySelectorAll("p, p *"), function() {
                if(!this.innerText.replace(/\s/g, "")) return;
                var FontSize = Math.round(getComputedStyle(this).fontSize.replace(/[^\d]*$/, "") * 100) / 100;
                if(!FontSizeCounter[FontSize]) FontSizeCounter[FontSize] = [];
                FontSizeCounter[FontSize].push(this);
            });
            var MostPopularFontSizeAmount = 0;
            for(var FontSize in FontSizeCounter) {
                if(FontSizeCounter[FontSize].length > MostPopularFontSizeAmount) {
                    MostPopularFontSizeAmount = FontSizeCounter[FontSize].length;
                    MostPopularFontSize = FontSize;
                }
            }
{'fraction_non_alphanumeric': 0.16148370176095916, 'fraction_numerical': 0.006993880354689647, 'mean_word_length': 2.52, 'pattern_counts': {'":': 4, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5095482', 'n_tokens_mistral': 2631, 'n_tokens_neox': 2508, 'n_words': 378}