// ==UserScript== // @name 下载即梦无水印图片 // @namespace https://github.com/xiaowang96-github/jimengNoWatermark // @version 1.0 // @description 通过F12控制台即梦生成的图片的无水印图片 // @author xiaowang // @match *://jimeng.jianying.com/* // @grant none // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/532480/%E4%B8%8B%E8%BD%BD%E5%8D%B3%E6%A2%A6%E6%97%A0%E6%B0%B4%E5%8D%B0%E5%9B%BE%E7%89%87.user.js // @updateURL https://update.greasyfork.icu/scripts/532480/%E4%B8%8B%E8%BD%BD%E5%8D%B3%E6%A2%A6%E6%97%A0%E6%B0%B4%E5%8D%B0%E5%9B%BE%E7%89%87.meta.js // ==/UserScript== (function() { 'use strict'; // 定义下载文件的函数 async function downloadFile(url, filename) { try { const response = await fetch(url); if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`); const blob = await response.blob(); const objectUrl = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = objectUrl; a.download = filename; a.click(); URL.revokeObjectURL(objectUrl); } catch (error) { console.error('下载失败:', error); } } // 定义一个函数来查找图片并添加下载按钮 function findImageAndAddButton() { // 查找图片容器 const imageContainer = document.querySelector('.container-Sq_B8G'); if (!imageContainer) return; // 查找图片元素 const imgElement = imageContainer.querySelector('img'); if (!imgElement) return; // 获取图片地址 const imageUrl = imgElement.src; // 查找顶部操作栏 const topActionBar = document.querySelector('.topActionBar-v7_WTk'); if (!topActionBar) return; // 检查下载按钮是否已经存在 const existingButton = topActionBar.querySelector('.mweb-button-tertiary.mwebButton-vwzuXc.operationBtnItem-_GEqBw[data-download-button]'); if (existingButton) return; // 创建下载按钮 const downloadButton = document.createElement('div'); downloadButton.className = 'mweb-button-tertiary mwebButton-vwzuXc operationBtnItem-_GEqBw'; downloadButton.setAttribute('data-download-button', ''); downloadButton.setAttribute('title', '下载无水印图'); downloadButton.innerHTML = ` `; // 为按钮添加点击事件 downloadButton.addEventListener('click', function() { downloadFile(imageUrl, "imageOrgin_jimeng.png"); }); // 将按钮添加到顶部操作栏 topActionBar.appendChild(downloadButton); } // 创建一个 MutationObserver 实例 const observer = new MutationObserver((mutationsList, observer) => { for (const mutation of mutationsList) { if (mutation.type === 'childList') { findImageAndAddButton(); } } }); // 配置观察选项 const config = { childList: true, subtree: true }; // 开始观察整个文档的变化 observer.observe(document.body, config); // 页面加载完成后也尝试查找一次 window.addEventListener('load', findImageAndAddButton); })();