// ==UserScript== // @name 笔趣阁小说下载助手 // @namespace http://tampermonkey.net/ // @version 2025.3.10 // @description 自动下载小说内容(带进度条版) // @author Shuaima // @match https://www.qu07.cc/kan/* // @grant GM_xmlhttpRequest // @grant GM_download // @grant GM_setValue // @grant GM_getValue // @connect dizishu.cc // ==/UserScript== (function() { 'use strict'; const USER_AGENTS = [ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' ]; // 进度条容器 const progressBar = document.createElement('div'); progressBar.style = ` position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0,0,0,0.2); z-index: 99999; display: none; `; const progressText = document.createElement('div'); progressText.style.marginBottom = '10px'; const barContainer = document.createElement('div'); barContainer.style = ` width: 300px; height: 20px; background: #eee; border-radius: 10px; overflow: hidden; `; const bar = document.createElement('div'); bar.style = ` width: 0%; height: 100%; background: #4CAF50; transition: width 0.3s ease; `; barContainer.appendChild(bar); progressBar.appendChild(progressText); progressBar.appendChild(barContainer); document.body.appendChild(progressBar); function getRandomUserAgent() { return USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)]; } function decodeContent(buffer) { const encodings = ['utf-8', 'gbk', 'gb2312', 'big5', 'gb18030']; for (let enc of encodings) { try { const decoder = new TextDecoder(enc, {fatal: true}); return decoder.decode(buffer); } catch(e) {} } return new TextDecoder('utf-8', {fatal: false}).decode(buffer); } async function fetchChapter(url, index) { return new Promise((resolve) => { GM_xmlhttpRequest({ method: "GET", url: url, headers: { "User-Agent": getRandomUserAgent(), "Referer": window.location.href }, responseType: "arraybuffer", onload: function(res) { try { const html = decodeContent(res.response); const parser = new DOMParser(); const doc = parser.parseFromString(html, "text/html"); // 修改后的内容选择器 // 使用 querySelector 获取 h1 标签 const title = doc.querySelector('h1.wap_none')?.textContent.trim(); const txtElement = doc.querySelector('#chaptercontent'); // 获取原始HTML内容处理换行 let content = txtElement?.innerHTML || ''; // 内容清洗 const cleaned = content // 1. 去除指定的p标签及其内容 .replace(/
[\s\S]*?<\/p>/gi, '')
// 2. 去除其他可能的干扰内容
.replace(/请收藏本站:https:\/\/www\.qu07\.cc。笔趣阁手机版:https:\/\/m\.qu07\.cc/gi, '')
// 3. 处理换行和格式
.replace(/
/gi, '\n')
.replace(/<\/p>|