Greasy Fork is available in English.

GB688 downloader;国标网下载

基于国标网显示规律在本地拼合成PDF并提供下载

// ==UserScript==
// @name         GB688 downloader;国标网下载
// @version      2024.09.26.01
// @license      Apache-2.0
// @namespace    https://github.com/yikuaibaiban/gb688_downloader
// @description  基于国标网显示规律在本地拼合成PDF并提供下载
// @author       yikuaibaiban
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAAXNSR0IArs4c6QAADoVJREFUeF7tnUuMXEcVhut2S2ETVokbe8V4AVKEJUxGWbvNxiwHNsDKYwmJFQqsvEDIthKJgISCSEQEEvFECIKlRG5FihQ2TAcRBUicBCmJwBZ4sqE9txVNrMQ8PPY0Os20057p+6hbp6pOnfv3xpKnbtU5//m/rqr76swI+IxGo6VOp7OaZdkxY0xfQEgIYU6BZy8MPvjPv/79ldOnH15vmzBZzIQ3NzfPZll2JmYMGLtagecvvmh+/4c/bR898sCJtkESBRCaMbrd7nnMFtXmlNCCAHnu4oumd+D+1kESHJDxeNyfTCatm6olGL1pDDNA6Pi2QRIUkN2Z42rTQuG4OArMA9I2SIICkuc5zRzYhMfxeeNR9wLSJkiCAZLn+aoxhvYd+CSmwCJA2gJJSEBoabWUmDcQrjGmCJA2QBIEEMweaXNWBoh2SEIBQksrWmLhk6ACVYBohiQUIFheJQjGLOQ6gGiFBIAkbNxQodcFRCMkoQCZhComxuFXwAYQbZAAEH4/qevRFhBNkAAQdXbmT6gJIFogASD8flLXY1NANEACQNTZmT8hF0BShwSA8PtJXY+ugKQMCQBRZ2f+hDgASRUSAMLvJ3U9cgGSIiQARJ2d+RPiBCQ1SAAIv5/U9cgNSEqQABB1duZPyAcgqUACQPj9pK5HX4CkAAkAUWdn/oR8AiIdEgDC7yd1PfoGRDIkAESdnfkTCgGIVEgACL+f1PUYChCJkAAQdXbmTygkINIgASD8flLXY2hAJEECQNTZmT+hGIBIgQSA8PtJXY+xAJEACQBRZ2f+hGICEhsSAMLvJ3U9xgYkJ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iQQoAEEHFQCjyFAAg8mqCiAQpAEAEFQOhyFMAgMirCSISpMC55eHgrE08al4c90Z/ZX1iTN8mebRtnQKtnkHOG2NWW1dyJFxbgY4xh78wHGzUPsAYo2YGebO/srRjzFWb5NG2VQqsLQ8Hp2wzVgMIJX6pv0IzCM0k+ECBeQU2loeDw00kUQXILiS0CTvTRAwco0+BzJjhg8PB8aaZqQOEhNhdbtGG/VhmzFJTcXBcmgpMjKF9xns7xgwfGg6GLlmoBMRFEBwLBeYVACDwAxQoUGA8Hvcnk8m6BoEyDUkgB1kK5Hmu5qQPAJHlLRXR5Hmu5toaAFFhSVlJaNl/kKoARJa3ko9mc3PzbJZlai4XAJDkLSkngdFotNTtdlXdlQFA5Pgr+UjyPKczV6pufAUgydtSRgIa4cAeRIa3ko5id1lFZ61UzRyzomAGSdqecYPXtiFfpCYAieux5EanGaPT6axmWXbStOB+vSCA7K5PkzMDAr5LAZVLqKoahwJkUhUI/g4FJCoAQCRWBTGJUQCAiCkFApGoAACRWBXEJEYBACKmFAhEogIARGJVEJMYBUIBQjew4Rl3MWVHIDUV2AgFiLqb2GoKjGZpKzAMAkgbbklI2weIvkCBtSCAaHqIH1ZqjwJZlh0PAoj2Oz7bY5lWZbrR6/UOBwGEZNX0potW2aSlydLsceDAgTB7kJnGWh+qaamHNKc97PV609euBptBaLDdpRad0cIpX832Sju36dJqlkJQQABJ2s5pQfQbWZadoqVVNEDmIKFXw+CHe1rgukRSvLOsmo83+AwyP/juxp2eTGvlwziJGEd7mPRG+3O9Xm9tUaJRAZkFNPcY57Hd/8MeRbst4+a3MZlMXt7Z2Vk7dOhQ6U/L/Q+Qj7nnIJSsugAAAABJRU5ErkJggg==
// @match        http://c.gb688.cn/*
// @grant        none
// ==/UserScript==

(function initStyles() {
    let style = document.createElement("style");
    style.appendChild(document.createTextNode(`.downloader_container {	position: fixed;	height: 40px;	width: 120px;	top: calc(50% - 20px);	right: 20px;}.downloader_container button {	width: 100%;	height: 40px;	background-color: blueviolet;	border: none;	color: white;	line-height: 40px;	text-align: center;	font-size: 20px;	border-radius: 5px;	transition: all 0.3s;	display: flex;	justify-content: center;    align-items: center;}.downloader_container button:hover {	background-color: dodgerblue;}@keyframes loading {	0% {		transform: rotate(0deg);	}	100% {		transform: rotate(360deg);	}}.loading {	width: 18px;	height: 18px;	margin-right: 5px;    animation: loading 1s infinite;}`));
    document.head.appendChild(style);
})();

