油猴小尾巴修复脚本

很多佬友在签名栏设置了自己的博客链接,或者是自己的座右铭。

但是自己没开启签名展示没意识到不能正常显示,让我们一起来修复它们吧

修复前:

修复后:

代码没什么技术含量 大家见笑了

// ==UserScript==
// @name         修复裂开的小尾巴
// @namespace    http://tampermonkey.net/
// @version      0.0.9
// @description  很多佬友在签名栏设置了自己的博客链接,或者是自己的座右铭。但是自己没开启签名展示没意识到不能正常显示,让我们一起来修复它们吧
// @author       ygmjjdev
// @match        https://linux.do/*
// @icon         https://linux.do/uploads/default/optimized/1X/3a18b4b0da3e8cf96f7eea15241c3d251f28a39b_2_180x180.png
// @grant        none
// @downloadURL https://update.greasyfork.org/scripts/490014/%E4%BF%AE%E5%A4%8D%E8%A3%82%E5%BC%80%E7%9A%84%E5%B0%8F%E5%B0%BE%E5%B7%B4.user.js
// @updateURL https://update.greasyfork.org/scripts/490014/%E4%BF%AE%E5%A4%8D%E8%A3%82%E5%BC%80%E7%9A%84%E5%B0%8F%E5%B0%BE%E5%B7%B4.meta.js
// ==/UserScript==

// 把裂开的图片换成文本或超链接
function replaceImage(img) {
  var src = img.getAttribute("src");

  if (src.startsWith("http")) {
    var a = document.createElement("a");
    a.setAttribute("href", src);
    a.textContent = src;

    img.parentNode.replaceChild(a, img);
  } else {
    var p = document.createElement("p");
    p.textContent = src;
    img.onerror = null;
    img.parentNode.replaceChild(p, img);
  }
}

(function () {
  "use strict";
  document.querySelectorAll(".signature-img").forEach(function (img) {
    if (img.complete && img.naturalHeight === 0 && img.naturalWidth === 0) {
      replaceImage(img);
    }
    img.onerror = function () {
      replaceImage(img);
    };
  });

  var observer = new MutationObserver(function (mutations) {
    mutations.forEach(function (mutation) {
      if (mutation.type == "childList") {
        mutation.addedNodes.forEach(function (node) {
          checkNodeAndChildren(node);
        });
      }
    });
  });

  function checkNodeAndChildren(node) {
    if (node.nodeName == "IMG" && node.classList.contains("signature-img")) {
      node.onerror = function () {
        setTimeout(() => {
          replaceImage(node);
        }, 30);
      };
    }

    // 递归检查子节点
    if (node.childNodes) {
      node.childNodes.forEach(function (childNode) {
        checkNodeAndChildren(childNode);
      });
    }
  }

  observer.observe(document.body, { childList: true, subtree: true });
})();


直达链接:link:修复裂开的小尾巴

13 个赞

油猴在本站的应用是真的很广啊 :laughing:

6 个赞

万能的油猴 :laughing:

好想法

油猴无所不能 :face_with_peeking_eye:

2 个赞

你这是大逆(bushi
本站钦定php
油猴教派是js

1 个赞

:rofl: :rofl: :rofl: :rofl:

你先别急

这是干啥用的?

好、

可以可以的

6啊

tieba25还的是你佬~

大佬,仰望

图片看不到

From #dev to 开发调优