网络百科聚合

同一词条在网络百科中互相跳转

目前为 2018-12-22 提交的版本。查看 最新版本

// ==UserScript==
// @name         网络百科聚合
// @version      0.94
// @description  同一词条在网络百科中互相跳转
// @include
// @match        *://baike.baidu.com/*
// @match        *://zh.wikipedia.org/*
// @match        *://baike.sogou.com/*
// @match        *://www.baike.com/*
// @match        *://baike.chinaso.com/*
// @grant        来自各个网络百科
// @author       太史子义慈
// @namespace    [email protected]
// ==/UserScript==

!(function() {
	wiki();
})();

function wiki() {
	//获取域名
	var wlhost = window.location.host;
	console.log(wlhost);
	//百度百科
	var host_baidu = (wlhost == "baike.baidu.com");
	//维基百科
	var host_wiki = (wlhost == "zh.wikipedia.org");
	//搜狗百科
	var host_sogou = (wlhost == "baike.sogou.com");
	//互动百科
	var host_hudong = (wlhost == "www.baike.com");
	//国搜百科
	var host_china = (wlhost == "baike.chinaso.com");

	//搜索引擎网址目录
	var dirall = dir_all();
	//新建选择框
	var new_select = document.createElement('select');
	new_select.setAttribute("id", "id_new_select");
	//循环索引
	var i
	//选择框子节点下面要建立大量【选项】子节点
	for(i in dirall) {
		var v = dirall[i][0];
		new_option(v, i, new_select);
	}
	//新建按钮
	var new_btn = document.createElement('div');
	new_btn.setAttribute("id", "id_new_button");
	new_btn.innerHTML = "跳转搜索";

	//百度百科
	if(host_baidu) {
		//调整祖先节点的宽度
		var wsm = document.getElementsByClassName("wgt-searchbar-main")[0];
		wsm.style.cssText = "width: 100%;";

		var father_baidu = document.getElementById("searchForm");
		var bro_baidu = document.getElementsByClassName("help")[0];
		father_baidu.insertBefore(new_select, bro_baidu);
		father_baidu.insertBefore(new_btn, bro_baidu);

		new_select.style.cssText = "outline:none;font-size:17px;height:40px;margin:0 0 0 4px;";
		new_btn.style.cssText = "display:inline-block;outline:none;font-size:17px;width:104px;height:40px;background-color:#FF5200;line-height:40px;text-align:center;color:white;letter-spacing:1px;cursor:pointer;vertical-align:middle;";
	} else if(host_wiki) {
		var p_search = document.getElementById("p-search");
		p_search.style.marginRight = "8px";

		var father_wiki = document.getElementById("right-navigation");
		father_wiki.appendChild(new_select);
		father_wiki.appendChild(new_btn);
		new_select.style.cssText = "outline:none;font-size:14px;height:25px;margin:9px 0 0 0;";
		new_btn.style.cssText = "display:inline-block;outline:none;font-size:14px;width:84px;height:25px;background-color:#FF5200;line-height:25px;text-align:center;color:white;letter-spacing:1px;cursor:pointer;margin:0 10px 0 0;";
	} else if(host_sogou) {
		var searchbox = document.getElementsByClassName("searchbox")[0];
		searchbox.style.width = "1138px";
		var btn_clear = document.getElementsByClassName("btn_clear")[0];
		btn_clear.style.right = "438px";

		var father_sogou = document.getElementById("Form");
		var bro_sogou = document.getElementById("divc");
		father_sogou.insertBefore(new_select, bro_sogou);
		father_sogou.insertBefore(new_btn, bro_sogou);
		new_select.style.cssText = "outline:none;font-size:16px;height:30px;margin:0 0 0 4px;";
		new_btn.style.cssText = "display:inline-block;outline:none;font-size:16px;width:104px;height:32px;background-color:#FF5200;line-height:32px;text-align:center;color:white;letter-spacing:1px;cursor:pointer;";
	} else if(host_hudong) {
		var father_hudong = document.getElementsByClassName("search-panel")[0];
		father_hudong.appendChild(new_select);
		father_hudong.appendChild(new_btn);
		new_select.style.cssText = "outline:none;font-size:16px;height:36px;margin:0 0 0 4px;";
		new_btn.style.cssText = "display:inline-block;outline:none;font-size:16px;width:104px;height:34px;background-color:#FF5200;line-height:34px;text-align:center;color:white;letter-spacing:1px;cursor:pointer;";
	}else if(host_china){
		var bkgg = document.getElementsByClassName("bkgg")[0];
		bkgg.style.display = "none";

		var father_china = document.getElementsByClassName("seInputWrapper")[0];
		father_china.appendChild(new_select);
		father_china.appendChild(new_btn);
		new_select.style.cssText = "outline:none;font-size:16px;height:43px;margin:0 0 0 650px;";
		new_btn.style.cssText = "display:inline-block;outline:none;font-size:16px;width:104px;height:43px;background-color:#FF5200;line-height:43px;text-align:center;color:white;letter-spacing:1px;cursor:pointer;margin:-43px 0 0 742px;";
	}

	//按钮点击事件
	new_btn.onclick = function new_btn_click() {
		//获得输入框数据
		var new_input;
		if(host_baidu) {
			new_input = document.getElementById("query");
		} else if(host_wiki) {
			new_input = document.getElementById("searchInput");
		} else if(host_sogou) {
			new_input = document.getElementById("searchText");
		} else if(host_hudong) {
			new_input = document.getElementsByClassName("ac_input")[0];
		} else if(host_china){
			new_input = document.getElementsByClassName("search_input2")[0];
		}
		var new_input_val = new_input.value;
		//计算输入框数据长度
		var new_input_val_len = new_input_val.length;
		//如果输入框有数据
		if(new_input_val_len > 0) {
			//获得选择框里被选中的选项索引
			var option_index = new_select.selectedIndex;
			//根据索引获得获得选择框里被选中的选项id
			var option_select_id = new_select.options[option_index].id;
			//根据id和网址目录获得网址
			var pcsearch = dirall[option_select_id][1];
			//用输入框的数据替换掉网址内的替换符
			var dti = pcsearch.replace("%sv%", new_input_val);
			//网址跳转
			window.open(dti);
		} else {
			alert("请在前面的输入框输入要搜索的内容。[GreasyFork]");
			new_input.focus();
		}
	}
}

