Greasy Fork

畅想之星id助手

在资源页面显示ruid

当前为 2023-08-30 提交的版本,查看 最新版本

// ==UserScript==
// @name         畅想之星id助手
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  在资源页面显示ruid
// @author       Xinconan
// @match        https://www.cxstar.com/Book/CloudResource*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=cxstar.com
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const customStyles = `
    .book-list-item{
    position:relative;
    }
    .book-ruid{
      position: absolute;
      right: 15px;
      top: 60px;
      color:#ff1a14;
    }
    `;

    // 监听列表变化的函数
  function watchListChanges() {
    const targetList = document.querySelector('.search-main-list');
      console.log(targetList);

    if (targetList) {
      // 创建一个监听器来监视节点插入和属性变化
      const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
          if (mutation.type === 'childList') {
            // 当有新节点插入时,找到插入的节点并提取 data-id 值
            mutation.addedNodes.forEach(function(node) {
              if (node.nodeType === Node.ELEMENT_NODE) {
                const dataId = node.getAttribute('data-id');
                if (dataId) {
                  // 将 data-id 值插入到列表中
                  const listItem = document.createElement('div');
                    listItem.classList = 'book-ruid';
                  listItem.textContent = `${dataId}`;
                  node.appendChild(listItem);
                }
              }
            });
          }
        });
      });

      // 开始监听列表的变化
      observer.observe(targetList, { childList: true, subtree: true });
    }
  }

   // 使用GM_addStyle函数添加样式
  GM_addStyle(customStyles);

  // 在页面加载完成后调用监听函数
  window.addEventListener('load', watchListChanges);
})();