homoer enhancement

made by SC

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         homoer enhancement
// @version      1.0
// @match        http*://*.homoer.com/*
// @description  made by SC
// @license      MIT
// @namespace    https://greasyfork.org/users/1010601
// ==/UserScript==
async function parse(url){
	const html=await (await fetch(url)).text(),key1='class="guest_box"';
	return html.substring(html.indexOf(key1)+key1.length,html.lastIndexOf('adsbygoogle.js'))
		.split(key1).filter(p=>!p.match(/這邊有一段限制閱讀文字|已經過期,無法閱讀/)).map((p,r)=>(
	r=[...p.matchAll(/(?:reply_by">|guest_time">|ip_flag' )(.+?)<\/span>/g)].map(m=>m[1]),
		r[3]=p.substring(...[...p.matchAll(/<div class="HTML_info"/g)].map(m=>m.index))
			.replaceAll(/<[^>]+>|[\t\r ]+/g,'').slice(1,-1).replaceAll(/\s*\n+\s*/g,'<br/>'),r));
}

function addRows(ol,page,rows){
    if(rows.length)rows.forEach(([name,time,ip,msg],i)=>ol.append(i>0||1==page?ip?
    `<li>${msg}<a class="guest_option_top">${name} (<img class='ip_flag' ${ip} ${time}</a></li>`:
    `<li>${msg}<a class="guest_option_top">${name}${time}</a></li>`:`<hr/>page #${page}`));
}

function createRoot(title){
    const ol=$(`<ol class="footer" style="padding:revert;background:black;color:white;font:12pt monospaced">${title}</ol>`);
	$('.footer').parent().empty().append(ol);
    return ol;
}

async function viewAll(tr){
	const {href,textContent:title}=tr.querySelector('a:first-child'),{textContent:pages}=tr.querySelector('a:last-child');
	const ol=createRoot(title.trim()),url=href.substring(0,href.lastIndexOf('=')+1);
	for(let i=1,n=~~pages||1;i<=n;i++)addRows(ol,i,await parse(url+i));
}

async function viewMore(href,param){
    const ol=createRoot(''),url=href.substring(0,href.lastIndexOf('=')+1),pages=~~param.get('p'),end=Math.max(pages-30,1);
    for(let page=pages;page>end;page--)addRows(ol,page,await parse(url+page));
    ol.append(`<hr/><a href="${url}${end}" style="color:pink">page #${end} &gt;</a>`);
}

let dom;
if((dom=document.querySelectorAll('#article_list tr:not(:first-child)')).length)
    for(const tr of dom)tr.addEventListener('click',e=>viewAll(tr));
else if((dom=document.querySelectorAll('#page_block .page_nr')).length)
    viewMore(location.href,new URLSearchParams(location.search));//{href,textContent}=dom[dom.length-1]