//新建option
function new_option(ih, aid, ns) {
	var new_opt = document.createElement('option');
	new_opt.innerHTML = ih;
	new_opt.setAttribute("id", aid);
	ns.appendChild(new_opt);
}

//搜索引擎网址目录,%sv%为替换符
function dir_all() {
	var da = {
		"id_opt_00": {
			0: "维基百科",
			1: "https://zh.wikipedia.org/w/index.php?search=%sv%&fulltext=1",
		},
		"id_opt_01": {
			0: "百度百科",
			1: "https://baike.baidu.com/search?word=%sv%",
		},
		"id_opt_02": {
			0: "百度搜索",
			1: "https://www.baidu.com/s?wd=site:(baike.baidu.com) \"%sv%\"&ct=1",
		},
		"id_opt_03": {
			0: "搜狗百科",
			1: "http://baike.sogou.com/Search.e?sp=S%sv%",
		},
		"id_opt_04": {
			0: "互动百科",
			1: "http://so.baike.com/doc/%sv%",
		},
		"id_opt_05": {
			0: "国搜百科",
			1: "http://baike.chinaso.com/wiki/search?q=%sv%",
		},
		"id_opt_06": {
			0: "知网学问",
			1: "http://xuewen.cnki.net/searchentry.aspx?key=%sv%",
		},
		"id_opt_07": {
			0: "必应网典",
			1: "http://www.bing.com/knows/search?mkt=zh-cn&q=%sv%",
		},
		"id_opt_08": {
			0: "360百科",
			1: "https://baike.so.com/search/?q=%sv%",
		},
	}
	return da;
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址