aolko / OpenServer toolbox

// ==UserScript==
// @name         OpenServer toolbox
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Toolbox for ospanel.io.
// @author       aolko
// @license 	GPL-3.0-or-later
// @match        https://ospanel.io/*
// @match        https://ospanel.io/forum/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=ospanel.io
// @grant        GM_addStyle
// @require      https://code.jquery.com/jquery-3.6.1.min.js
// @require      https://cdn.jsdelivr.net/npm/js-cookie@3.0.1/dist/js.cookie.min.js
// @run-at       document-start
// ==/UserScript==

/*
Settings are currently not working. Will fix in the future.
*/

/* globals $ */

var osp_QuickLinks = [
    {
      "name": "Новости разработки",
      "url": "./viewtopic.php?f=1&t=5395&start=99980"
    },
    {
      "name": "Предложения",
      "url": "./viewtopic.php?f=1&t=1030&start=99980"
    }
];

(function() {
    'use strict';
    console.log("run");
    $(`header > nav > div.navbar-collapse.collapse.clps1 > ul > li:nth-child(7)`).remove();
    //$("head > link[href*='https://ospanel.io/bootstrap/css/bootstrap.1658434517.css']").remove();
    $("head > script[src*='https://ospanel.io/bootstrap/js/bootstrap.1658434524.js']").remove();
    //$(`head`).append(`<link rel="stylesheet" href="https://glcdn.githack.com/aolko/userscripts-res/-/raw/main/ospanel.io/assets/bs3/css/bootstrap.min.css">`);
    $(`#tophtml > p:nth-child(4)`).remove();
    $(`body`).append(`
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js"></script>
        <script src="https://cdn.jsdelivr.net/gh/aolko/fontawesome-pro@master/fontawesome-pro-6.1.2-web/js/all.min.js" data-auto-replace-svg="nest"></script>
        <script src="https://cdn.jsdelivr.net/gh/aolko/fontawesome-pro@master/fontawesome-pro-6.1.2-web/js/v4-shims.min.js"></script>
        `);
    $(`header.container`).prepend(`
        <div class="alert alert-warning alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <strong>Внимание!</strong> Здешняя версия бутстрапа пиздецки устарела.
        </div>
    `);

    if (window.location.href.indexOf("download") != -1){
        $(function() {
            var og_DL = $(`#first_button`).attr('onclick');
            GM_addStyle(`
            #donate_form{opacity:.2;transition:all .2s ease-in-out;pointer-events:none;}
            #donate_form>*{pointer-events:none;}
            `);
            setInterval(function() {
                $(`#donate_form`).slideUp();
            }, 1000);
            $(`#first_button`).remove();
            $(`
            <div class="download--options" style="width:100%;">
                <div class="dropdown">
                  <button class="btn btn-secondary dropdown-toggle" style="width:100%;" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                    Скачать OpenServer
                    <span class="caret"></span>
                  </button>
                  <ul class="dropdown-menu" style="width:100%;">
                    <li class="dropdown-header"><i class="fa-solid fa-gauge-min"></i> Официально</li>
                    <li><a class="dropdown-item" href="#" onclick=${og_DL}>С сайта</a></li>
                    <li role="separator" class="divider"></li>
                    <li class="dropdown-header"><i class="fa-solid fa-gauge-max"></i> Из сети</li>
                    <li style="display: flex; align-items: center;"><a class="dropdown-item" style="width:100%" href="https://rutracker.net/forum/tracker.php?nm=open-server"><img src="https://www.google.com/s2/favicons?sz=64&domain=rutracker.net" width="16" height="16"></img> С рутрекера</a></li>
                    <li style="display: flex; align-items: center;"><a class="dropdown-item" style="width:100%" href="https://nnmclub.to/forum/tracker.php?nm=open%20server"><img src="https://www.google.com/s2/favicons?sz=64&domain=nnmclub.to" width="16" height="16"></img> С nnm-club</a></li>
                  </ul>
                </div>
            </div>
            `).insertAfter(`#inhtml`);
            $.when( `firstPress()` ).done(function() {
                $(`.kotik`).remove();
                $(`#accept2`).html(`
                    <h2 class="h2">Сейчас будем качать</h2>
                    <p class="jst">Просто нажми на кнопку</p>
                `);
                $(`#second_button`).html(`<i class="fa-solid fa-gauge-min"></i> Скачать медленно с сайта Open Server`);
                $(`#second_button`).attr(`style`,`display: flex; align-items:center; gap: 5px;`);
                $(`#second_button`).appendTo(`#accept2`);
                //$(`#second_button`).remove();
                $(`#second_button`).addClass(`jst`);
            });
        });
    }
    else if (window.location.href.indexOf("forum") != -1){
        $(function() {
            $(`#page-header > div.headerbar > div > div.menunav.maxmenu > a:nth-child(7)`).remove();
            $(`#page-header > div.navbar.tabbed.not-static > div > div > ul.leftside > li.tab.home.responsive-cloned-item`).remove();
            $(`#nav-breadcrumbs > li.breadcrumbs > span:nth-child(1)`).remove();
            $(`#nav-footer > li.breadcrumbs > span:nth-child(1)`).remove();

            var osp_QuickLink_html = `
            <div class="forabg category-1 elegant" data-hide-description="1">
                  <div class="inner">
                    <ul class="topiclist">
                      <li class="header">
                        <dl class="row-item">
                          <dt>
                            <div class="list-inner">Быстрые ссылки</div>
                          </dt>
                        </dl>
                        <i class="fa-solid fa-puzzle-piece-simple" style="position: absolute; right: 5px; top: 50%; margin-top: -8px; height: 16px; width: 16px; opacity: .7"></i>
                      </li>
                    </ul>
                    <ul class="topiclist forums">
                    </ul>
                  </div>
                </div>
            `;
            $(`<div class="osp_ql">${osp_QuickLink_html}</div>`).insertAfter(`#page-body > div.navbar`);
            $.each(osp_QuickLinks, function(item) {
                $(`#page-body > div.osp_ql > div > div > ul.topiclist.forums`).append(`

                      <li class="row">
                        <dl class="row-item forum_unread elegant-row">
                          <dt>
                            <a href="${osp_QuickLinks[item].url}" class="row-item-link"></a>
                            <div class="list-inner">
                              <a href="${osp_QuickLinks[item].url}" class="forumtitle" data-id="1">${osp_QuickLinks[item].name}</a>
                            </div>
                          </dt>
                        </dl>
                      </li>

            `);
            });
        });
    };

    $(`body`).append(`
        <dialog id="osp_script_settings">
          <form method="dialog">
            <h2 style="display: flex; align-items: center; margin: 0 0 10px 0;"><i class="icon fa-cog fa-fw" aria-hidden="true"></i> Настройки</h2>
            <hr/>
            <p>
            <label><input type="checkbox" id="osp_QuickLinks" name="quickLinks" checked> Быстрые ссылки</label>
            </p>
            <p>
            <label><input type="checkbox" id="osp_Infobar" name="infoBar" checked> Отображать баннер</label>
            </p>
            <div>
              <button value="cancel">Отмена</button>
            </div>
          </form>
        </dialog>
    `);
    $(`#page-header > div.navbar.tabbed.not-static > div > div > ul.rightside`).append(`
        <li class="tab osp-settings" data-skip-responsive="true" title="Настройки" data-responsive-index="-1" data-osp-settings>
            <a class="nav-link" href="#" title="Настройки" role="menuitem"><i class="icon fa-cog fa-fw" aria-hidden="true"></i></a>
        </li>
    `);
    $(`*[data-osp-settings]`).click(function(){
        document.querySelector(`#osp_script_settings`).showModal();
    });
    $("input#osp_QuickLinks").change(function() {
        if($(this).is(":checked")) {
            Cookies.set("osp_quicklinks", "true", {expires: 60});
        }
        else {
            Cookies.set("osp_quicklinks", "false", {expires: 60});
        }
    });
    $("input#osp_Infobar").change(function() {
        if($(this).is(":checked")) {
            Cookies.set("osp_infobar", "true", {expires: 60});
        }
        else {
            Cookies.set("osp_infobar", "false", {expires: 60});
        }
    });

})();