代码
// ==UserScript==
// @name 百度搜索。链接其他搜索。跳转功能。
// @namespace http://tampermonkey.net/
// @version 0.1(2020-6-24 17:37:27)
// @description try to take over the world!
// @author gwd
// @match https://www.baidu.com/s?*
// @require http://cdn.bootcss.com/jquery/1.12.4/jquery.min.js
// @grant none
// ==/UserScript==
(function () {
'use strict';
// Your code here...
// add(2020-7-13 18:15:25)
$(function () {
// $('div#content_left>div.result.c-container').css('background-color','yellow');
// .css('border', '5px solid rgb(201 219 241)')
var statement = `
<style>
#open_buttons button{
width: fit-content;
}
#search_buttons button{
background-color: white;
color: white;
width:100px;
height:50px;
/*width: fit-content;*/
}
#search_buttons {
display: flex;
flex-direction: column;
flex-wrap: wrap; /* 允许项目换行 */
justify-content: flex-end;
/*gap: 0px;*/
max-height: 70vh; /* 设置最大高度为视口高度的50% */
/*overflow-y: auto;*/ /* 超出部分滚动显示 */
}
</style>
<script>
function opensiblings(obj) {
$(obj).siblings().each(function (index, element) {
element.click();
});
}
function home() {
window.open('http://localhost:8080/');
}
function search(obj) {
window.open($(obj).attr('value') + $('#kw').val());
}
function click_num(len_) {
let len = $('#len_num').val();
if (len_ != null)
len = len_;
for (let i = 0; i < len; i++) {
$('div#content_left>div.c-container h3.t>a')[i].click();
}
};
</script>
<div id='inmybox' style='position:fixed;top:80px;right:10px;display: flex;flex-direction: column;align-items: flex-end;font-size: initial;'>
<button style='background-color:initial;color: red;' οnclick='home()'>Tomcat首页</button>
<div id='open_buttons' style='display: flex;flex-direction: column;align-items: flex-end;'>
<p>
输入N:<input id='len_num' value='0' style='width:50px;font-size: 20px;' />
<button οnclick='click_num()' style='background-color: black;color: white;'>打开前N项</button>
</p>
<button style='background-color: black;color: white;' οnclick='click_num(3)'>打开前3项</button>
<button style='background-color: black;color: white;' οnclick='click_num(5)'>打开前5项</button>
<button style='background-color: black;color: white;' οnclick='click_num(10)'>打开前10项</button>
</div>
结果不满意?试试:
<div id='search_buttons'>
<button value='https://weixin.sogou.com/weixin?type=2&query=' οnclick='search(this)'>微信搜索</button>
<button value='https://www.google.com/search?q=' οnclick='search(this)'>谷歌搜索</button>
<button value='https://cn.bing.com/search?q=' οnclick='search(this)'>必应搜索</button>
<button value='https://www.sogou.com/web?query=' οnclick='search(this)'>搜狗搜索</button>
<button value='https://www.douyu.com/search/?kw=' οnclick='search(this)'>斗鱼搜索</button>
<button value='https://search.bilibili.com/all?keyword=' οnclick='search(this)'>bilibili搜索</button>
<button value='https://www.zhihu.com/search?q=' οnclick='search(this)'>知乎搜索</button>
<button value='https://s.weibo.com/weibo?q=' οnclick='search(this)'>微博搜索</button>
<button value='https://www.douyin.com/search/' οnclick='search(this)'>抖音搜索</button>
<button οnclick='opensiblings(this)' style='background-color:yellow;color: red;width: fit-content;'>全部打开</button>
</div>
</br>
</div>
`;
$("div#u").append(statement);
$("input#len_num").val($('div#content_left>div.c-container').css('margin-bottom','50px').length);
setTimeout(function () {
document.body.scrollTop = document.documentElement.scrollTop = 0;
}, 1000);
$("#kw").on("keydown", function (event) {
if (event.keyCode == 13) {
window.location.href = "https://www.baidu.com/s?wd=" + $(this).val();
return;
}
});
// 重新定义点击事件。事件(2020-7-13 19:11:22)
$("div.page-inner>a").click(function () {
window.location.href = "https://www.baidu.com" + $(this).attr("href");
});
});
})();
有改进、优化的地方可以提出建议。
有自己好用的网站脚本代码可以分享。