linux.do.level

Linux.Do 查看用户信任级别以及升级条件,数据来源于 https://connect.linux.do

Від 23.03.2024. Дивіться остання версія.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         linux.do.level
// @namespace    https://linux.do/u/io.oi/s/level
// @version      1.1.0
// @author       LINUX.DO
// @description  Linux.Do 查看用户信任级别以及升级条件,数据来源于 https://connect.linux.do
// @icon         https://cdn.linux.do/uploads/default/original/1X/de7ee26820e897b6a07350126411ebc489f62202.png
// @match        https://linux.do/*
// @grant        GM.xmlHttpRequest
// @grant        GM_addStyle
// ==/UserScript==

(e=>{if(typeof GM_addStyle=="function"){GM_addStyle(e);return}const o=document.createElement("style");o.textContent=e,document.head.append(o)})(" .level-window{position:fixed;bottom:0;background:var(--secondary);z-index:999;padding:.5em;color:var(--primary);box-shadow:0 0 4px #00000020;border:1px solid var(--primary-low)}.level-window .title .close{width:30px;height:30px;color:#fff;background:red;display:inline-block;text-align:center;line-height:30px;float:right;cursor:pointer;border-radius:4px}.level-window .bg-white{background-color:var(--primary-50);border-radius:.5em;padding:.5em;margin-top:.5em}.level-window h1{color:var(--primary);font-size:1.3rem}.level-window h2{font-size:1.25rem}.mb-4 table tr:nth-child(2n){background-color:var(--tertiary-400)}.level-window .text-red-500{color:#ef4444}.level-window .text-green-500{color:#10b981}.level-window .mb-4 table tr td{padding:4px 8px} ");

(function () {
  'use strict';

  var _GM = /* @__PURE__ */ (() => typeof GM != "undefined" ? GM : void 0)();
  function getLevelFromConnect(onLoad) {
    _GM.xmlHttpRequest({
      method: "GET",
      url: "https://connect.linux.do",
      onload: (response) => {
        let regx = /<body[^>]*>([\s\S]+?)<\/body>/i;
        let contents = regx.exec(response.responseText);
        if (contents) {
          onLoad(contents[1].replace('<a href="/logout" target="_self" class="text-blue-500 hover:underline" title="LINUX DO登录也会退出">退出</a>', ""));
        }
      }
    });
  }
  let levelWindow = void 0;
  function createLevelButton() {
    let li = document.createElement("li");
    li.className = "header-dropdown-toggle chat-header-icon";
    li.setAttribute("id", "level-button");
    li.innerHTML = `
        <div class="widget-component-connector">
            <a class="icon btn-flat" tabindex="2" title="查看我的等级">
                <svg class="fa d-icon d-icon-d-chat svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#discourse-sparkles"></use></svg>
            </a>
        </div>
    `;
    li.addEventListener("click", () => {
      getLevelFromConnect((content) => {
        if (levelWindow) {
          levelWindow.remove();
          levelWindow = void 0;
        } else {
          levelWindow = createWindow(content);
          document.body.appendChild(levelWindow);
        }
      });
    });
    return li;
  }
  function createWindow(content) {
    let root = document.createElement("div");
    root.setAttribute("id", "level-window");
    root.className = "level-window";
    root.style.right = document.querySelector("div.chat-drawer.is-expanded") ? "430px" : "15px";
    root.innerHTML = `
     <div class="title">
         <span class="close" id="close-button">
              <svg class="fa d-icon d-icon-times svg-icon svg-string" xmlns="http://www.w3.org/2000/svg">
                  <use href="#times"></use>
              </svg>
         </span>
         <div id="content" class="content"></div>
     </div>`;
    let div = root.querySelector("#content");
    if (div) {
      div.innerHTML = content;
    }
    let close = root.querySelector("#close-button");
    if (close) {
      close.addEventListener("click", () => {
        root.remove();
        levelWindow = void 0;
      });
    }
    let chatContainer = document.querySelector("div.chat-drawer-outlet-container");
    if (chatContainer) {
      let observer = new MutationObserver((_) => {
        let chat = document.querySelector("div.chat-drawer.is-expanded");
        root.style.right = chat ? "430px" : "15px";
      });
      observer.observe(chatContainer, { childList: true });
    }
    return root;
  }
  (() => {
    let headerObserver = void 0;
    function addLevelButtonToTitleBar(header) {
      let titleBar = header.querySelector("header div div div.panel ul.icons.d-header-icons");
      if (titleBar && !titleBar.querySelector("li#level-button")) {
        titleBar.prepend(createLevelButton());
      } else {
        console.warn("query title bar fail.");
      }
    }
    function addHeaderObserver(header) {
      if (headerObserver) {
        headerObserver.disconnect();
      }
      headerObserver = new MutationObserver((_) => {
        addLevelButtonToTitleBar(header);
      });
      headerObserver.observe(header, { childList: true });
      addLevelButtonToTitleBar(header);
    }
    function init() {
      window.addEventListener("load", () => {
        let header = document.querySelector("body section div div.d-header-wrap.drop-down-mode.ember-view");
        if (header) {
          addHeaderObserver(header);
        } else {
          let section = document.querySelector("section.ember-application");
          if (section) {
            let mainObserver = new MutationObserver((_) => {
              addHeaderObserver(section.querySelector("body section div div.d-header-wrap.drop-down-mode.ember-view"));
              mainObserver.disconnect();
            });
            mainObserver.observe(section, { childList: true });
          }
        }
      });
      window.addEventListener("unload", () => {
        if (headerObserver) {
          headerObserver.disconnect();
        }
      });
    }
    init();
  })();

})();