Greasy Fork is available in English.
删除百度搜索结果的百家号结果
当前为
// ==UserScript==
// @name 移除百家号搜索结果
// @namespace http://tampermonkey.net/
// @home-url http://greasyfork.icu/zh-CN/scripts/375240
// @description 删除百度搜索结果的百家号结果
// @version 1.00
// @include http://www.baidu.com/*
// @include https://www.baidu.com/*
// @require http://code.jquery.com/jquery-1.8.2.js
// @author mzcc
// @note 2019.01.25-1.00 百度搜索页面由于界面变化,观察页面dom的方式已经失效,更换新的去除方式
// @note 2018.12.30-0.15 根据反馈,删除操作做新的变更逻辑
// @note 2018.12.19-0.14 根据百度界面变化,删除操作做新的变更逻辑
// @grant GM_getValue
// @grant GM.getValue
// @grant GM_setValue
// @grant GM.setValue
// @grant GM_addStyle
// @grant GM.xmlHttpRequest
// @run-at document-end
// ==/UserScript==
(function () {
'use strict';
if (typeof (GM) == "undefined") {
// 这个是ViolentMonkey的支持选项
GM = {};
GM.setValue = GM_setValue;
GM.getValue = GM_getValue;
}
let DefaultConfig = {
removeType: 0,
};
let config = {};
Promise.all([GM.getValue('config')]).then(function (data) {
if (data[0] != null) {
config = data[0];
} else {
config = DefaultConfig;
}
switch (config.removeType) {
case 0:
removeType0();
console.log('option 0')
break;
case 1:
removeType1();
console.log('option 1')
break;
}
}).catch(function (e) {
console.log(e);
});
// 第一种移除方式
function removeType0() {
let $aTags = $('#content_left a[href^="http://www.baidu.com/link?url="]');
let $top = $('.c-offset');
$aTags.each(function (i, v) {
let url = $(this).attr('href');
(function (url, node) {
// 补足url,否则报错
url = url.indexOf("eqid") < 0 ? url + "&wd=&eqid=" : url;
GM.xmlHttpRequest({
method: "GET",
url: url,
timeout: 5000,
headers: {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Host": "www.baidu.com",
"Accept-Encoding": "gzip, deflate, br",
"Connection": "keep-alive"
},
onload: function (response) {
let reg = /URL=['|"]([^'|"]+)/;
if (reg.test(response.responseText)) {
let realUrl = response.responseText.match(reg)[1];
if (realUrl.indexOf('baijia') > -1) {
$(node).parents('.c-container').remove();
// 第一项是否还有子元素
if (!$top.children().length) {
$top.parent().remove();
}
} else {
// 还原真实地址
$(node).attr('href', realUrl);
}
}
}
});
})(url, this);
});
// 移除百度视频
let $video = $('.op-short-video-pc');
if ($video.length) {
$video.parent().remove();
}
}
function removeType1() {
// 暂未写
}
function ShowSetting() {
if (document.body != null && document.querySelector("#mzcc-config") == null) {
var Container = document.createElement('div');
Container.id = "mzcc-config";
Container.innerHTML =
" <h4 title='移除百家号搜索设置'>移除百家号搜索设置" + GM_info.script.version + "</h4>\n" +
" <ul>\n" +
" <li><label title='移除页面元素方式'><input name='mzcc_config_remove_type' type='radio' value='0' " + (config.removeType ? 'checked' : '') + ">移除页面元素方式</label>\n" +
" </li>\n" +
" <li><label title='改变搜索方式' ><input name='mzcc_config_remove_type' type='radio' value='1' " + (config.removeType ? 'checked' : '') + ">改变搜索方式</label></li>\n" +
" </ul>\n" +
" <span id='mzcc-config-cancel' title='取消'>取消</span>\n" +
" <span id='mzcc-config-save' title='保存设置'>保存</span>\n";
try {
document.body.appendChild(Container);
} catch (e) {
console.log(e);
}
try {
$("#mzcc-config-save").on("click", function () {
// 点击之后的保存功能
config.removeType = $("[name=mzcc_config_remove_type]:checked").val();
GM.setValue("config", config);
console.log(config);
setTimeout(function () {
window.location.reload();
}, 400);
}, false);
} catch (e) {}
}
}
})();