linux.do.level

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

As of 2024-03-22. See the latest version.

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.

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

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.0.0
// @author       LINUX.DO
// @license      GPL-3.0
// @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:5em;background:#313131;z-index:999;padding:.5em;color:#ddd;border-radius:4px}.level-window .title .close{width:30px;height:30px;color:#ddd;background:red;display:inline-block;text-align:center;line-height:30px;float:right;cursor:pointer;border-radius:4px}.level-window .bg-white{background-color:#222;border-radius:.5em;padding:.5em;margin-top:.5em}.level-window h1{color:#fff;font-size:1.3rem}.level-window h2{font-size:1.25rem}.mb-4 table tr:nth-child(2n){background-color:#313131}.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.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") ? "450px" : "5em";
    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;
      });
    }
    return root;
  }
  (() => {
    function init() {
      window.addEventListener("load", () => {
        let timer = setTimeout(() => {
          let titleBar = document.querySelector("body section div div header div div div.panel ul.icons.d-header-icons");
          if (titleBar) {
            let button = createLevelButton();
            titleBar.prepend(button);
            clearTimeout(timer);
          }
        }, 500);
      });
    }
    init();
  })();

})();