nhentai布局优化

优化页面布局

// ==UserScript==
// @name         nhentai布局优化
// @namespace    https://greasyfork.org/zh-CN/scripts/469945
// @version      0.6
// @description  优化页面布局
// @author       雷锋
// @match        http*://nhentai.net/*
// @icon         http://nhentai.net/favicon.ico
// @grant        none
// ==/UserScript==

(async () => {
	let Sleep = (millisecond) => new Promise((resolve) => setTimeout(resolve, millisecond));
	// 优化翻页按钮布局
	(async () => {
		while (!document.querySelector('.pagination')) await Sleep(200);
		var htmlLabelPG = '';
		var htmlLabelFL = '';
		document.querySelectorAll('.pagination>a').forEach((node) => {
			node.classList.contains('page') ? (htmlLabelPG += node.outerHTML) : (htmlLabelFL += node.outerHTML);
		});
		if (!htmlLabelFL.includes('first')) htmlLabelFL = '<a></a><a></a>' + htmlLabelFL;
		if (!htmlLabelFL.includes('last')) htmlLabelFL = htmlLabelFL + '<a></a><a></a>';
		document.querySelector('.pagination').innerHTML = `
        <style>.menutab{display:flex;justify-content:space-between;}</style>
        <div class="menutab">${htmlLabelPG}</div>
        <div class="menutab">${htmlLabelFL}</div>
        <div class="ios-mobile-webkit-bottom-spacing">&nbsp;&nbsp;</div>
        `;
        console.log(`已优化布局`, location.href);
	})();

	// 优化阅览体验
	(async () => {
		while (!document.querySelector('.thumb-container img')) await Sleep(200);
		document.querySelectorAll('.thumb-container a').forEach((node) => node.removeAttribute('href'));
		document.querySelectorAll('.thumb-container img').forEach((img) => {
			let src = img.getAttribute('data-src').replace(/\/t(\d+)/, '/i$1').replace(/t(\.[a-z]+)$/, '$1');
			img.setAttribute('data-src', src);
			if (img.src.startsWith('https://t')) img.src = src;
		});
		document.body.insertAdjacentHTML('beforeend', `<style>.thumb-container, .thumb-container img {width: 100%;height: auto;}</style>`);
        console.log(`已优化页面`, location.href);
	})();
})();