Skip to main content

html网页打包下载

// ==UserScript==
// [url=home.php?mod=space&uid=170990]@name[/url] **文学电子书下载
// [url=home.php?mod=space&uid=467642]@namespace[/url] http://tampermonkey.net/
// [url=home.php?mod=space&uid=1248337]@version[/url] 2024-01-31
// @description 打包下载**文学电子书下载!
// [url=home.php?mod=space&uid=686208]@AuThor[/url] You
// [url=home.php?mod=space&uid=195849]@match[/url] https://www.*ing*ue*oke.com/*/
// [url=home.php?mod=space&uid=593100]@Icon[/url] https://www.*ing*ue*oke.com/favicon.ico
// [url=home.php?mod=space&uid=609072]@grant[/url] none
// ==/UserScript==

(function() {
'use strict';
var contentList = document.getElementById('content-list')
if(contentList === null){
return;
}
var bookDescribe = contentList.querySelector('.book-describe').innerText;
var metas = bookDescribe.split('\n\n');
var title = metas[0];
var author = metas[1].split(':')[1];
var guojia = metas[2].split(':')[1];
var niandai = metas[3].split(':')[1];
var description= metas[5];
var booklist = document.querySelector('.book-list');
var sections = [];
var tasks = [];
booklist.querySelectorAll('a').forEach(function(a,i){
sections.push({title:a.title,content:i});
var t = fetch(a.href).then(function(response){
return response.text()}
).then(function (text) {
var div = document.createElement('div');
div.innerHTML = text;
var nr1=div.querySelector('#nr1 div');
sections[i].content = nr1.innerHTML;
});
tasks.push(t);
});
Promise.all(tasks).then(function(){
var html = ['<!DOCTYPE html>',
'<html lang="zh-CN">',
'<head>',
'<meta charset="utf-8">',
'<meta name="author" content="' + author + '">',
'<meta name="description" content="'+ description +'">',
'<title>' + title + '</title>',
'</head>',
'<body>',
'<article>',
'<h1>' + title + ' <small> '+ author +'</small></h1>'];
sections.forEach(function(section){
html.push('<section>');
html.push('<h2>' + section.title + '</h2>');
html.push(section.content);
html.push('</section>');
});
html.push('</article>');
html.push('</body>');
html.push('</html>');
contentList.querySelector('.book-describe').innerHTML = '<p><a id="download">点击下载电子书</a></p>' + contentList.querySelector('.book-describe').innerHTML;
var a = document.getElementById('download');
a.href = 'data:text/plain;charset=utf-8,'+html.join('\n');
a.download = title + '.html';
});
})();