// ==UserScript==
// @name 网站助手
// @namespace http://tampermonkey.net/
// @version 1.3
// @description 1、简化百度页面,去除广告,美化搜索结果,页面滚动到下方自动加载;2、修改部分网站超链打开窗口为新窗口方式;3、Github搜索列表自动翻译,修改列表展示方式,滚动自动加载,readme划词翻译
// @author Yisin
// @require https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js
// @match *://www.baidu.com/*
// @match *://www.google.com.hk/*
// @match *://bbs.125.la/*
// @match *://github.com/*
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// @downloadURL none
// ==/UserScript==
(function () {
'use strict';
$(window).on('load', function () {
var start = function () {
var host = document.location.host;
// 百度
if(host == 'www.baidu.com'){
new BaiduHelper().listener();
} else if(host == 'github.com'){
// Guthub
new GitHubHelper().listener();
}
// 超链接
new HrefHelp().ready();
};
start();
});
/**
* 百度助手
*/
function BaiduHelper() {
this.pageIndex = 1;
this.first = '';
}
BaiduHelper.prototype = {
listener: function () {
var that = this;
setInterval(function () {
var href = document.location.href;
if (href == 'https://www.baidu.com/') {
that.homeClearAd();
}
var t = $('.result.c-container .t:eq(0)').text();
if (that.first != t) {
that.first = t;
setTimeout(function () {
that.pageIndex = 1;
that.clearAd();
}, 200);
}
}, 200);
},
// 去广告
homeClearAd: function () {
$('#s_wrap').remove();
document.body.style.overflow = 'hidden';
},
clearAd: function () {
var href = document.location.href;
if (href.substring(0, 24) == 'https://www.baidu.com/s?') {
document.body.style.overflow = 'auto';
$('#content_right,#rs,#foot').remove();//#page,
var cleard = function () {
$('#content_left > div').each(function () {
var that = $(this);
if (!that.hasClass('result') || that.find('.m').text() == '广告') {
that.remove();
}
});
}
setInterval(cleard, 200);
cleard();
this.autoLoadSearch();
this.pageFormat();
}
},
// 页面美化
pageFormat: function () {
var cw = document.body.clientWidth;
cw = parseInt(cw / 3) - 22;
var styleText = ".result.c-container{border:1px solid #dedede;margin: 5px;padding: 3px;height: 100px;float: left;overflow-y: auto;width: " + cw + "px;}";
GM_addStyle('#page{display:none;}#container{width:100%;} #content_left{width: calc(100% - 10px);padding-left:0; padding-top:0;padding:5px;} ' + styleText);
},
// 自动加载搜索下一页
autoLoadSearch: function () {
var that = this;
var loadstatus = false;
var max = $('#page a').length - 1;
var startload = function () {
loadstatus = true;
var kw = $('#kw').val();
var num = that.pageIndex * 10;
var url = formatByJson("https://www.baidu.com/s?wd={0}&pn={1}", {
wd: kw, pn: num
});
loadHtml(url, function (res) {
loadstatus = false;
try {
var $html = $(res);
if ($html) {
var items = $html.find('#content_left > div.result');
if (items && items.length) {
$('#content_left').append(items);
that.pageIndex++;
if($('body').height() < $(window).height() && that.pageIndex < max && that.pageIndex < 4){
startload();
}
}
}
} catch (e1) {
}
});
}
startload();
$(window).unbind('scroll').scroll(function (e, i) {
if ($(window).scrollTop() + $(window).height() >= $(document).height() - 10) {
if (!loadstatus) {
startload();
}
}
});
}
};
var githubcss = `
.container-lg {
max-width: 10120px;
}
.paginate-container {
float: left;
width: 100%;
}
.float-left {
width: 210px;
}
.codesearch-results {
width: calc(100% - 210px);
}
.repo-list-item {
width: 530px;
height: 250px;
float: left;
padding: 5px;
overflow-y: auto;
overflow-x: hidden;
}
.repo-list-item > div:nth-child(1) {
width: calc(100% - 130px) !important;
}
.repo-list-item > div:nth-child(1) p {
width: 100% !important;
}
.repo-list-item .d-flex {
width: 130px !important;
display: block !important;
float: left;
}
.repo-list-item .d-flex > div {
float: left !important;
width: 230px !important;
height: 30px !important;
text-align: left !important;
}
.paginate-container {
display: none !important;
}
`;
/**
* GitHub助手
*/
function GitHubHelper() {
this.first = '';
this.pageIndex = 2;
this.itemw = 530;
}
GitHubHelper.prototype = {
searchPage: function () {
var href = document.location.href;
if (href.substring(0, 26) == 'https://github.com/search?') {
var $inpo = $('input.header-search-input');
if ($inpo && !$inpo.val()) {
$inpo.val('search:start');
}
this.searchFanyi();
}
},
searchFanyi: function () {
var that = this;
var $p = $('.repo-list .repo-list-item p.d-inline-block');
if ($p && $p.length) {
var i1 = 0;
var startFY = function (i2) {
if($p[i2].fy){
i1++;
startFY(i1);
return;
}
var text = $p[i2].innerText;
fanyi(text, function (res) {
if (res) {
i1++;
$p[i2].innerHTML = $p[i2].innerHTML + '