// ==UserScript== // @name 【手机】去除百度跳转及去推广,标识csdn下载 // @namespace http://tampermonkey.net/ // @version 0.3.4 // @description 由于手机搜索东西搜到cdsn下载的网站,特意标识一下防止误进恶心人,自动加载搜索结果的下一页(默认关闭) // @author MT-戒酒的李白染 // @include *://m.baidu.com/* // @include *://www.baidu.com/* // @include *://baijiahao.baidu.com/* // @include *://tieba.baidu.com/* // @include *://wk.baidu.com/* // @include *://jingyan.baidu.com/* // @include *://baike.baidu.com/* // @include *://zhidao.baidu.com/* // @grant GM_addStyle // @grant GM_registerMenuCommand // @grant GM_unregisterMenuCommand // @grant GM_getValue // @grant GM_setValue // @grant GM_deleteValue // @grant GM_listValues // @grant GM_xmlhttpRequest // @require http://cdn.staticfile.org/jquery/2.1.4/jquery.min.js // @run-at document-start // @downloadURL none // ==/UserScript== (function () { 'use strict'; var Flag_Title_css = ` .component-box .praise { padding-right: 20px; background: #ff5722; text-indent: 1em; border-top-left-radius: 50px; border-top-right-radius: 50px; border-bottom-left-radius: 50px; border-bottom-right-radius: 50px; background: -webkit-linear-gradient(left,#ff5722,#f78d6b); background: -o-linear-gradient(right,#ff5722,#f78d6b); background: -moz-linear-gradient(right,#ff5722,#f78d6b); background: linear-gradient(to right,#ff5722,#f78d6b); } .component-box .praise,.component-box .share { /*width: 110px; height: 34px; line-height: 34px;*/ height:auto;line-height:normal;color: #fff; } .component-box a { display: inline-block; font-size: 14px; } .component-box { /*margin: 0 auto; text-align: center; display: inline;*/ display: flex; margin: 0; text-align: left; font-size: 0; position: relative; width: 260px; } ` function repalceLink_Event() { function repalceA_Tag(DOM, new_href) { let aTag = Array.from(DOM.getElementsByTagName("a")); aTag.forEach((item) => { item.href = new_href; }) removeControl(); } function addWebsiteFlag(DOM) { let WebsiteTitle = Array.from(DOM.getElementsByClassName("c-title-text")); if (WebsiteTitle.length) { console.log(WebsiteTitle[0]); let Title_Div = document.createElement("div"); Title_Div.className = 'component-box'; Title_Div.innerHTML = `CSDN下载`; WebsiteTitle[0].append(Title_Div); } } function removeControl() { if ($(".icon-logo").length) { $(".icon-logo")[0].remove(); //底部下一页前面图标删除 } $("#page-relative").remove(); //末尾 ===>> 大家都在搜 广告位 $(".c-recomm-wrap.new-ux-recom-wrapper.c-bg-color-white.animation").remove(); //中间 ===>> 大家都在搜 广告位 $("#pop-up").remove(); //跳转百度app提示 let searchWebSitePages = $(".c-result.result"); searchWebSitePages = Array.from(searchWebSitePages); searchWebSitePages.forEach((items, index) => { let searchArticleOriginal_link = JSON.parse(items.dataset.log)['mu']; if (searchArticleOriginal_link.match(/recommend_list.baidu.com/g)) { console.log('%c%s', 'color:blue;', "删除广告==>大家都在搜"); items.remove(); } if (items.outerText.substr(0, 5) == "大家还在搜") { console.log('%c%s', 'color:blue;', "删除广告==>大家都在搜:显示出来的"); items.remove(); } if (items.childNodes.length > 1) { if (items.outerText.match(/(大家还在搜|百度APP内打开)/)) { console.log('%c%s', 'color:blue;', "删除广告==>大家都在搜:隐藏的(点击后,跳出来的)"); items.childNodes[1].remove(); } } let bottom_logo_text = items.getElementsByClassName("c-color-source"); //底部标识 if (bottom_logo_text != null) { let bottom_remove_flag = false; let bottom_logo = Array.from(bottom_logo_text); bottom_logo.forEach((items_b, index_b) => { let it_text = items_b.outerText; if (it_text.match(/百度(APP内打开|手机助手)/)) { bottom_remove_flag = true; } }) if (bottom_remove_flag) { console.log('%c%s', 'color:blue;', "删除广告==>百度APP内打开"); items.remove(); } } if (items.getElementsByClassName('component-box').length == 0 && searchArticleOriginal_link.match(/http(s|):\/\/(download.csdn.net|www.iteye.com\/resource)/g)) { addWebsiteFlag(items); console.log("插入csdn标题"); } if (items.hasAttribute("srcid") && items.attributes.srcid.value.match(/(sigma|vid_fourfold)/g)) { console.log('%c%s', 'color:blue;', "删除推荐==>xxx 相关 xxx"); items.remove(); } }) let every_result = $("span"); every_result = Array.from(every_result); every_result.forEach((items, index) => { let result_parent = items.parentElement.parentElement; if (items.outerText.match(/百度APP内打开/) || result_parent.getAttribute("data-from") == "etpl") { console.log("存在隐藏"); every_result[index].parentElement.parentElement.remove(); } }) } function replaceLink() { let searchWebSitePages = $(".c-result.result"); searchWebSitePages = Array.from(searchWebSitePages); searchWebSitePages.forEach((items, index) => { let searchArticleOriginal_link = JSON.parse(items.dataset.log)['mu']; if (searchArticleOriginal_link) { let BaiduSearchReplaceAfter = items.getElementsByTagName("article")[0]; if (BaiduSearchReplaceAfter && BaiduSearchReplaceAfter.hasAttribute('rl-link-href')) { let BaiduSearchReplaceAfterValue = BaiduSearchReplaceAfter.getAttributeNode("rl-link-href").value; if (!BaiduSearchReplaceAfterValue.match(/http(s|):\/\/m.baidu.com\/from/g)) { console.info('%c%s', 'color:red;', "当前的 ===>> " + BaiduSearchReplaceAfterValue); return } if (BaiduSearchReplaceAfterValue.match(/http:\/\/www.internal.video.baidu.com/g) || searchArticleOriginal_link.match(/http:\/\/www.internal.video.baidu.com/g)) { let internalVideo = decodeURIComponent(BaiduSearchReplaceAfter.getAttribute("rl-link-data-log")); let internalVideoMatch = internalVideo.match(/\/sf\?pd=video_pag(.*?)={/g); if (internalVideoMatch) { internalVideoMatch = internalVideoMatch[0]; let newinternalVideo = internalVideoMatch.substring(0, internalVideoMatch.length - 2); console.log('%c%s', 'color:orange;', "修复后的视频:" + newinternalVideo); BaiduSearchReplaceAfter.setAttribute("rl-link-href", newinternalVideo); repalceA_Tag(items, newinternalVideo); } } else if (searchArticleOriginal_link.match(/http:\/\/m.baidu.com\/productcard/g)) { console.info('%c%s', 'color:red;', "该链接不予替换"); } else { BaiduSearchReplaceAfter.setAttribute("rl-link-href", searchArticleOriginal_link); repalceA_Tag(items, searchArticleOriginal_link); //console.info('%c%s','color:red;',"修复后的 ===>> "+searchArticleOriginal_link); } } } }) } function main() { removeControl(); replaceLink(); } main(); } var runNum = 0; function replaceLink() { Array.from($("script")).forEach((items, index) => { if (items.text.match(/define\(\"@molecule\/aftclk\/index\",/g)) { console.log('%c%s', 'color:blue;', "删除跳转百度app提示js==>"); items.remove(); } }) $(".search-page").bind("DOMNodeInserted", function () { console.log("当前执行次数:" + runNum); repalceLink_Event(); runNum = runNum + 1; }) } let baidu = { current_url: window.location.href, init() { this.search(); this.baijiahao(); this.tieba(); this.wenku(); this.jingyan(); this.baike(); this.zhidao(); }, css: { search: ` .c-container.na-ec-item, .c-container.ec-container, div[data-type="ad"], .c-result.sfc-log[data-tpl="adv_wenku_fc"], .c-recomm-wrap.new-ux-recom-wrapper.animation, #results-pre, .video-recommend, .c-result.sfc-log[data-tpl="search_recomm"], .sfc-image-content-waterfall-item[wat-item-data-id="no-img"], .se-results-pre, div#copyright + div{ display:none !important; }`, baijiahao: ` .layer-wrap, .openImg, .oPadding, .infinite-scroll-component__outerdiv, .bottomTTSStruct, .undefined, .headDeflectorContainer, .followSuper, #searchwordSdk ~ div:nth-child(n+4), #searchwordSdk, div#commentModule div div span:last-child{ display:none !important; } body.scrollHide{ overflow:auto !important; } .mainContent{ height: auto !important; } `, tieba: ` .tb-backflow-defensive, .fixed-nav-bar-defensive, .post-cut-guide, .ertiao-wrap-defensive, .feed-warp.gray-background, .pb-page-wrapper.app-view.transition-fade nav:first-child, .banner-wrapper-defensive{ display:none !important; } body.tb-modal-open{ overflow:auto !important; }`, wenku: ` .reader-pop-manager-view-containter, .core-download, .card-wrap.card-vip, #app{ display:none !important; } .reader-wrap{ height:auto !important; } #view-app, #view-rr-app{ max-height: 100% !important; } .top-card{ margin-top: 10px !important; } *{ -webkit-touch-callout: inherit !important; -khtml-user-select: auto !important; -moz-user-select: auto !important; -ms-user-select: auto !important; user-select: auto !important; } `, jingyan: ` .article-feed-next, .wgt-rel-exp-feed, .article-feed-btn-fixed, .read-whole-mask.app{ display:none !important; } .exp-content-container.fold.more2line{ max-height: 100% !important; } `, baike: ` .BK-after-content-wrapper, .yitiao-container, #J-tashuo-button-fixed{ display:none !important; }`, zhidao: ` #feed-recommend, .dec, .dec + div, .wgt-topic-hot, #respect-footer, div.question-line + div, .w-detail-display-btn{ display:none !important; } .w-detail-container{ max-height: 100% !important; overflow: auto !important; } `, }, search() { // 百度搜索 if (this.current_url.match(/(m|www).baidu.com/g)) { GM_addStyle(this.css.search); $(function () { main_start(); }) } }, baijiahao() { // 百家号 if (this.current_url.indexOf("baijiahao.baidu.com") != -1) { GM_addStyle(this.css.baijiahao); } }, tieba() { // 贴吧 if (this.current_url.indexOf("tieba.baidu.com") != -1) { GM_addStyle(this.css.tieba); } }, wenku() { // 文库 if (this.current_url.indexOf("wk.baidu.com") != -1) { GM_addStyle(this.css.wenku); } }, jingyan() { // 经验 if (this.current_url.indexOf("jingyan.baidu.com") != -1) { GM_addStyle(this.css.jingyan); } }, baike() { // 百科 if (this.current_url.indexOf("baike.baidu.com") != -1) { GM_addStyle(this.css.baike); } }, zhidao(){ // 知道 if (this.current_url.indexOf("zhidao.baidu.com") != -1) { GM_addStyle(this.css.zhidao); } } } function autoLoadNextPage() { var isloding_flag = false; let isloading_html = ``; $("#page-controller").after($(isloading_html)); $(window).bind("scroll", function () { // scroll at bottom if (Math.ceil($(window).scrollTop() + $(window).height()) >= $(document).height()) { // load data if (isloding_flag == false) { $(".page-isloading").css("display", "flex"); isloding_flag = true; let next_page_url = $(".new-nextpage").attr("href") || $(".new-nextpage-only").attr("href"); console.log("正在请求下一页数据", next_page_url); GM_xmlhttpRequest({ url: next_page_url, timeout: 5000, method: "GET", onload: function (resp) { $(".page-isloading").css("display", "none"); console.log("正在请求的下一页url", next_page_url); let page_html = $(resp.response); let search_result = page_html.find(".c-result.result"); let next_html_next_page_html = page_html.find("#page-controller"); let this_page_results = $("#results"); if (this_page_results != void 0) { $.each(search_result, (i, n) => { this_page_results.append(n); }) $("#page-controller").html(next_html_next_page_html); } else { $(".page-isloading").html("已加载所有的搜索结果"); $(window).unbind(); } isloding_flag = false; }, onerror: function (resp) { console.log(resp); $(".page-isloading").html("加载失败"); } }) } else { console.log("正在加载中请稍后,请勿重复"); } } }) } function main_start() { replaceLink(); if (GM_getValue("menu_autoloading")) { autoLoadNextPage(); } } var GM_menus = [ ["menu_autoloading", "自动展开下一页", false] ] function change_normal_menu() { //修改菜单默认值 console.log(GM_listValues()) for (let i = 0; i < GM_menus.length; i++) { let get_GM_value = GM_getValue(GM_menus[i][0]); if (get_GM_value) { GM_menus[i][2] = true; } else { GM_menus[i][2] = false; } } } function register_GM_Menu() { //注册油猴菜单 for (let i = 0; i < GM_menus.length; i++) { let current_v = GM_menus[i][0]; let current_name = GM_menus[i][1]; let current_status = GM_menus[i][2]; GM_registerMenuCommand(`[${current_status?"√":"×"}]${current_name}`, function () { if (current_status) { GM_deleteValue(current_v); } else { GM_setValue(current_v, "1"); } window.location.reload(); }) } } change_normal_menu(); register_GM_Menu(); GM_addStyle(Flag_Title_css); baidu.init(); })();