bilbili动态页面图片去掉 .avif

try to change the world!

当前为 2025-02-02 提交的版本,查看 最新版本

// ==UserScript==
// @name        bilbili动态页面图片去掉 .avif
// @namespace    none
// @version      0.1
// @description  try to change the world!
// @author       klw
// @include      https://www.bilibili.com/opus/*
// @match        https://www.bilibili.com/opus/*
// @grant        none
// @license      GNU GPL-3.0
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
// 读取图片目标
const source = document.querySelectorAll(".bili-album__preview__picture source[type=\"image/avif\"]")
const allMinImgDiv =document.querySelector(".opus-module-content .bili-album__preview")
const bigImg = document.querySelector(".bili-album__watch .bili-album__watch__content img")
const cvImg = document.querySelectorAll(".opus-para-pic .b-img__inner source[type=\"image/avif\"]")
// 确定正则表达式
const pattern = /@.*/,
    str = ''
// 读取缩略图,并替换图片路径
for (let i = 0; i < source.length; i++) {
    source[i].srcset = source[i].srcset.replace(pattern, str)
}
// 读取并替换专栏图片
for (let i = 0; i < cvImg.length; i++) {
    cvImg[i].srcset = cvImg[i].srcset.replace(pattern, str)
}
// 替换大图路径函数
function refresh(){
    setTimeout(function () {
        bigImg.src = bigImg.src.replace(pattern, str)
    },200)
}
// 判断是否点击图片
allMinImgDiv.addEventListener('click', function (e) {
    if (e.target.tagName === "IMG"){
        refresh()
        // 判读是否有上一张,如果有执行替换函数
        const prev = document.querySelector(".bili-album__watch .bili-album__watch__content .bili-album__watch__content__prev")
        console.log(prev)
        if (prev) {
            prev.addEventListener('click', function (e) {
                refresh()
                const next = document.querySelector(".bili-album__watch .bili-album__watch__content .bili-album__watch__content__next")
                next.addEventListener('click', function (e) {
                    refresh()
                })
            })
        }
        // 判读是否有下一张,如果有执行替换函数
        const next = document.querySelector(".bili-album__watch .bili-album__watch__content .bili-album__watch__content__next")
        console.log(next)
        if (next){
            next.addEventListener('click', function (e) {
                refresh()
                const prev = document.querySelector(".bili-album__watch .bili-album__watch__content .bili-album__watch__content__prev")
                prev.addEventListener('click', function (e) {
                    refresh()
                })
            })
        }
    }
})

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址