<commit_before>// ==UserScript==
// @name         Wikipedia - Toggle Sidebar
// @description  Adds a small button to hide or show the sidebar. Makes reading easier.
// @version      0.2.0
// @author       <NAME>
// @namespace    https://github.com/arthurhammer
// @license      MIT
// @homepage     https://github.com/arthurhammer/userscripts/tree/master/Wikipedia_ToggleSidebar
// @updateURL    https://github.com/arthurhammer/userscripts/raw/master/Wikipedia_ToggleSidebar/wikipedia_toggle-sidebar.user.js
// @downloadURL  https://github.com/arthurhammer/userscripts/raw/master/Wikipedia_ToggleSidebar/wikipedia_toggle-sidebar.user.js
// @match        *.wikipedia.org/wiki/*
// @run-at       document-body
// @grant        none
// ==/UserScript==

(function() {

    var prefs = {
        hiddenByDefault: true
    };

    function rotate(element, degrees) {
        var rotation = 'rotate(' + degrees + 'deg)';
        element.style.WebkitTransform = rotation;
        element.style.transform = rotation;
    }

    function addCSS(css) {
        var style = document.createElement('style');
        style.textContent = css;
        document.head.appendChild(style);
    }

    var css = '\
        body { \
            background-color: white; \
        } \
        #content { \
            border-color: #ddd; \
            border-left-width: 0; \
            margin-left: 5em;    /* TODO: smaller margin for smaller widths */ \
            margin-right: 5em; \
        } \
        #content.with-sidebar { \
            margin-left: 10em; \
            margin-right: 0em; \
        } \
        #mw-panel { \
            display: none; \
        } \
        #sidebar-toggle { \
            position: absolute; \
            top: 0; \
            left: 5; \
            z-index: 999; \
            padding: 10px; \
            font-size: 20px; \
            opacity: 0.5; \
            cursor: pointer; \
            transition: all 0.1s; \
        } \
        #sidebar-toggle:hover { \
            font-size: 23px; \
            opacity: 1; \
            top: -2px; \
        } \
    ';

    addCSS(css);

    document.addEventListener('DOMContentLoaded', function() {
        var sidebarToggle = document.createElement('div'),
            sidebar = document.getElementById('mw-panel'),
            mainContent = document.getElementById('content');

        sidebar.style.display = 'none';  // Seems to be undefined initially

        sidebarToggle.id = 'sidebar-toggle';
        sidebarToggle.title = 'Toggle Sidebar';
        sidebarToggle.textContent = '▸';

        sidebarToggle.addEventListener('click', function() {
            rotate(sidebarToggle, mainContent.classList.contains('with-sidebar') ? 0 : 90);
            mainContent.classList.toggle('with-sidebar');
            sidebar.style.display = (sidebar.style.display === 'none') ? 'block' : 'none';
        });

        if (! prefs.hiddenByDefault) sidebarToggle.click();

        document.body.insertBefore(sidebarToggle, document.body.firstElementChild);
    });

})();<commit_msg>Handle DOM ready event not being fired, closes #2<commit_after>// ==UserScript==
// @name         Wikipedia - Toggle Sidebar
// @description  Adds a small button to hide or show the sidebar. Makes reading easier.
// @version      0.2.1
// @author       <NAME>
// @namespace    https://github.com/arthurhammer
// @license      MIT
// @homepage     https://github.com/arthurhammer/userscripts/tree/master/Wikipedia_ToggleSidebar
// @updateURL    https://github.com/arthurhammer/userscripts/raw/master/Wikipedia_ToggleSidebar/wikipedia_toggle-sidebar.user.js
// @downloadURL  https://github.com/arthurhammer/userscripts/raw/master/Wikipedia_ToggleSidebar/wikipedia_toggle-sidebar.user.js
// @match        *.wikipedia.org/wiki/*
// @run-at       document-body
// @grant        none
// ==/UserScript==

(function() {

    var prefs = {
        hiddenByDefault: true
    };

    var css = '\
        body { \
            background-color: white; \
        } \
        #content { \
            border-color: #ddd; \
            border-left-width: 0; \
            margin-left: 5em;    \
            margin-right: 5em; \
        } \
        #content.with-sidebar { \
            margin-left: 10em; \
            margin-right: 0em; \
        } \
        #mw-panel { \
            display: none; \
        } \
        #sidebar-toggle { \
            position: absolute; \
            top: 0; \
            left: 5; \
            z-index: 999; \
            padding: 10px; \
            font-size: 20px; \
            opacity: 0.5; \
            cursor: pointer; \
            transition: all 0.1s; \
        } \
        #sidebar-toggle:hover { \
            font-size: 23px; \
            opacity: 1; \
            top: -2px; \
        }';

    function rotate(element, degrees) {
        var rotation = 'rotate(' + degrees + 'deg)';
        element.style.WebkitTransform = rotation;
        element.style.transform = rotation;
    }

    function addCSS(css) {
        var style = document.createElement('style');
        style.textContent = css;
        document.head.appendChild(style);
    }

    function addSidebarToggle() {
        if (!document.body || document.getElementById('sidebar-toggle')) return;

        var sidebarToggle = document.createElement('div');
        sidebarToggle.id = 'sidebar-toggle';
        sidebarToggle.title = 'Toggle Sidebar';
        sidebarToggle.textContent = '▸';

        sidebarToggle.addEventListener('click', function() {
            var sidebar = document.getElementById('mw-panel');
            var mainContent = document.getElementById('content');

            rotate(sidebarToggle, mainContent.classList.contains('with-sidebar') ? 0 : 90);
            mainContent.classList.toggle('with-sidebar');
            sidebar.style.display =
                (sidebar.style.display && sidebar.style.display === 'none') ? 'block' : 'none';
        });

        if (! prefs.hiddenByDefault) sidebarToggle.click();

        document.body.insertBefore(sidebarToggle, document.body.firstElementChild);
    }

    document.addEventListener('DOMContentLoaded', addSidebarToggle);
    addCSS(css);
    // DOMContentLoaded can fire before the listener was installed. Double-check.
    addSidebarToggle();

})();
{'fraction_non_alphanumeric': 0.1328560063643596, 'fraction_numerical': 0.009387430389817025, 'mean_word_length': 1.891444342226311, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2010580', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1732, 'n_words': 338}