DeepFloodbeta

【油猴】种子和元老我全都要 - 在元老前面加一个种子标签

效果图

v1awPk5W1Vad2iX52qKv8aGjz7kZXUWx.webp
gKnPGtY8wnoGP9HA70KlCIxW4ldGJBtg.webp
O2MvyLuydS2TV5p9XouTNsJZZ2jnzYRz.webp

插件代码,自取


// ==UserScript==
// @name        给元老标签前面加一个种子标签
// @namespace   Violentmonkey Scripts
// @match       https://www.deepflood.com/post-*
// @match       https://www.deepflood.com/space*
// @grant       none
// @version     1.0
// @author      -
// @description 2025/10/19 07:59:18
// ==/UserScript==

;(function(){

    const yuanlaoSelector = `.nsk-badge.role-tag.role-veteran`;
    const yonghuYuanlaoSelector =  `.MItem.role-tag.role-veteran`;

    const waitForElement = selector => new Promise(res => {
      const el = document.querySelectorAll(selector);
      if (el && el.length > 0) return res(el);
      new MutationObserver((_, o) => {
        const found = document.querySelectorAll(selector);
        if (found) { o.disconnect(); res(found); }
      }).observe(document.body, { childList: true, subtree: true });
    })

    const appendZhongzi = (yuanlao, replacer) => {
      if(yuanlao){
        [].slice.call(yuanlao).forEach(dangeyuanlao => {
          const iconNode = dangeyuanlao.cloneNode(true);
          replacer(iconNode)
          dangeyuanlao.insertAdjacentHTML('beforebegin', iconNode.outerHTML)
        })
      }
    }




  // ===== 初始化 (Initialization) =====
  // 脚本的入口点和主逻辑流程。
  const init = async () => {

    waitForElement(yuanlaoSelector).then(yuanlao => {
      appendZhongzi(yuanlao, (iconNode) => {
        iconNode.classList.replace('role-veteran', 'role-seed')
        iconNode.innerHTML = `<svg class="iconpark-icon" style="width:12px;height:12px;position: relative; top: -1px;"><use href="#seedling"></use></svg><!----><span>种子</span>`
      })
    });

    waitForElement(yonghuYuanlaoSelector).then(yuanlao => {
      appendZhongzi(yuanlao, (iconNode) => {
        iconNode.classList.replace('role-veteran', 'role-seed')
        iconNode.textContent = `种子`
      })
    });


  };

  // 脚本从load事件后开始执行
  window.addEventListener('load', init);
})();
1234
1234