linux.do.level

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

当前为 2024-03-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name linux.do.level
  3. // @namespace https://linux.do/u/io.oi/s/level
  4. // @version 1.0.1
  5. // @author LINUX.DO
  6. // @description Linux.Do 查看用户信任级别以及升级条件,数据来源于 https://connect.linux.do
  7. // @icon https://cdn.linux.do/uploads/default/original/1X/de7ee26820e897b6a07350126411ebc489f62202.png
  8. // @match https://linux.do/*
  9. // @grant GM.xmlHttpRequest
  10. // @grant GM_addStyle
  11. // ==/UserScript==
  12.  
  13. (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} ");
  14.  
  15. (function () {
  16. 'use strict';
  17.  
  18. var _GM = /* @__PURE__ */ (() => typeof GM != "undefined" ? GM : void 0)();
  19. function getLevelFromConnect(onLoad) {
  20. _GM.xmlHttpRequest({
  21. method: "GET",
  22. url: "https://connect.linux.do",
  23. onload: (response) => {
  24. let regx = /<body[^>]*>([\s\S]+?)<\/body>/i;
  25. let contents = regx.exec(response.responseText);
  26. if (contents) {
  27. onLoad(contents[1].replace('<a href="/logout" target="_self" class="text-blue-500 hover:underline" title="LINUX DO登录也会退出">退出</a>', ""));
  28. }
  29. }
  30. });
  31. }
  32. let levelWindow = void 0;
  33. function createLevelButton() {
  34. let li = document.createElement("li");
  35. li.className = "header-dropdown-toggle chat-header-icon";
  36. li.innerHTML = `
  37. <div class="widget-component-connector">
  38. <a class="icon btn-flat" tabindex="2" title="查看我的等级">
  39. <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>
  40. </a>
  41. </div>
  42. `;
  43. li.addEventListener("click", () => {
  44. getLevelFromConnect((content) => {
  45. if (levelWindow) {
  46. levelWindow.remove();
  47. levelWindow = void 0;
  48. } else {
  49. levelWindow = createWindow(content);
  50. document.body.appendChild(levelWindow);
  51. }
  52. });
  53. });
  54. return li;
  55. }
  56. function createWindow(content) {
  57. let root = document.createElement("div");
  58. root.setAttribute("id", "level-window");
  59. root.className = "level-window";
  60. root.style.right = document.querySelector("div.chat-drawer.is-expanded") ? "430px" : "15px";
  61. root.innerHTML = `
  62. <div class="title">
  63. <span class="close" id="close-button">
  64. <svg class="fa d-icon d-icon-times svg-icon svg-string" xmlns="http://www.w3.org/2000/svg">
  65. <use href="#times"></use>
  66. </svg>
  67. </span>
  68. <div id="content" class="content"></div>
  69. </div>`;
  70. let div = root.querySelector("#content");
  71. if (div) {
  72. div.innerHTML = content;
  73. }
  74. let close = root.querySelector("#close-button");
  75. if (close) {
  76. close.addEventListener("click", () => {
  77. root.remove();
  78. levelWindow = void 0;
  79. });
  80. }
  81. return root;
  82. }
  83. (() => {
  84. function init() {
  85. window.addEventListener("load", () => {
  86. let timer = setTimeout(() => {
  87. let titleBar = document.querySelector("body section div div header div div div.panel ul.icons.d-header-icons");
  88. if (titleBar) {
  89. let button = createLevelButton();
  90. titleBar.prepend(button);
  91. clearTimeout(timer);
  92. }
  93. }, 500);
  94. });
  95. }
  96. init();
  97. })();
  98.  
  99. })();