mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
const regex = /(.*?)@(.*)\./;
|
|
const excludeIds = [
|
|
"certify-img1",
|
|
"certify-img2",
|
|
];
|
|
const MaxChangedTimes = 8;
|
|
export function imageResolution(element)
|
|
{
|
|
if (excludeIds.includes(element.id))
|
|
{
|
|
return;
|
|
}
|
|
let changedTimes = 0;
|
|
const observer = new Observer(element, () =>
|
|
{
|
|
changedTimes++;
|
|
if (changedTimes > MaxChangedTimes)
|
|
{
|
|
observer.stop();
|
|
return;
|
|
}
|
|
const src = element.getAttribute("src");
|
|
const match = src.match(regex);
|
|
if (match && match[1])
|
|
{
|
|
observer.stop();
|
|
element.setAttribute("src", match[1]);
|
|
}
|
|
});
|
|
observer.options = {
|
|
childList: false,
|
|
attributes: true,
|
|
subtree: false,
|
|
};
|
|
observer.start();
|
|
}
|
|
document.querySelectorAll("img").forEach(it => imageResolution(it));
|
|
Observer.childListSubtree("body", mutations =>
|
|
{
|
|
for (const mutation of mutations)
|
|
{
|
|
for (const node of mutation.addedNodes)
|
|
{
|
|
if (node.nodeName.toLowerCase() === "img")
|
|
{
|
|
imageResolution(node);
|
|
}
|
|
node.querySelectorAll && node.querySelectorAll("img").forEach(it => imageResolution(it));
|
|
}
|
|
}
|
|
});
|
|
export default {
|
|
export: { imageResolution }
|
|
}; |