// ==UserScript== // @name Bilibili 哔哩哔哩查看原图 // @icon https://t.bilibili.com/favicon.ico // @namespace https://lolico.moe/ // @version 2.3.0 // @description 方便在B站内查看各种图片的原图,支持动态、专栏 // @author Jindai Kirin // @match https://t.bilibili.com/* // @match https://space.bilibili.com/* // @match https://www.bilibili.com/read/* // @license GPL-3.0 // @grant GM_addStyle // @run-at document-end // @require https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js // @downloadURL none // ==/UserScript== (function () { 'use strict'; if (location.hostname === 't.bilibili.com' || location.hostname === 'space.bilibili.com') { 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).on('click', async ({ target }) => { if (target.className !== 'img-content') return; const $imagesbox = $('.imagesbox:hover'); const $btn = await findBtn($imagesbox); const $newBtn = $($btn.prop('outerHTML').replace('大', '原')); $newBtn.on('click', () => { window.open($imagesbox.find('.boost-img img').attr('src').replace(/@.*?$/, ''), '_blank'); }); $btn.after($newBtn); const removeBtn = () => $newBtn.remove(); $imagesbox.find('.bp-v-middle:contains(收起)').one('click', removeBtn); $imagesbox.find('.boost-img').one('click', removeBtn); }); } else if (location.href.startsWith('https://www.bilibili.com/read/')) { GM_addStyle('img.normal-img,.card-image__image{cursor:pointer}'); $('img.normal-img').each(function () { const $img = $(this); $img.on('click', () => { window.open($img.attr('src').replace(/@.*?$/, '')); }); $img.attr('title', '点击打开原图'); }); $('.card-image__image').each(function () { const $div = $(this); $div.on('click', () => { window.open( $div .css('background-image') .replace(/^url\(["']?/, '') .replace(/["']?\)$/, '') .replace(/@.*?$/, ''), '_blank' ); }); $div.attr('title', '点击打开原图'); }); } })();