蛋图

煎蛋首页右侧看图

当前为 2025-05-24 提交的版本,查看 最新版本

// ==UserScript==
// @name         蛋图
// @version      1.0.0
// @description  煎蛋首页右侧看图
// @author       Jack.Chan
// @namespace    http://fulicat.com
// @url          https://greasyfork.org/zh-CN/scripts/537058
// @match        https://jandan.net/*
// @grant        none
// @run-at       document-end
// @license MIT
// ==/UserScript==

(() => {

	const regHTTP = /^http:/i;
	const regLowDefinition = /\/(mw600|thumb180)\//i;

	function replaceSrc() {
		const $imgs = document.querySelectorAll('.sidebar .hot-list img');
		// console.log($imgs);
		let $p = null;
		let src = null;
		$imgs.forEach((img) => {
			src = null;
			if (regHTTP.test(img.src)) {
				src = img.src.replace(regHTTP, 'https:');
			}
			if (regLowDefinition.test(img.src)) {
				src = (src || img.src).replace(regLowDefinition, '/large/');
			}
			if (src) {
				img.src = src;
				img.hasReplaced = true;
			}
			$p = document.createElement('p');
			$p.style.cssText = `margin: 20px 0 5px 0;`;
			$p.innerHTML = `<a style="color:#0d6efd;" target="_blank" href="${ img.src }">查看原图</a>`;
			img.parentNode.insertBefore($p, img);
			img.parentNode.querySelector('.gif-mask')?.remove();

		});
	}

	let $tabs = null;
	function init() {
		if ($tabs || $tabs && $tabs.hasBind) return;
		$tabs = document.querySelector('.hot-tabs');
		// console.log('$tabs', $tabs);
		if ($tabs) {
			$tabs.hasBind = true;
			$tabs.addEventListener('click', () => {
				setTimeout(replaceSrc, 1000);
			});
		}
	}

	init();

	setTimeout(() => {
		init();
		replaceSrc();
	}, 2000);

})();