// ==UserScript== // @name 微信读书图片复制和下载 // @namespace http://tampermonkey.net/ // @version 0.1.1 // @description 为了方便在微信读书看技术书复制图片用的,点击按钮新标签页打开图片的功能,还有图片下载的功能,图片下载的名称是按照时间戳为图片名的。 // @author ldbmcs // @require https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js // @match https://weread.qq.com/web/reader* // @grant unsafeWindow // @grant GM_setValue // @grant GM_getValue // @grant GM_openInTab // @grant GM_download // @grant GM_setClipboard // @grant GM_notification // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 当DOM完全加载后执行 window.addEventListener('load', function() { // 查找所有具有特定类名的img元素 const images = document.querySelectorAll('img.wr_readerImage_opacity'); images.forEach(function(img) { // 为每个找到的img元素添加下载链接 const downloadLink = document.createElement('a'); downloadLink.setAttribute('href', img.src); downloadLink.setAttribute('download', 'download'); downloadLink.innerText = '下载'; downloadLink.style.position = 'absolute'; downloadLink.style.top = '5px'; downloadLink.style.left = '5px'; downloadLink.style.backgroundColor = 'white'; downloadLink.style.color = 'black'; downloadLink.style.padding = '5px'; downloadLink.style.borderRadius = '5px'; downloadLink.style.textDecoration = 'none'; // 将下载链接添加到图片的父元素,假设父元素支持相对定位 img.parentNode.style.position = 'relative'; img.parentNode.appendChild(downloadLink); }); }); })();