Skip to content

Commit

Permalink
merge sotab into this repo
Browse files Browse the repository at this point in the history
  • Loading branch information
h2y committed May 4, 2017
1 parent 3869065 commit fc14557
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 11 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
如果你不知道浏览器脚本是什么,我的这篇文章会给与你帮助:[<使用UserScript加强你的浏览器>](https://hzy.pw/p/1872),一定会让你受益匪浅。


# /soTab

**搜索引擎一键切换 soTab**

在常用的搜索引擎页面中添加互相切换的按钮,包括图片、视频、知道、学术搜索。

虽然同类脚本这不是第一款,但这是最省资源的一款。之前有幸使用过其他类似的脚本,太重,启用后全网监控,每个网页都要固定注入一大段 JS/CSS,看着都难受,于是索性自己写了重新写了个轻量级的。

**Greasyfork 在线安装: <https://greasyfork.org/zh-CN/scripts/14856>**


## /wallhaven

**Wallhaven 壁纸网站增强**
Expand All @@ -16,7 +27,7 @@

**网站效果预览:<https://alpha.wallhaven.cc/search?purity=110&sorting=random>**

**Greasyfork 在线安装: <https://greasyfork.org/zh-CN/scripts/27384>**
**Greasyfork 在线安装: <https://greasyfork.org/zh-CN/scripts/29444>**


## /mdn_cn
Expand All @@ -27,6 +38,7 @@

**Greasyfork 在线安装: <https://greasyfork.org/zh-CN/scripts/27384>**


## /read_mode

**网页阅读模式**
Expand All @@ -35,6 +47,7 @@

**Greasyfork 在线安装: <https://greasyfork.org/zh-CN/scripts/26709>**


## /taobao_sort

**淘宝销量排序**
Expand All @@ -43,6 +56,7 @@

**Greasyfork 在线安装: <https://greasyfork.org/zh-CN/scripts/14505>**


## /auto_jd

**自动京东配送**
Expand Down Expand Up @@ -91,5 +105,4 @@

- AC-Baidu:绕过百度重定向直接访问网页:<https://greasyfork.org/zh-CN/scripts/14178>
- Google:绕过搜索结果网页链接重定向:<https://greasyfork.org/zh-CN/scripts/14150>
- soTab:搜索引擎一键切换:<https://greasyfork.org/zh-CN/scripts/14856>
- 自动在中英文之间加上个空格:<https://greasyfork.org/zh-CN/scripts/2185>
13 changes: 4 additions & 9 deletions mdn_cn/mdn_cn.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// @grant none
// @run-at document-start

// @version 1.0.1
// @modified 02/21/2017
// @version 1.0.2
// @modified 05/03/2017
// ==/UserScript==


Expand All @@ -26,17 +26,12 @@
const allowLang = 'zh-CN',
nowLang = 'en-US';

/*
https://developer.mozilla.org/zh-CN/Apps/Design/Planning_your_app
then
nowPath = 'Apps/Design/Planning_your_app';
*/

//check conditions
if(document.referrer) {
let splitRet = location.pathname.split(nowLang+'/', 2);
if(splitRet.length!==2)
return 'bad location :(';
return; // unknown location
const nowPath = splitRet[1];

let regRet = document.referrer.match(/mozilla\.org\/(.+?)\/(.*)$/);
Expand All @@ -45,7 +40,7 @@ if(document.referrer) {
lastPath = regRet[2];

if(lastPath==nowPath)
return 'user choose the English version manually.';
return; // user choose the English version manually
}
}

Expand Down
221 changes: 221 additions & 0 deletions soTab/soTab.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
// ==UserScript==
// @name soTab - Search Engine Switcher
// @name:zh-CN 搜索引擎一键切换 soTab
// @name:zh-TW 搜索引擎壹鍵切換 soTab
// @description Add links to each other in search engines. Including multiple search modes.
// @description:zh-CN 在常用的搜索引擎页面中添加互相切换的按钮,包括图片、视频、知道、学术搜索。
// @description:zh-TW 在常用的搜索引擎頁面中添加互相切換的按鈕,包括圖片、視頻、知道、學術搜索。


// @author Moshel
// @namespace http://hzy.pw
// @homepageURL http://hzy.pw/p/1849
// @supportURL https://github.com/h2y/link-fix
// @icon http://q.qlogo.cn/qqapp/100229475/F1260A6CECA521F6BE517A08C4294D8A/100
// @updateURL https://github.com/h2y/link-fix/raw/master/soTab/soTab.user.js
// @license GPL-3.0

// @include *.baidu.com/*
// @exclude *.baidu.com/link?*
// @include *.so.com/*
// @include *.bing.com/*
// @include *.zhihu.com/search?*
// include *.soku.com/*
// @include *.sogou.com/*
// @include /^https?://[a-z]+\.google\.[a-z,\.]+/.+$/
// @grant none
// @run-at document_end

// @date 10/30/2015
// @modified 08/17/2016
// @version 1.3.4.12
// ==/UserScript==


var href0 = "";
! function ajax_fixer() {
var href = location.href;
if (href0 != href) {
var oldDOM = document.getElementById('soTab');
if (oldDOM) {
oldDOM.parentNode.removeChild(oldDOM);
}
soTab_init();
href0 = href;
}
setTimeout(ajax_fixer, 2222);
}();


function soTab_init() {
//console.log("soTab开始加载");

if (top != window) {
console.log("soTab! not top window");
return;
}

//判断搜索引擎,将仅使用hostname适配
var site = ["baidu", "bing", "so.com", "", "zhihu", "google", "", "soku", "sogou"],
siteName = ["百度", "必应", "好搜", "ALLSO", "知乎", "谷歌", "清澄漫语", "搜库", "搜狗"],
siteID = -1;
for (var i = 0; i < site.length; i++) {
if (site[i] && location.hostname.indexOf(site[i]) >= 0) {
siteID = i;
break;
}
}
if (siteID == -1) {
console.log("soTab can't match site.");
return;
}

//判断搜索类型,使用href适配
var kind = [];
switch (siteID) {
case 0:
kind = ["www.baidu", "image.baidu", "zhidao.baidu.com/search", "v.baidu", "xueshu.baidu.com/s"];
break;
case 1: //bing
kind = [".com/search", ".com/images", ".com/knows/search", ".com/videos", "/academic/search"];
break;
case 2:
kind = ["www.so", "image.so", "wenda.so.com/search", "video.so"];
break;
case 4: //zhihu
kind = ["", "", ".com/search"];
break;
case 5: //google
kind = ["", "tbm=isch", "", "tbm=vid", "scholar.google"];
break;
case 7:
//kind[3] = "soku";
break;
case 8: //sogou
kind = [ ["/web?", "/sogou?", "weixin.sogou", "english.sogou"],
"pic.sogou",
["interation=196636", "mingyi.sogou", "wenwen.sogou", ".com/zhihu"],
"v.sogou",
".com/xueshu"
];
break;
}
//0:normal 1:pic 2:zhidao 3:video 4:xueshu
var kindID = -1;
for (i = 0; i < kind.length; i++) {
if (!kind[i])
continue;
else if (Array.isArray(kind[i])) { //数组形式
for (var j=0; j<kind[i].length; j++ )
if(location.href.indexOf(kind[i][j]) >= 0) {
kindID = i;
break;
}
if(kindID!=-1)
break;
}
else if (location.href.indexOf(kind[i]) >= 0) {
kindID = i;
break;
}
}
//谷歌特殊处理
if (siteID == 5 && kindID == -1) {
if (location.href.indexOf('q=') >= 0)
kindID = 0;
}
if (kindID == -1) {
console.log("soTab! no kind found");
return;
}

//console.log("soTab loaded: " + siteID + "." + kindID);

//初始化搜索路径
//"百度", "必应", "好搜", "ALLSO", "知乎", "谷歌", "清澄漫语", "搜库", "搜狗"
var link = []; //link[siteID]
if (kindID == 0) { //normal
link = ["https://www.baidu.com/s?wd=",
"https://cn.bing.com/search?q=",
"https://www.so.com/s?q=",
"http://h2y.github.io/allso/#",
"",
"https://www.google.com/search?q=",
"", "",
"https://www.sogou.com/web?query="
];
} else if (kindID == 1) { //pic
link = ["https://image.baidu.com/search/index?tn=baiduimage&word=",
"https://cn.bing.com/images/search?q=",
"https://image.so.com/i?q=",
"", "",
"https://www.google.com/search?tbm=isch&q="
];
} else if (kindID == 2) { //zhidao
link = ["https://zhidao.baidu.com/search?word=",
"https://cn.bing.com/knows/search?q=",
"", "",
"https://www.zhihu.com/search?q=",
"", "", "",
"http://www.sogou.com/sogou?interation=196636&query="
];
} else if (kindID == 3) { //video
link = ["https://v.baidu.com/v?ie=utf-8&word=",
"",
"https://video.so.com/v?q=",
"", "",
"https://www.google.com/search?tbm=vid&q=",
"https://hzy.pw/dm/?s=",
"https://www.soku.com/v?keyword="
];
} else if (kindID == 4) { //xueshu
link = ["https://xueshu.baidu.com/s?wd=",
"https://cn.bing.com/academic/search?q=",
"", "", "",
"https://scholar.google.com/scholar?q="
];
}

//获取搜索词(get通用)
var key;
if (siteID == 0)
key = (location.search.indexOf("wd=") >= 0) ? "wd" : "word";
/*else if (siteID == 7)
key = "keyword";*/
else if (siteID == 8)
key = (location.search.indexOf("query=") >= 0) ? "query" : 'w';
else
key = "q";
var tmp = location.href.split(key + "=", 2);
if (tmp.length <= 1) {
console.log("soTab! no keyword found");
return;
}
var tmp2 = tmp[1];
tmp = tmp2.split("&", 2);
key = tmp[0];

//console.log(key);

//加载css
var dom = document.createElement('style'),
dom_body = document.getElementsByTagName("body")[0];
dom.innerHTML = '.soTab{position:fixed;background-color:#000;opacity:.3;border-radius:40px;color:#fff;padding:15px 20px;bottom:100px;height:40px;left:-320px;width:300px;z-index:9999999;transition:all 400ms}.soTab:hover{left:5px;opacity:1;border-radius:10px;box-shadow:5px -5px 10px #777}.soTab p{margin:0}p.soTab_title{font-weight:bold;margin-bottom:3px}.soTab a{color:#0cf;margin-right:1rem}';
dom_body.appendChild(dom);

//生成切换框
dom = document.createElement('div');
dom.id = "soTab";
var str = "<p class='soTab_title'>soTab 一键切换引擎:</p><p>";
for (i = 0; i < link.length; i++) {
if (i != siteID && link[i]) {
str += "<a href='" + link[i] + key + "' target='_blank'>" + siteName[i] + "</a>";
}
}
dom.innerHTML = str + '</p>';
dom.className = "soTab soTab_site" + siteID + " soTab_kind" + kindID;
dom_body.appendChild(dom);

//console.log("soTab all run!");

}
33 changes: 33 additions & 0 deletions soTab/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.soTab {
position: fixed;
background-color: #000;
opacity: 0.3;
border-radius: 40px;
color: #fff;
padding: 15px 20px;
bottom: 100px;
height: 40px;
left: -320px;
width: 300px;
z-index: 9999999;
transition: all 400ms;
}
.soTab:hover {
left: 5px;
opacity: 1;
border-radius: 10px;
box-shadow: 5px -5px 10px #777;
}

.soTab p {
margin: 0;
}
p.soTab_title {
font-weight: bold;
margin-bottom: 3px;
}

.soTab a {
color: #0cf;
margin-right: 1rem;
}
1 change: 1 addition & 0 deletions soTab/style.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fc14557

Please sign in to comment.