ori_hzoj

【数据删除】太好用了,你知道吗

// ==UserScript==
// @name         ori_hzoj
// @namespace    http://tampermonkey.net/
// @version      2025-11-16
// @description  bring Hitokoto back and remove the calendar on hzoj main page
// @author       Gon_Tata
// @match        https://h.hszxoj.com
// @match        https://h.hszxoj.com/d/hztg/
// @icon         https://cdn.luogu.com.cn/upload/image_hosting/evr4azbb.png
// @grant        none
// ==/UserScript==

(function() {
	'use strict';
	function onReady(fn) {
		if (document.readyState !== 'loading') {
			fn();
		} else {
			document.addEventListener('DOMContentLoaded', fn);
		}
	}

	onReady(() => {
		try {

			const calendars = document.querySelectorAll('.index-calendar');
			calendars.forEach(cal => {
				const big = cal.querySelector('.punch-big');
				if (big) cal.remove();
			});

			const colRight = document.querySelector('.large-3.columns');
			if (!colRight) return;

			const headerToRemove = colRight.querySelector('.section__header');
			if (headerToRemove) {
				headerToRemove.remove();
			}

			const section = document.createElement('div');
			section.className = 'section side visible';

			const header = document.createElement('div');
			header.className = 'section__header';
			const h1 = document.createElement('h1');
			h1.className = 'section__title';
			h1.style.textAlign = 'left';
			h1.textContent = 'Hitokoto';
			header.appendChild(h1);

			const body = document.createElement('div');
			body.className = 'section__body';
			body.style.textAlign = 'center';

			const quote = document.createElement('div');
			quote.className = 'hitokoto-quote';
			quote.style.fontSize = '17px';
			quote.style.lineHeight = '1.6';
			quote.style.wordBreak = 'break-word';
			quote.style.whiteSpace = 'normal';
			quote.style.padding = '14px 12px';
			quote.style.minHeight = '60px';
			quote.textContent = '加载中……';

			const sourceWrap = document.createElement('div');
			sourceWrap.style.display = 'flex';
			sourceWrap.style.justifyContent = 'space-between';
			sourceWrap.style.alignItems = 'center';
			sourceWrap.style.marginTop = '8px';

			const emptyLeft = document.createElement('div');
			emptyLeft.style.flex = '1';

			const sourceRight = document.createElement('div');
			sourceRight.style.flex = '1';
			sourceRight.style.textAlign = 'right';
			sourceRight.style.fontSize = '15px';
			sourceRight.className = 'hitokoto-from';
			sourceRight.textContent = '';

			sourceWrap.appendChild(emptyLeft);
			sourceWrap.appendChild(sourceRight);

			body.appendChild(quote);
			body.appendChild(sourceWrap);

			section.appendChild(header);
			section.appendChild(body);

			const existingSections = Array.from(colRight.querySelectorAll(':scope > .section'));
			if (existingSections.length >= 1) {
				const ref = existingSections[0].nextSibling;
				if (ref) colRight.insertBefore(section, ref);
				else colRight.appendChild(section);
			} else {
				colRight.appendChild(section);
			}

			fetch('https://v1.hitokoto.cn/?c=a&c=b&c=c&c=d&c=e&c=f&c=h&c=i&c=j&c=k&c=l')
				.then(resp => {
					if (!resp.ok) throw new Error('网络错误 ' + resp.status);
					return resp.json();
				})
				.then(data => {
					if (!data) throw new Error('返回数据为空');
					const text = data.hitokoto || data.hitokoto || '';
					const from = data.from || '';
					quote.textContent = text;
					sourceRight.textContent = from ? '——'+from : '-- 无来源 --';
				})
				.catch(err => {
					quote.textContent = '获取失败';
					sourceRight.textContent = '--';
					console.error('Hitokoto 获取失败', err);
				});
		} catch (e) {
			console.error('脚本执行异常', e);
		}
	});
})();
posted @ 2025-11-16 16:16  Gon-Tata  阅读(11)  评论(0)    收藏  举报