@Name- // ==UserScript==
- // @name 复制bilibili专栏图片链接
- // @namespace http://tampermonkey.net/
- // @version 2024-10-28
- // @description 在专栏页面的右侧边栏添加复制正文中图片链接的按钮,并在链接前后添上图片标签
- // @author u
- // @match https://www.bilibili.com/opus/*
- // @match https://www.bilibili.com/read/cv*
- // @icon https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- const h =`<div id="cpoyImgLink" class="side-toolbar__action collection"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="none">
- <rect width="12" height="14" x="8" y="7" fill="none" stroke="currentColor"></rect>
- <polyline points="16 3 4 3 4 17" fill="none" stroke="currentColor"></polyline>
- </svg> <div class="side-toolbar__action__text">图链</div></div>`;
- const oh = `<div id="cpoyImgLink" class="toolbar-item" data-v-0974dd01=""><i class="iconfont" data-v-0974dd01="">\uE61A</i><span class="toolbar-item__num" data-v-0974dd01="">图链</span></div>`;
- if(document.querySelector('.side-toolbar__top'))
- document.querySelector('.side-toolbar__top').insertAdjacentHTML('beforeend',h);
- else
- document.querySelector('.side-toolbar').insertAdjacentHTML('afterbegin',oh);
- document.querySelector('#cpoyImgLink').addEventListener('click', ()=> {
- let a=[];
- document.querySelectorAll('.opus-module-content img,.editor-cards img,.article-content img').forEach( (e) => {
- let s=e.src;
- if(!s)s=e.getAttribute('data-src');
- if(s.startsWith('//'))s='https:'+s;
- a.push(s.replace(/@.*/, ''))
- });
- let c = a.length;
- let o = a.map( (l) => `[img]${l}[/img]`).join('');
- navigator.clipboard.writeText(o).then(() => {
- alert(c+'个图片链接已复制到剪贴板!');
- })
- .catch(err => {
- console.log(`找到的${c}个链接:\n${o}`);
- alert('复制失败了,已将找到的图片链接输出至F12控制台。', err);
- });;
- });
- })();
复制代码 |