Greasy Fork

Bilibili 哔哩哔哩动态查看原图

使哔哩哔哩动态可以查看原图以保存图片等,同时也支持空间中的动态

目前为 2019-11-01 提交的版本。查看 最新版本

// ==UserScript==
// @name         Bilibili 哔哩哔哩动态查看原图
// @icon         https://t.bilibili.com/favicon.ico
// @namespace    https://lolico.moe/
// @version      2.1
// @description  使哔哩哔哩动态可以查看原图以保存图片等,同时也支持空间中的动态
// @author       Jindai Kirin
// @match        https://t.bilibili.com/*
// @match        https://space.bilibili.com/*
// @license      GPL-3.0
// @grant        none
// @run-at       document-end
// @require      https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js
// ==/UserScript==

(function() {
    'use strict';

    const findBtn = $imagesbox =>
        new Promise(resolve => {
            const $btn = $imagesbox.find('.bp-v-middle:contains(查看大图)');
            if ($btn.length > 0) {
                resolve($btn);
                return;
            }
            new MutationObserver((mutations, self) => {
                mutations.forEach(({ addedNodes }) => {
                    if (addedNodes.length > 0 && addedNodes[0].className === 'boost-wrap') {
                        self.disconnect();
                        resolve($imagesbox.find('.bp-v-middle:contains(查看大图)'));
                    }
                });
            }).observe($imagesbox[0], { childList: true });
        });

    $(document).click(async ({ target }) => {
        if (target.className !== 'img-content') return;
        const $imagesbox = $('.imagesbox:hover');
        const $btn = await findBtn($imagesbox);
        console.log($btn);
        const $newBtn = $($btn.prop('outerHTML').replace('大', '原'));
        $newBtn.click(() => {
            window.open(
                $imagesbox
                    .find('.boost-img img')
                    .attr('src')
                    .replace(/@.*/, '')
            );
        });
        $btn.after($newBtn);
        const removeBtn = () => $newBtn.remove();
        $imagesbox.find('.bp-v-middle:contains(收起)').one('click', removeBtn);
        $imagesbox.find('.boost-img').one('click', removeBtn);
    });
})();