// ==UserScript== // @name 起点小说优化|VIP章节免费阅读|支持本章说显示|自动翻页|简洁风格 // @version 1.4.5.2 // @description 提供多功能的起点小说网站优化插件,支持多书源、本章说、翻译、净化等功能 // @author JiGuang // @namespace www.xyde.net.cn // @homepageURL https://51coolplay.cc // @match https://www.qidian.com/* // @match https://51coolplay.cc/service/* // @require https://cdn.jsdelivr.net/npm/sweetalert2@11 // @require https://cdn.staticfile.org/jquery/2.0.3/jquery.min.js // @grant GM_setValue // @grant GM_getValue // @grant GM_openInTab // @grant GM_xmlhttpRequest // @grant GM_registerMenuCommand // @license MIT // @downloadURL none // ==/UserScript== (function() { const default_config = `[{"id":1,"open":true,"name":"读书阁书源","author":"Hunter David","offical":false,"version":"1.0.3","description":"文章正文换成读书阁的书源,修复已购买仍然加载的问题","code":"async function onLoad() {function setStatusText(txt){try{document.querySelector('#reader-content > div.min-h-100vh.relative.z-1.bg-inherit > div > div.relative > div > div.text-s-gray-500.mt-4px.text-bo4.flex.items-center.flex-wrap').innerHTML = txt;}catch(err){console.warn('设置失败');}}if(isBuy()){setStatusText('起点小说优化|您已购买本章');return;}setStatusText('起点小说优化|正在加载内容中...');const DOMAIN = 'http://www.dushuge.com/';const book_res_doc = await parseDocFromAjax('get','http://www.dushuge.com/hsdgiohsdigohsog.php?ie=gbk&q=' + readBookName());let books = [];book_res_doc.querySelectorAll('div.bookinfo > h4 > a').forEach((item, index) => {if(item !== undefined){books.push({name:item.innerText,url:item.href,val:calculateTextSimilarity(readBookName(),item.innerText)});}});books.sort((a, b) => b.val - a.val);if(books.length === 0){notify('未找到该书','error');return;}let book = books[0];let chapters = [];const chapter_res_doc = await parseDocFromAjax('get',book.url.replace('https://www.qidian.com/', DOMAIN));chapter_res_doc.querySelectorAll('dl > dd > a').forEach((item, index)=>{if(item !== undefined){chapters.push({name:item.innerText,url:item.href,val:calculateTextSimilarity(readChapterName(),item.innerText)});}});chapters.sort((a, b) => b.val - a.val);if(books.length === 0){notify('未找到该书有效的目录','error');return;}let chapter = chapters[0];const content_res_doc = await parseDocFromAjax('get',chapter.url.replace('https://www.qidian.com/', DOMAIN));const targetContent = content_res_doc.querySelector('#content').innerText;writeContent(targetContent);notify('读书阁书源读取成功');setStatusText('起点小说优化|正在使用读书阁书源阅读');}"},{"id":9999,"open":true,"name":"开启本章说","author":"Hunter David","offical":true,"version":"1.0.0","description":"把阅读页面上的文本重新调整匹配到本章说,已测试读书阁书源可用,其他自测","code":"setTimeout(function() {if(isBuy()){loadComment();}}, 3500);"}]` // 取脚本版本 function getVersion(){ return '1.4.5.2' } // 首次更新到新版本的提示 function firstTip(){ if(GM_getValue('qdv_'+getVersion(),'') == ''){ Swal.fire({ title: "👏欢迎使用起点小说优化", text: "1.4.5更新了本章说显示支持,默认开启,可前往插件设置中更换书源和开关本章说、净化等功能(旧版本升级用户需要去设置里开启)", icon: "success" }) GM_setValue('qdv_'+getVersion(),'read_notice') } } // 脚本专用:读取配置到51 function read51Config(){ // 如果空,就默认装一下插件 //console.log('config',GM_getValue('config',default_config)) document.querySelector("#config").value = GM_getValue('config',default_config) } // 脚本专用:从51写配置 function save51Config(){ GM_setValue('config',document.querySelector("#config").value) } // 脚本专用:运行开启的配置 function readConfigOpen(is_read_page = true){ function add_float_menu(){ let div = document.createElement('div') div.innerHTML = '
' document.body.appendChild(div); document.querySelector("#b56").onclick = ()=>{ GM_openInTab('https://51coolplay.cc/service/book/settings.php') } } window.onLoad = ()=>{ notify('您在当前页面没有开启任何插件!!','error') add_float_menu() } let codes = '' try{ const config_str = GM_getValue('config',default_config) // console.log(config_str) const config_items = JSON.parse(config_str) // console.log(config_items) //筛选插件代码 if(is_read_page){ codes = config_items.filter(e => e.open).map(e => e.code).join(';') }else{ //全局起点页面插件需要配置global=true,然后插件里自己设计路径检测 codes = config_items.filter(e => e.open).filter(e => e.global).map(e => e.code).join(';') } }catch(err){ console.warn('加载配置失败0',err) notify('加载配置失败,请去设置页面重新配置','error') add_float_menu() return } //注入插件 console.log(codes) try{ eval(codes) //执行启动函数(书源专用)注意,设置中的自定义插件会默认添加onload函数包裹 onLoad() }catch(err){ console.warn('加载配置失败',err) notify('加载配置失败,请去设置页面检查是否启用了不兼容的插件','error') add_float_menu() return } } // 内置函数:读取页面书名 function readBookName(){ const bookNameElement = document.querySelector("#r-breadcrumbs > a.text-s-gray-900"); if (bookNameElement) { // 使用正则表达式去掉括号内的内容 const rawName = bookNameElement.innerText; const cleanedName = rawName.replace(/\([^)]*\)/g, '').trim(); console.log(`BookName:${cleanedName}`) return cleanedName; } else { return '未知' // 或者返回一个默认的名称,或者抛出错误,具体根据需求来定 } } // 内置函数:读取章节名 function readChapterName(){ let ele = document.querySelector("#reader-content > div.min-h-100vh.relative.z-1.bg-inherit > div > div.relative > div > h1") if (ele) { let res = '' + ele.innerText res = res.replace(' ', '') console.log(`BookChapter:${res}`) return res } return '未知' } // 内置函数:读取正文 function readContent(){ return document.querySelector("#reader-content > div.min-h-100vh.relative.z-1.bg-inherit > div > div.relative > div > main").innerText } // 内置函数:将请求的url的html内容转化成document对象 async function parseDocFromAjax(method,url){ console.log('请求url:',url) return new Promise((resolve,reject) => { GM_xmlhttpRequest({ method, url, onload:(res) => { //console.log('response',res) let htmldoc = document.createElement('html') let htmlstr = res.responseText // 修复 某图片自动加载的问题 htmlstr = htmlstr.replace(/http /g, "https") htmlstr = htmlstr.replace(/img src/g, "a url") htmlstr = htmlstr.replace(/onerror/g, "class") htmldoc.innerHTML = htmlstr resolve(htmldoc) }, onerror:(err) => { reject(err) } }) }) } // 内置函数:axios/fetch风格的跨域请求 async function request(url,data = '',method = 'GET'){ console.log('请求url1:',url) return new Promise((resolve,reject) => { GM_xmlhttpRequest({ method, url, data, onload:(res) => { //console.log('response1',res.response) resolve(JSON.parse(res.response)) }, onerror:(err) => { reject(err) } }) }) } async function loadComment(){ //先加载本章说 let cid = location.href.split('/')[location.href.split('/').length-2] let bid = location.href.split('/')[location.href.split('/').length-3] const res = await request(`https://www.qidian.com/ajax/chapterReview/reviewSummary?_csrfToken=${document.cookie.split(';').find(e=>e.indexOf("_csrfToken")!=-1).split('=')[1]}&bookId=${bid}&&chapterId=${cid}`, true) let content = document.querySelector("#reader-content > div.min-h-100vh.relative.z-1.bg-inherit > div > div.relative > div > main").innerHTML let txts = content.split('${txt}${num}
` let comment_ui = ` ` contents += plus contents += comment_ui }) document.querySelector("#reader-content > div.min-h-100vh.relative.z-1.bg-inherit > div > div.relative > div > main").innerHTML = contents txts.forEach((item,index) =>{ document.querySelector("#content-"+(index + 1)).addEventListener("click", async function() { // 显示本章说吧!(等到点击的时候再加载书评,省流) console.log('click'+(index + 1)) let template_contents = '' //请求起点的书评API,自己动手,丰衣足食~ let res = await request(`https://www.qidian.com/ajax/chapterReview/reviewList?bookId=${bid}&chapterId=${cid}&page=1&pageSize=20&segmentId=${index+1}&type=2&_csrfToken=${document.cookie.split(';').find(e=>e.indexOf("_csrfToken")!=-1).split('=')[1]}`) res.data.list.forEach((item,index)=>{ let template_unit = `精华${item.content}