// ==UserScript== // @name 修身学堂整页下载 // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author You // @match http://gdslzstsg.superlib.libsou.com/node/409.jspx* // @grant GM_download // @connect http://photoapps.yd.chaoxing.com/* // @downloadURL none // ==/UserScript== (function () { 'use strict'; const head = document.getElementsByTagName('head'); head[0].insertAdjacentHTML('beforeend', ``); const openDown2 = (url, title) => { GM_download({ url, name: title, headers: { Origin: '', Referer: '', }, onerror(e) { console.log('onerror', e) } }) } const getLastItem = arr => arr[arr.length - 1] const downloadfn = () => { document.querySelectorAll('#bookIFlist li').forEach(x => { const url = x.querySelector('a').href const title = x.querySelector('h2').innerText + '_' + getLastItem(url.split('/')) openDown2(url, title) }) } const downloadpage = () => { if (!JSON.parse(window.localStorage.hxconfirmed || 'false')) { if (window.confirm('点击 确认 之后会创建多个下载请求,请将浏览器设置的【每次询问文件保存位置 】关掉')) { window.localStorage.hxconfirmed = true downloadfn() } } else { downloadfn() } } const downEL = document.createElement('span') let length = '统计中…' downEL.innerText = '下载本页 ' + length setTimeout(_ => { downEL.innerText = '下载本页 ' + document.querySelectorAll('#bookIFlist li').length }, 1500) downEL.className = 'hx-download-the-page' downEL.addEventListener('click', downloadpage) document.querySelector('.instit h1').parentElement.insertAdjacentElement('beforeend', downEL) // Your code here... })();