SuhEugene / Dark theme for code-block in Yandex Lyceum

// ==UserScript==
// @name         Dark theme for code-block in Yandex Lyceum
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Maked with love
// @copyright    2019, SuhEugene
// @license      MIT
// @updateURL    https://openuserjs.org/meta/SuhEugene/Dark_theme_for_code-block_in_Yandex_Lyceum.meta.js
// @downloadURL  https://openuserjs.org/install/SuhEugene/Dark_theme_for_code-block_in_Yandex_Lyceum.user.js
// @author       SuhEugene
// @match        https://lyceum.yandex.ru/*
// ==/UserScript==

(function (window, undefined) {
    var w;
    if (typeof unsafeWindow != undefined) {
        w = unsafeWindow
    } else {
        w = window;
    }

    if (w.self != w.top) {
        return;
    }

    if (/https:\/\/lyceum.yandex.ru/.test(w.location.href) && !(/materials/.test(w.location.href))) {
        // var style = '.header__top {background-color:#222!important;}.icon_type_menu.icon_size_l {background-image: url("data:image/svg+xml,%3Csvg width=\'16\' height=\'14\' xmlns=\'http://www.w3.org/2000/svg\'%3E%3Cg fill=\'none\' fill-rule=\'evenodd\'%3E%3Cpath d=\'M-4-5h24v24H-4z\'/%3E%3Cpath d=\'M0 2V0h16v2H0zm0 6V6h16v2H0zm0 6v-2h16v2H0z\' fill=\'%23fff\'/%3E%3C/g%3E%3C/svg%3E")!important;}.header__menu-toggle {cursor: pointer!important;}.logo_lang_ru {filter: hue-rotate(190deg) invert(1) saturate(200)!important;}#root {background-color: #222!important;}.progress-bar__fill {background-color: #1fc51f!important;border-radius:999px!important;}.Sideblock-Content {background-color: #222!important;box-shadow: 0 0 5px 0 black!important;}.progress-bar {border-radius:999px!important;}.Accordion {border: 1px solid #444;}.Accordion-Item {border-top: 1px solid #444;}.Accordion-Group:not(:last-of-type) .Accordion-Item:last-of-type {border-bottom: 1px solid #444;}code {font-family: "Ubuntu Mono", monospace!important;}.code pre code {color:white!important;}.main-nav {padding: 0.5rem 1rem;border-radius: 5px;background-color: white;margin-left: 1rem;}:root {--color-text-main: #ddd!important;--color-text-secondary: #bbb!important;--color-text-heading: white!important;--color-text-invert: #fff!important;--color-text-control: black!important;--color-text-status: #eee!important;--color-text-warning: #eb0909!important;--color-text-positive: #1fc51f!important;--color-spinner-label: grey!important;--color-background-main: #fff!important;--color-background-menu: #333!important;--color-background-tooltip: #444!important;--color-background-panel: #272822!important;--color-background-active: #ffeba0!important;--color-background-notification-center: #f8f8f8!important;--color-separator: #444!important;--color-separator-dark: hsla(0,0%,100%,0.3)!important;--color-outline: #fc0!important;--color-control-active: #333!important;--color-control-hover: #f5f5f5!important;--color-control-outline: #ccc!important;--color-control-outline-hover: #b3b3b3!important;--color-checked-checkbox: #ffdb4d!important;--color-checked-checkbox-hover: #ffd633!important;--color-link: white!important;--color-link-hover: #ccc!important;--color-link-grey: grey!important;--color-link-grey-hover: #999!important;--color-ticker: #ffdb4d!important;--color-button-active: #f3f1ed!important;--color-button-ok: #2db32d!important;--color-button-ok-hover: #1fc51f!important;--color-button-ok-active: #2dca2d!important;--color-button-action: #ffdb4d!important;--color-button-action-hover: #ffd633!important;--color-button-action-active: #fc0!important;--color-indicator-dark-green: #2db32d!important;--color-indicator-green: #a8de00!important;--color-indicator-red: #ff4242!important;--color-indicator-dark-grey: #ccc!important;--color-indicator-grey: rgba(0,0,0,0.2)!important;--color-indicator-white: #fff!important;--color-indicator-yellow: #ffdd61!important;--color-indicator-dot-red: #ff4242!important;--color-indicator-dot-dark-grey: #ccc!important;--color-header-accepted: #2db32d!important;--color-header-accepted-after-deadline: #accd8c!important;--color-header-rework: #ff4242!important;--color-status-ok: #2dca2d!important;--color-status-redo: #fe3535!important;--color-status-active: #ffeba0!important;--color-status-waiting: #eb9c3d!important;--color-status-accepted-after-deadline: #accd8c!important;--color-table-cell-text: #000!important;--color-table-button-border: #979797!important;--color-task-status-ok: #2eb72e!important;--color-task-status-waiting: #ffc800!important;--color-task-status-redo: #ff4242!important;--color-notification-error: #ff4242!important;--color-notification-success: #1fc51f!important;--color-comments-form-background: #f5f5f5!important;--color-comments-own-background: #fff5d0!important;--color-comments-after-deadline-text: #fb0006!important;--color-comments-after-deadline-border: #fb0006!important;--color-comments-own-active-background: #ffeba0!important;--color-comments-list-box-shadow: rgba(0,0,0,0.08)!important;--color-schedule-events-outline: #6c6c6c!important;--color-schedule-secondary-text: #a8a8a8!important;--color-schedule-event-elective: #d1f0d0!important;--color-schedule-event-elective-hover: #b4e6b2!important;--color-schedule-event-lesson: #e6e6e6!important;--color-schedule-event-lesson-hover: #d9d9d9!important;--color-schedule-event-reserve: #fce68e!important;--color-schedule-event-reserve-hover: #fedf6f!important;--color-schedule-event-vacation: #fce68e!important;--color-schedule-event-vacation-hover: #fedf6f!important;--color-schedule-event-vacation-text: #fe3535!important;--color-schedule-event-test: #d1ebff!important;--color-schedule-event-test-hover: #a3d6ff!important;--color-schedule-event-skip: #fe3535!important;--color-schedule-event-selected-text: #fff!important;--color-schedule-event-selected-background: #666!important;--color-schedule-event-edited-background: #f5f5f5!important;--color-schedule-unassigned-events-list: #000!important;--opacity-schedule-event-passed: 0.6;--color-filter-label-background: #dddcff!important;--color-filter-label-border: #c5c2f2!important;--color-filter-clear-label-background: #fff!important;--color-filter-clear-label-border: #ccc!important;--color-filter-clear-label-text: #fe3535!important;--color-filter-value-separator: #8682c7!important;--color-tag-blue: #247ba0!important;--color-tag-green: #70c1b3!important;--color-tag-red: #f25f5c!important;--color-variant-status-not-assigned: rgba(0,0,0,0.08)!important;--color-variant-status-not-solved: #0090e6!important;--color-variant-status-is-solving: rgba(0,144,230,0.3)!important;--color-variant-status-has-solved: #777!important;--color-student-graduated: #ffc100!important;--color-student-expelled: #ff4242!important;--icon-opacity: 0.24;--icon-opacity-hover: 0.8;}::-webkit-scrollbar {width: 7px;height: 7px;background-color: rgba(255,255,255,.1);}::-webkit-scrollbar-thumb {border-radius: 10px;background-color: rgba(255,255,255,.1);}::-webkit-scrollbar-thumb:hover {border-radius: 10px;background-color: rgba(255,255,255,.2);}.icon_type_notification.icon_size_l {background-image: url("data:image/svg+xml,%3Csvg width=\'18\' height=\'22\' xmlns=\'http://www.w3.org/2000/svg\'%3E%3Cg fill=\'none\' fill-rule=\'evenodd\'%3E%3Cpath d=\'M-3-1h24v24H-3z\'/%3E%3Cpath d=\'M16 11c0-3.896-.549-7.676-5-8.775 0 0 0-2.247-2-2.225-2 .022-2 2.225-2 2.225-4.451 1.1-5 4.88-5 8.764V15l-2 2v1h18v-1l-2-2v-4zM9 22a3 3 0 0 0 3-3H6a3 3 0 0 0 3 3z\' fill=\'%23fff\'/%3E%3C/g%3E%3C/svg%3E")!important;}';
        var style = '.header__menu-toggle {cursor: pointer!important;}.progress-bar {border-radius:999px!important;}code {font-family: "Ubuntu Mono", monospace!important;}.code pre code {color:white!important;}:root {--color-background-panel: #272822!important;}::-webkit-scrollbar {width: 7px;height: 7px;background-color: rgba(255,255,255,.1);}::-webkit-scrollbar-thumb {border-radius: 10px;background-color: rgba(255,255,255,.1);}::-webkit-scrollbar-thumb:hover {border-radius: 10px;background-color: rgba(255,255,255,.2);}';
        var style_el = document.createElement("style");
        var root = document.getElementById("root");
        style_el.innerHTML = style;

        document.body.insertBefore(style_el, root);

        function setColors() {
            var codes = document.querySelectorAll(".code pre code span");
            for (var i = 0; i < codes.length; i++) {
                switch (codes[i].style.color) {
                    case 'rgb(170, 13, 145)':
                        codes[i].style.color = "#f92672";
                        break;
                    case 'rgb(28, 0, 207)':
                        codes[i].style.color = "#a6e22e";
                        break;
                    case 'rgb(92, 38, 153)':
                        codes[i].style.color = "#fd971f";
                        break;
                    case 'rgb(196, 26, 22)':
                        codes[i].style.color = "#e6db74";
                        break;
                    case 'rgb(0, 0, 0)':
                        codes[i].style.color = "#66d9ef";
                        break;
                }
            }
        }

        setInterval(setColors, 500);

    }
})(window);