Greasy Fork

Greasy Fork is available in English.

【网页标题助手】

自定义网页标题+相关工具

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         【网页标题助手】 
// @namespace    http://greasyfork.icu/
// @version      241009.13
// @description  自定义网页标题+相关工具
// @author       You
// @license      MIT
// @run-at       document-end
// @match        *://*/*
// @grant        GM_registerMenuCommand
// @grant        GM_setClipboard
// ==/UserScript==

(function() {
    'use strict';const $=(e)=>{return document.querySelector(e)};

let autoTitle=1;/*值为1时,无标题网页自动把域名作为标题*/

const siteRules=[
	{
		'name':'网站名称',
		'match':'匹配url正则。用构造函数创造的正则对象,需要常规的字符转义规则(在前面加反斜杠 \)',
		'title':'网页标题选择器/函数'
	},
	{
		'name':'微信公众号文章',
		'match':'mp.weixin.qq.com\\/s',
		'title':()=>{return document.title+'_'+$('#js_name').innerText.trim();}
	},
	{
		'name':'可爱TV',
		'match':'keai.cm\\/\\?.*?id=.*?',
		'title':'.text-container'
	}

];

function main(){

/*匹配自定义规则*/
for(let i of siteRules){
let ruleReg=new RegExp(i.match);
if(location.href.match(ruleReg)){
let title=typeof i.title=='function'?i.title():$(i.title)?.innerText;
title&&(document.title=title);
break;}
}

!document.title&&autoTitle=='1'&&(document.title=location.hostname);

}

setTimeout(main,1000);

GM_registerMenuCommand('【修改网页标题】',function(){let newTitle=prompt('想要什么标题,随心改',document.title);newTitle&&(document.title=newTitle);});
GM_registerMenuCommand('【复制网页标题】',function(){GM_setClipboard(document.title);});
GM_registerMenuCommand('【复制网页标题和网址】',function(){GM_setClipboard(`${document.title}\n${decodeURIComponent(location.href)}\n\n`);});

})();