星凰·众里寻她千百度

我们有幸降落在这个星球...这是他们一生也无法看到的风景...

目前為 2021-02-07 提交的版本,檢視 最新版本

// ==UserScript==
// @name			星凰·众里寻她千百度
// @version			5.21
// @author			科技星凰
// @namespace		https://space.bilibili.com/379335206
// @match			https://www.baidu.com/
// @match			https://www.baidu.com/?bs_nt=1
// @match			https://www.baidu.com/?tn=*
// @description		我们有幸降落在这个星球...这是他们一生也无法看到的风景...
// @require			https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @supportURL		https://jq.qq.com/?_wv=1027&k=IMqY916N
// @icon			https://cdn.jsdelivr.net/gh/loktindyi/mybaiduhp@master/tri-bdhp-icon.png
// @run-at			document-idle
// @grant			GM_addStyle
// @grant			GM_world.rise
// @grant			GM_world.take
// @grant			GM_deleteValue
// @grant			GM_xmlhttpRequest
// @note			5.20 这个版本准备了很久 修改过很多次 功能终于接近完善 因此直接跳到这个版本号 
// @note			5.21 星凰·新年祝愿:全新界面!
// ==/UserScript==

(() => {
	console.time("星凰·众里寻她千百度\n\t本次耗时");
	const NOTICE_TRISAY_KEEPER = 12; //NOTICE时长
	const TRI_UPDATE_NOTICE =
		`星凰·新年祝愿:<br>
		全新界面!<br>
		<span>
		欢迎使用《<strong>星凰·众里寻她千百度</strong>》
		<strong>右边缘双击</strong>可打开配置
		</span>
	`;
	const IMAGES = [
		"http://g.hiphotos.baidu.com/zhidao/pic/item/8644ebf81a4c510f973523a36b59252dd52aa592.jpg",
		"https://cdn.jsdelivr.net/gh/loktindyi/mybaiduhp@master/imgraw.png",
		"https://cdn.jsdelivr.net/gh/loktindyi/mybaiduhp@master/tri-bdhp-icon.png"
	];
	const SEASON_LOGO = [
		"", //春 未至
		"https://i0.hdslb.com/bfs/archive/e62b6b095ef38dfb742687f11e4b570dde420b5d.png",
		"https://i0.hdslb.com/bfs/archive/622017dd4b0140432962d3ce0c6db99d77d2e937.png",
		"https://i0.hdslb.com/bfs/vc/fb9521333b8ea79d90bdfc6da31cf83c52d93ec9.png"
	];
	const API = [
		"https://api.bilibili.com/x/web-show/res/locs?pf=0&ids=142",
		"https://www.bing.com/HPImageArchive.aspx?format=js&n=1"
	];
	const DEFAULT_CONFIG = {
		searchInputOpt: false,			//搜索框
		luma: false,					//流光
		vzin: false,					//维新
		pageTiltle: "众里寻她千百度",	//标题
		topLeft: false,					//左上角推广
		userList: false,				//右上角用户
		hotNews: false,					//新闻
		inputLenTillTop: [90, 280],		//搜索框位置
		inputFontSize: 20,		//字体大小
		pageBackgroundImg: IMAGES[0],//背景图片地址
		pageBackgroundImgBing: false,		//必应背景图
		replaceLogo: 233,				//logo
		season: 3,						//季节
		cusLogoUrl: "",					//自定义logourl
		tipDeLogo: "前往哔哩哔哩",		//logo提示语
		targetDeLogo: false,			//跳转方式
		logoLinksTo: "https://www.bilibili.com", //链接到
		thmColor: ["#222c", "rgb(250 114 152 / 1)", "#0000", "rgb(250 114 152 / .8)"],	//fc fo bg bd
		triSay: TRI_UPDATE_NOTICE		//triSay
	};
	const me = "ct";
	const TRI_HTML = [
		`<form action="/s" class="trifm"><input id="tript" type="text" name="wd" autocomplete="off" autofocus></form>`,
		`<input type="button" class="tri-dis btn" ondblclick="$('#tri-fds')[0].className=$('#tri-fds')[0].className!='in'?'in':'out'"><div id="tri-fds" class="ts" oninput="$('#tri-styles')[0].innerHTML=$('#tri-ell')[0].innerText"><fieldset><legend class="fdt">星凰·众里寻她千百度</legend><input type="button" class="save-btn b-a btn" title="保存" value="铭记"><br><br><hr><label><input id="vsearch" type="checkbox"> 搜索框优化 &nbsp&nbsp&nbsp&nbsp</label><label title="极简模式"><input id="luma" type="checkbox"> 流光 &nbsp&nbsp&nbsp&nbsp</label><label title="控制台输出更多信息"><input id="vzin" type="checkbox"> 维新</label><br>命名 <input id="pagetitle" type="text" class="fs-ipt" placeholder="垃圾百度,毁我青春"><br><label title="移除左上角推广"><input id="topleft" type="checkbox"> 不看推广 </label><label title="移除右上角"><input id="vuser" type="checkbox"> 不用登录 </label><label title="移除偶现的新闻"><input id="vnews" type="checkbox"> 不看新闻</label><br>搜索框位置 <input id="ipos" type="number" class="fs-ipt ipnum" oninput="$('#iptlen')[0].innerText=this.value" placeholder="90">字体大小 <input id="ipfz" type="number" class="fs-ipt ipnum" oninput="$('#kw')[0].value='字体大小'+this.value+'px';$('#iptfz')[0].innerText=this.value" placeholder="18"><br><div title="背景图">背景图 &nbsp&nbsp&nbsp&nbsp<label><input id="bgimg-bing" type="checkbox"> 与微软必应同步</label><br>或者 <input id="bgimg" style="width:70%" type="text" class="fs-ipt" placeholder="https...xxx.png/jpg" oninput="$('#sbgimg')[0].innerText=this.value==''?'':'background-image: url('+this.value+')'" autocomplete="off"></div><div title="关于LOGO...">传送 <select id="vlogo" onchange="$('#cuslgurl')[0].style.display=$('#op666')[0].selected?'block':'none'"><option value="0">不替换</option><option value="-2">隐藏式</option><option value="-1">移除</option><option value="1" style="color:#9ECE60">哔哩哔哩四季</option><option value="233" style="color:#fa7298">与哔哩哔哩同步</option><option value="666" id="op666">自定义</option></select><input id="cuslgurl" type="text" class="fs-ipt cus-lg" style="display:none" placeholder="https...xxx.png" autocomplete="off"></div>指引 <input id="lgtip" type="text" class="fs-ipt" style="width:50%" placeholder="你要去往哪里…"><br><div title="跳转方式">>>> <label><input id="lgtars" type="radio" name="target_de_logo"> 跃迁 </label><label><input id="lgtar" type="radio" name="target_de_logo"> 新世界</label></div>目标 <input id="lglinksto" type="text" class="fs-ipt" style="width:50%" placeholder="https...xxx.com" autocomplete="off"><br><div><span style="font-size:large;color:var(--thm-fo)">妖染</span><br>搜索框字体 <input id="thmcolor0" type="text" class="fs-ipt" oninput="$('#scolor0')[0].innerText=this.value" autocomplete="off"><br>主色调 <input id="thmcolor1" type="text" class="fs-ipt" oninput="$('#scolor1')[0].innerText=this.value" autocomplete="off"><br>背景 <input id="thmcolor2" type="text" class="fs-ipt" oninput="$('#scolor2')[0].innerText=this.value" autocomplete="off"><br>边框 <input id="thmcolor3" type="text" class="fs-ipt" oninput="$('#scolor3')[0].innerText=this.value" autocomplete="off"></div><input class="joinus b-a btn" type="button" onclick="window.open('https://jq.qq.com/?wv=1027&k=IMqY916N')" title="加入群" value="星凰不在" style="display: none" disabled></fieldset><br><div title="星凰言语"><span class="trilato">世人愿还天朗朗<br><img class="trimg" alt="星凰"><span>尘土之下骨凄凉</span></span></div></div><span id="tri-ell" style="display:none"></span><style id="tri-styles" type="text/css"></style>`
	];
	const TRI_CSS_TEXT = {
		searci: `html {overflow: hidden}#s_wrap {display: none}#head_wrapper .s_btn {opacity: 0}#head_wrapper .ipt_rec,#head_wrapper .soutu-btn {display: none}#head_wrapper #kw,#head_wrapper #kw:focus {background-image: linear-gradient(-45deg, transparent 8px, #fffd 0, #fffd calc(100% - 8px), transparent 0);color: var(--thm-fc) !important}#head_wrapper #form .bdsug-new {position: absolute;left: 7%;top: 55px !important;background-color: #fff0;background-image: linear-gradient(-45deg, transparent 8px, #fffd 0, #fffd calc(100% - 8px), transparent 0);border-radius: 0;border: none !important;position: absolute;top: 55px}.bdsug-s,.bdsug-s b {color: var(--thm-fo) !important;font-size: large !important}#head_wrapper #form .bdsug-new ul {border-top: none;}#head_wrapper .soutu-env-nomac #form #kw,#head_wrapper #form #kw {width: 618px !important;padding-right: 16px !important;border: none;border-radius: 0;background-color: var(--thm-bg);text-align: center}`,
		others: `#bottom_layer {display: none}#s_side_wrapper {display: none}#head_wrapper #kw {font-size: calc(var(--ipt-fz) * 1px)}#head .head_wrapper {top: calc(var(--ipt-len) * 1px)}.s-hotsearch-wrapper {display: none}#s_top_wrap {display: none}body {background-size: cover;background-attachment: fixed}#headwrapper #form .bdsug-new user_list {border-top-color: transparent}`,
		tris: `@keyframes appear {from {visibility: hidden;opacity: 0}to {visibility: visible;opacity: 1}}@keyframes fullfadeout {from {visibility: visible;opacity: 1}to {visibility: hidden;opacity: 0}}@keyframes fadeout {from {opacity: 0.85}to {opacity: 0}}@keyframes tminus {from {width: 0}to {width: 320px}}input[type=checkbox],input[type=radio] {position: relative;height: 0}input[type=checkbox]::before,input[type=radio]::before {content: "";width: 12px;height: 12px;position: absolute;left: 0;top: -12px;border: 1px solid var(--thm-fo);border-radius: 50%;}input[type=checkbox]:checked::before,input[type=radio]:checked::before {content: "";background-color: var(--thm-fo);}.trisay {user-select: none;overflow: hidden;min-width: 60px;background-image: linear-gradient(-45deg, transparent 5px, #fffd 0, #fffd calc(100% - 5px), transparent 0);opacity: 0.85;width: 320px;height: auto;font-size: 14px;min-height: 30px;color: var(--thm-fo);line-height: 30px;text-align: center;position: fixed;top: 60%;left: 40%;z-index: 998}.trisay span {font-size: smaller}.trisay hr {height: 5px;border: none;background-image: linear-gradient(-45deg, transparent 4px, var(--thm-fo) 0);animation: tminus var(--hr-time) linear forwards;z-index: 999}.fadeout {animation: fadeout 0.5s forwards}.ts {display: none;opacity: 0}.in {animation: appear 0.8s forwards}.out {animation: fullfadeout 0.8s forwards}.fs-ipt {padding-left: 5px;background-color: transparent;border-bottom: 1px solid var(--thm-fo);outline: none;height: 18px;font-size: 60%;z-index: 997}#vlogo {border: none;background-color: transparent;height: 16px;font-size: 12px;outline: none}.cus-lg {position: absolute;right: 10%;top: 38%;width: 38%}.ipnum {width: 12%}.btn {outline: none;position: absolute;}.b-a {background-image: linear-gradient(-45deg, transparent 6px, var(--thm-fo) 0, var(--thm-fo) calc(100% - 6px), transparent 0);background-color: transparent;color: white}.tri-dis {top: 0;right: -2px;width: 7px;height: 100%;background-color: transparent;background-image: linear-gradient(to left, var(--thm-fo), transparent);opacity: 0}.tri-dis:hover {animation: appear 0.1s linear forwards}.save-btn {font-size: large;top: 2%;right: 4%;width: 80px;height: 40px;z-index: 998}.joinus {bottom: 25%;right: 6%;width: 70px;height: 35px}.fdt {color: var(--thm-fo);font-size: 23px;position: absolute;top: 3%;left: 3%;}#tri-fds {position: fixed;top: 7%;right: 5%;border-color: #0000;padding: 15px;font-size: 14px;line-height: 200%;height: 600px;color: #222;width: 300px;background-image: linear-gradient(-45deg, transparent 15px, #fffd 0, #fffd calc(100% - 15px), transparent 0);text-align: left;user-select: none;z-index: 996}#tri-fds hr {height: 1px;border: none;background-color: var(--thm-fo);z-index: 997}.trilato {padding: 5px;background-image: linear-gradient(-45deg, transparent 10px, #fffd 0, #fffd calc(100% - 10px), transparent 0);position: absolute;width: 90%;height: 10%;cursor: pointer;font-size: large;color: var(--thm-fo)}.trilato span {position: absolute;right: 10px}.trimg {position: absolute;bottom: 8px;left: 10px;width: 32px}`,
		luma: `.trifm {margin: auto;top: calc(var(--ipt-len) * 1px)}#tript {border-bottom: solid 2px var(--thm-bd);outline: none;color: var(--thm-fc);background-color: var(--thm-bg);margin: auto;height: 40px;width: 540px;font-size: calc(var(--ipt-fz) * 1px);text-align: center;}`
	};
	const world = {
		draw: GM_addStyle,
		rise: GM_setValue,
		take: GM_getValue,
		execute: GM_deleteValue,
		require: GM_xmlhttpRequest,
		log: (say) => {
			console.log('%c TriLingvo %c\n' + say, 'color:#fff;background-color:#fa7298;border-radius:8px', '');
		},
		say: (msg, duration) => {
			duration = isNaN(duration) ? 3 : duration;
			world.draw(`:root{--hr-time: ` + duration + `s}`);
			let m = document.createElement('div');
			let n = document.createElement('hr');
			m.className = "trisay";
			m.innerHTML = msg;
			document.body.appendChild(m);
			m.appendChild(n);
			setTimeout(() => {
				m.className += " fadeout";
				setTimeout(() => {
					document.body.removeChild(m);
				}, 1000);
			}, duration * 1000);
		},
		update: () => {
			if (DEFAULT.triSay != User.triSay) {
				world.say(DEFAULT.triSay, NOTICE_TRISAY_KEEPER);
				User.triSay = DEFAULT.triSay
			};
			if (world.take("set")) {
				world.rise("USER_CONFIG", DEFAULT);
				world.execute("set");
				world.execute("uct")
			};
			if (User.inputUpDownPosition) {
				User.inputLenTillTop = DEFAULT.inputLenTillTop;
				delete User.inputUpDownPosition
			};
			if (User.thmColor[1] == "1") User.thmColor = DEFAULT.thmColor;
			if (User.triLingvo != undefined) delete User.triLingvo;
			if (User.vzin == undefined) User.vzin = false;
			if ([1, 2, 3, 4].indexOf(User.replaceLogo) != -1) User.replaceLogo = 1;
			if (User.season == undefined) User.season = 3;
			world.rise("USER_CONFIG", User);
			if (User.vzin) world.log('星凰升级完成')
		},
		savl: (settings) => {
			let els = {
				search: $('#vsearch')[0],
				luma: $('#luma')[0],
				vzin: $('#vzin')[0],
				pagetitle: $('#pagetitle')[0],
				topleft: $('#topleft')[0],
				user: $('#vuser')[0],
				news: $('#vnews')[0],
				ipos: $('#ipos')[0],
				ipfz: $('#ipfz')[0],
				bgimg: $('#bgimg')[0],
				bgimgbing: $('#bgimg-bing')[0],
				logo: $('#vlogo')[0],
				cuslgurl: $('#cuslgurl')[0],
				lgtip: $('#lgtip')[0],
				lgtar: $('#lgtar')[0],
				lglinksto: $('#lglinksto')[0],
				thmcolor0: $('#thmcolor0')[0],
				thmcolor1: $('#thmcolor1')[0],
				thmcolor2: $('#thmcolor2')[0],
				thmcolor3: $('#thmcolor3')[0]
				//Ne triSay
			};
			if (!settings) {	// save
				return {
					searchInputOpt: els.search.checked,
					luma: els.luma.checked,
					vzin: els.vzin.checked,
					pageTiltle: els.pagetitle.value,
					topLeft: els.topleft.checked,
					userList: els.user.checked,
					hotNews: els.news.checked,
					inputLenTillTop: User.luma ? [User.inputLenTillTop[0], els.ipos.value] : [els.ipos.value, User.inputLenTillTop[1]],
					inputFontSize: els.ipfz.value,
					pageBackgroundImg: els.bgimg.value,
					pageBackgroundImgBing: els.bgimgbing.checked,
					replaceLogo: parseInt(els.logo.value),
					season: User.season,
					cusLogoUrl: els.cuslgurl.value,
					tipDeLogo: els.lgtip.value,
					targetDeLogo: els.lgtar.checked,
					logoLinksTo: els.lglinksto.value,
					thmColor: [els.thmcolor0.value, els.thmcolor1.value, els.thmcolor2.value, els.thmcolor3.value]
				}
			} else {	// load
				els.search.checked = settings.searchInputOpt;
				if (settings.luma) {
					els.luma.checked = settings.luma;
					els.topleft.disabled = true;	// ban such settings
					els.user.disabled = true;
					els.news.disabled = true;
					els.logo.disabled = true;
					els.lgtip.disabled = true;
					$('#lgtars')[0].disabled = true;
					els.lgtar.disabled = true
				}
				els.vzin.checked = settings.vzin;
				if (settings.pageTiltle) els.pagetitle.value = settings.pageTiltle;
				els.topleft.checked = settings.topLeft;
				els.user.checked = settings.userList;
				els.news.checked = settings.hotNews;
				els.ipos.value = settings.luma ? settings.inputLenTillTop[1] : settings.inputLenTillTop[0];
				els.ipfz.value = settings.inputFontSize;
				els.bgimg.value = settings.pageBackgroundImg;
				els.bgimgbing.checked = settings.pageBackgroundImgBing;
				els.logo.value = settings.replaceLogo;
				els.cuslgurl.value = settings.cusLogoUrl;
				els.lgtip.value = settings.tipDeLogo;
				settings.targetDeLogo ? els.lgtar.checked = true : $('#lgtars')[0].checked = true;
				els.lglinksto.value = settings.logoLinksTo;
				els.thmcolor0.value = settings.thmColor[0];
				els.thmcolor1.value = settings.thmColor[1];
				els.thmcolor2.value = settings.thmColor[2];
				els.thmcolor3.value = settings.thmColor[3];
				if (settings.replaceLogo == 666) {
					els.cuslgurl.style.display = 'block';
					if (settings.vzin) world.log('自定义logo:\n\t' + (settings.cusLogoUrl == "" ? "地址为空" : settings.cusLogoUrl))
				}
			}
		}
	};
	//取得用户设定
	var User = world.take("USER_CONFIG", DEFAULT);
	world.update();
	world.log('欢迎来到这个星球。');
	if (User.vzin) world.log('维新开始工作。')
	let inputLenTillTop = User.luma ? User.inputLenTillTop[1] : User.inputLenTillTop[0];
	//预置的必需样式 others tris
	// world.draw(`:root{--wallpaper: url(` + IMAGES[2] + `)}`);
	world.draw(TRI_CSS_TEXT.others);
	world.draw(TRI_CSS_TEXT.tris);
	if (User.pageTiltle) document.title = User.pageTiltle;
	if (User.pageBackgroundImgBing) {
		world.require({
			method: "GET",
			url: API[1],
			onload: (b) => {
				let bing = 'https://www.bing.com' + JSON.parse(b.responseText).images[0].url;
				world.draw('body{background-image:url(' + bing + ')}');
				if (User.vzin) world.log('壁纸与微软必应同步:\n\t' + bing)
			}
		});
	};
	if (User.luma) {	//luma estas on
		world.draw(TRI_CSS_TEXT.luma)
		$('body')[0].innerHTML = TRI_HTML[0];
	} else {	//luma estas off
		if (User.searchInputOpt) world.draw(TRI_CSS_TEXT.searci);
		if (User.topLeft) world.draw(`.s-top-left{display: none}`);
		if (User.userList) {
			world.draw(`.s-top-right{display: none}`)
		}
		// else {world.draw(`.s-top-right .s-top-login-btn{display: none}`)}	//应当不需要这个
		if (User.hotNews) $("#m").remove();
		//elogo
		let lgs = User.replaceLogo;
		if (lgs) {
			let elogo = $("#s_lg_img")[0];
			switch (lgs) {
				case -2:
					elogo.style.opacity = "0";
					break;
				case -1:
					elogo.style.display = "none"; //移除
					break;
				case 1:
				case 233:
					world.require({
						method: "GET",
						url: API[0],
						onload: (r) => {
							let bili = JSON.parse(r.responseText).data[142][0].litpic.replace("http:", "https:");
							if (User.replaceLogo == 1) {
								elogo.src = SEASON_LOGO.indexOf(bili) == -1 ? SEASON_LOGO[User.season] : bili;
								if (User.vzin) world.log('logo同步哔哩哔哩四季\n\t' + SEASON_LOGO[User.season])
							} else {
								elogo.src = bili;
								if (User.vzin) world.log('logo与哔哩哔哩同步\n\t' + bili)
							};
						}
					});
					if (SEASON_LOGO.indexOf(elogo.src) != -1) {
						User.season = elogo.src;
						world.rise("USER_CONFIG", User)
					};
					break;
				case 666:
					if (User.cusLogoUrl == "") elogo.src = User.cusLogoUrl;
					break;
			};
			let mp = $("area")[0];
			if (lgs != -1) {	//-1 移除 无需替换
				mp.href = User.logoLinksTo;
				mp.target = User.targetDeLogo ? "_blank" : "_self";
				mp.title = User.tipDeLogo
			}
		}
	}
	let ct = document.createElement('div');
	ct.innerHTML = TRI_HTML[1];
	try {
		document.body.appendChild(ct);
		$('.trimg')[0].src = IMAGES[2];
		$('#tri-ell')[0].innerHTML = `
			body {<span id="sbgimg"></span>}
			:root{
				--ipt-len: <span id="iptlen">` + inputLenTillTop + `</span>;
				--ipt-fz: <span id="iptfz">` + User.inputFontSize + `</span>;
				--thm-fc: <span id="scolor0">` + User.thmColor[0] + `</span>;
				--thm-fo: <span id="scolor1">` + User.thmColor[1] + `</span>;
				--thm-bg: <span id="scolor2">` + User.thmColor[2] + `</span>;
				--thm-bd: <span id="scolor3">` + User.thmColor[3] + `</span>
			}
		`;
		$('#tri-styles')[0].innerHTML = `
			body {`+ (User.pageBackgroundImg == '' ? '' : 'background-image: url(' + User.pageBackgroundImg + ')') + `}
			:root{
				--ipt-len: ` + inputLenTillTop + `;
				--ipt-fz: ` + User.inputFontSize + `;
				--thm-fc: ` + User.thmColor[0] + `;
				--thm-fo: ` + User.thmColor[1] + `;
				--thm-bg: ` + User.thmColor[2] + `;
				--thm-bd: ` + User.thmColor[3] + `
			}
		`;
		$(document).on('click', '.trilato', () => {
			// window.open(IMAGES[1])
			world.rise(me, world.take(me, 0) + 1);
			switch (world.take(me)) {
				case 1:
					world.say("如果我能更快一点...", 2);
					setTimeout(() => {
						world.execute(me)
					}, 12000)
					break;
				case 2:
					world.say("她或许就不会死...", 2);
					break;
				case 3:
					world.say("她的荒落...", 1.5);
					break;
				case 4:
					world.say("不是...终点...", 4);
					world.execute("USER_CONFIG");
					world.execute(me);
					setTimeout(() => {
						alert("world.execute(me);");
						window.location.reload()
					}, 8000)
					break;
			};
		});
		$(document).on('click', '.save-btn', () => {
			world.say("记忆装填中...", 1);
			world.rise("USER_CONFIG", world.savl(0));
			setTimeout(() => {
				window.location.reload()
			}, 1500)
		});
		world.execute(me);
		world.savl(User);
	} catch (e) {
		console.log(e)
	}
	if (User.vzin) {
		console.log(world.savl(0))
		console.timeEnd("星凰·众里寻她千百度\n\t本次耗时")
	}
})();