<commit_before>const isVisible = require('./common_functions').isVisible;
const Url = require('./url');

const ScrollToAnchor = (() => {
    const init = () => {
        scrollToAnchorInQuery();
        addAnchorsToElements();
    };

    const makeAnchorLink = (id) => {
        const anchor_link = document.createElement('a');
        const url = new URL(window.location);
        url.search = `anchor=${encodeURI(id)}`;
        anchor_link.href = url.href;
        anchor_link.classList.add('data-anchor-link');
        return anchor_link;
    };

    const addAnchorsToElements = () => {
        const els = document.querySelectorAll('[data-anchor]');
        els.forEach(el => {
            const id = el.dataset.anchor;
            const anchor_link = makeAnchorLink(id);
            el.appendChild(anchor_link);
            anchor_link.addEventListener('click', (e) => {
                e.preventDefault();
                $.scrollTo(el, 500);
                const params = Url.paramsHash();
                params.anchor = window.encodeURI(id);
                Url.setQueryStringWithoutReload(
                    Url.paramsHashToString(params)
                );
            });
        });
    };

    const scrollToAnchorInQuery = () => {
        const params = Url.paramsHash();
        const id = window.decodeURI(params.anchor);
        if (!id) return;
        const candidates = document.querySelectorAll(`[data-anchor="${id}"]`);
        const el = Array.from(candidates).find(isVisible);
        if (!el) return;
        $.scrollTo(el, 500);
    };

    const cleanup = () => {
        const params = Url.paramsHash();
        delete params.anchor;
        const new_query_string = Url.paramsHashToString(params);
        Url.setQueryStringWithoutReload(new_query_string);<commit_msg>custom encode function<commit_after>const isVisible = require('./common_functions').isVisible;
const Url = require('./url');

const ScrollToAnchor = (() => {
    const init = () => {
        addAnchorsToElements();
        scrollToAnchorInQuery();
    };

    const encode = (str) => {
        const prep = str.toLowerCase().replace(/\s/g, '-');
        return encodeURI(prep);
    };

    const makeAnchorLink = (id) => {
        const anchor_link = document.createElement('a');
        const url = new URL(window.location);
        url.search = `anchor=${id}`;
        anchor_link.href = url.href;
        anchor_link.classList.add('data-anchor-link');
        return anchor_link;
    };

    const addAnchorsToElements = () => {
        const els = document.querySelectorAll('[data-anchor]');
        els.forEach(el => {
            const title = el.dataset.anchor;
            const id = encode(title);
            el.dataset.anchor = id;
            const anchor_link = makeAnchorLink(id);
            el.appendChild(anchor_link);
            anchor_link.addEventListener('click', (e) => {
                e.preventDefault();
                $.scrollTo(el, 500);
                const params = Url.paramsHash();
                params.anchor = id;
                Url.setQueryStringWithoutReload(
                    Url.paramsHashToString(params)
                );
            });
        });
    };

    const scrollToAnchorInQuery = () => {
        const params = Url.paramsHash();
        const id = params.anchor;
        if (!id) return;
        const candidates = document.querySelectorAll(`[data-anchor="${id}"]`);
        const el = Array.from(candidates).find(isVisible);
        if (!el) return;
        $.scrollTo(el, 500);
    };

    const cleanup = () => {
        const params = Url.paramsHash();
        delete params.anchor;
        const new_query_string = Url.paramsHashToString(params);
        Url.setQueryStringWithoutReload(new_query_string);
{'fraction_non_alphanumeric': 0.136158940397351, 'fraction_numerical': 0.0031788079470198675, 'mean_word_length': 2.0976210008203444, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1448322', 'n_tokens_mistral': 1059, 'n_tokens_neox': 1027, 'n_words': 188}