function downloadPDF() {
	let downloadBtn = document.querySelector('#downloadBtn');
	downloadBtn.disabled = true;

	let loadingIcon = new Image();
	loadingIcon.src =
		'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAAXNSR0IArs4c6QAAD3dJREFUeF7tXdFx3DgMlSbpI8mHdsZVnF2J7Up8riR2JdlUkZndDzt9aEdn6CSPLEsiCIIiJL79yc2ZIsEHPBIkQbAs8NsUAqfT6a4oin+Korgmwcuy/N40zWtZlq9FUfx++//HqqqOm+qUYWFLw7JBtAEC5/P536IoHpigHJumeT4cDk/M8ig2gwAI4jANGrG7UfpbWZZ/aYSu6/r16uqKRuzov/P5fN00zU+SQdAYyXq/lqwC+cx/AoJMqKhzYx4cRtmO0pfL5RjLAIkcb+7UrxArIvfrcrncxJIxRLYtfAuCfHRjyCDJjWn9e+YvyiitQY6h/HVd/wBJmBodFANBOjBCDbJpmnstn//Pnz/fv379+uKvzvkvMJPI0ARBiqLo1hk/ZRB++OpGYwfpdDq9CNccri48VlVFi338mAhkTxDt0TrUlQmdyVx6D5XPVf/e/p49Qc7nMy2CfdYcLhugc4gbV6G5v0ecPfomMYt4KCdrgsQaraWjtPZsNmcHVVVlrXcPfhRZAxVh9uixF80inoeBPnr+UFZKYHGDG/4wW4LEHq0lRhiRsB9MVHPHbcO2zxI9W4Io7lxNAi0xwhXWH62sTdM8HQ6He5aFZF4oW4LEdmckBDmfz80a9giC8FEGQfhYeZWUGOFaM0gX8SveaZsCotvwKChOjf6+l1P7bAlyOp0oAJBCx6P8LBNEItsYpD7sf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QgyGeCNC79p7zR2EU+t9eTy7L8u9cDOpcO1vo7CDJAuosDe3GBnyqkYko+ZHpxaSvs7yDIAD9udpVUBFlYG8HtC+PB7NcgyAga5v341S9tuWY33NOPwxAQ5DNB6D7K3RzcqUK6XbMbCAKCxEFgVKvr+m/KBfrc7JaKtKsoJHEjmEEmFNDnCW6a5nt/u/Htv5/KsnyuquqYSmcLW9Cru3ypMFi7XRDEgTi5NnVdv1o5HDydTndlWd4SeSnzfWrSrm2wa7f3H1+NZplzxdt4AAAAAElFTkSuQmCC';
	loadingIcon.className = 'loading';
	downloadBtn.insertBefore(loadingIcon, downloadBtn.children[0]);

	let pheight = document.querySelector('div.page').clientHeight;
	let pwidth = document.querySelector('div.page').clientWidth;

	let qwidth = pwidth * 0.1;
	let qheight = pheight * 0.1;

	let canvasArray = new Array();
	let imagesArray = new Array();

	document.querySelectorAll('.page').forEach(function (elem, i) {
		let canvas = document.createElement('canvas');
		canvas.width = pwidth;
		canvas.height = pheight;
		canvas.setAttribute('complete', '0');
		canvasArray.push(canvas);

		let ctx = canvas.getContext('2d');
		ctx.fillStyle = 'white';
		ctx.fillRect(0, 0, pwidth, pheight);

		let image = new Image();
		imagesArray.push(image);

		image.src = elem.hasAttribute('bg')
			? elem.getAttribute('bg')
			: $(elem)
					.children('span')
					.first()
					.css('background-image')
					.split('"')[1]
					.split(/\\/)
					.slice(-1)[0];

		image.addEventListener('load', (e) => {
			$(elem)
				.children('span')
				.each(function (j, s) {
					ctx.drawImage(
						image,
						-parseInt($(s).css('background-position-x')),
						-parseInt($(s).css('background-position-y')),
						qwidth,
						qheight,
						$(s).attr('class').split('-')[1] * qwidth,
						$(s).attr('class').split('-')[2] * qheight,
						qwidth + 1,
						qheight
					);
				});
			canvas.setAttribute('complete', '1');
		});
	});

	let timer = setInterval(() => {
		for (let i = 0; i < canvasArray.length; i++) {
			const element = canvasArray[i];
			if (element.getAttribute('complete') != '1') {
				return;
			}
		}

		const { jsPDF } = window.jspdf;
		const pdf = new jsPDF('p', 'px', [pwidth, pheight]);

		let title = $('title').text().split('|')[1].toString().trim();
		canvasArray.forEach(function (e, i) {
			pdf.addImage(
				e.toDataURL('image/jpeg'),
				'jpeg',
				0,
				0,
				pwidth,
				pheight,
				'',
				'MEDDIUM'
			);
			pdf.addPage();
		});

		let targetPage = pdf.internal.getNumberOfPages();
		pdf.deletePage(targetPage);

		pdf.save(title + '.pdf');
		clearInterval(timer);
		downloadBtn.disabled = false;
		downloadBtn.removeChild(downloadBtn.children[0]);
	}, 500);
}

function init() {
	var jspdfScript = document.createElement('script');
	jspdfScript.src =
		'https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js';
	document.querySelector('head').appendChild(jspdfScript);

	var container = document.createElement('div');
	document.querySelector('body').appendChild(container);
	container.className = 'downloader_container';

	var downloadButton = document.createElement('button');
	container.appendChild(downloadButton);
	downloadButton.innerHTML = '<span>下载PDF</span>';
	downloadButton.addEventListener('click', downloadPDF);
	downloadButton.id = 'downloadBtn';
}



(async function () {
    init()
})();