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