Replace Title Conlon

Replace Title Conlon in the web page

目前為 2023-11-20 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name               Replace Title Conlon
// @namespace          h
// @version            1.0
// @description        Replace Title Conlon in the web page
// @author             amormaid
// @include            http*://*/*
// @grant              none
// @run-at             document-end
// @license            MIT License
// ==/UserScript==
 
(function() {
    'use strict';
 

	function is(target, type){
		return Object.prototype.toString.call(target).slice(8, -1).toLowerCase() === `${type}`.toLowerCase()
	}

	function get_the_most_used_fontsize() {
		let nodes = document.querySelectorAll('*');
		let nodes_filtered = Array.from(nodes).filter(e => {
			let is_non_text = ['SCRIPT', 'STYLE', 'TEXTAREA'].includes(e.nodeName);
			let is_text = e.childNodes.length && is(e.childNodes[0], 'text');
			return !is_non_text && is_text
		});

		let statistics = nodes_filtered.reduce((acc, cur) => {
			let fontSize = getComputedStyle(cur).fontSize
			acc[fontSize] = (acc[fontSize] || 0) + 1
			return acc
		},{})
		let the_most_used = Math.max(...Object.values(statistics))
		let the_most_used_fontsize = Object.keys(statistics).find(key => statistics[key] === the_most_used)
		return the_most_used_fontsize
	}

	let content_fontsize = parseInt(get_the_most_used_fontsize())

	let content_to_replaced = Array.from(document.querySelectorAll('*')).filter(e => !['SCRIPT', 'STYLE', 'TEXTAREA'].includes(e.nodeName) && e.childNodes.length && is(e.childNodes[0], 'text') && e.innerText.includes(':'))

	content_to_replaced.forEach(e => {
		if(parseFloat(getComputedStyle(e).fontSize) > content_fontsize) {
			console.log('replcing ', e)
			e.innerHTML = e.innerHTML.replace(':', ' ')
			e.style.color = 'red'
		}
	})
 
})();