很多佬友在签名栏设置了自己的博客链接,或者是自己的座右铭。
但是自己没开启签名展示没意识到不能正常显示,让我们一起来修复它们吧
修复前:
修复后:
代码没什么技术含量 大家见笑了
// ==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 });
})();
直达链接: 修复裂开的小尾巴