您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
百度第一页查询csdn橙色,知乎蓝色,豆瓣绿色,百度灰色
当前为
// ==UserScript== // @name AC-baidu的搜索引擎样式再优化,对视觉中心优化-------请额外下载AC-baidu,此功能在AC-baidu基础上进行样式优化. // @namespace http://tampermonkey.net/ // @version 0.2 // @description 百度第一页查询csdn橙色,知乎蓝色,豆瓣绿色,百度灰色 // @author 白水 // @match https://www.baidu.com/s?* // @match https://www.google.*/search?* // @grant none // @require https://code.jquery.com/jquery-3.5.1.js // ==/UserScript== //--------------常用封装-------------------- //写入JQuery 3.5.1 //(function(url) { document.body.appendChild(document.createElement('script')).src = url; })("https://code.jquery.com/jquery-3.5.1.js"); //var $;//不能写入 //--------------定义-------------- var host = window.location.host, //host href = window.location.href; //href /** get 指定JS querySelector的对象,返回一个对象 * @param {*} querySelector JS 选择器 */ function getByQuerySelector(querySelector) { if (!document.querySelector(querySelector)) return false; return document.querySelector(querySelector); } /** get 指定id属性值的对象,返回一个对象 * @param {*} Id */ function getById(Id) { if (!document.getElementsById(Id)) return false; return document.getElementsById(Id); } /**get 指定TagName的对象 ,返回一个数组 * @param {*} TagName 指定tag的对象 */ function getByTagNameArr(TagName) { if (!document.getElementsByTagName(TagName)) return false; return document.getElementsByTagName(TagName); } /** get 指定Name属性的对象,返回一个数组 * @param {*} Name 指定Name的对象 */ function getByNameArr(Name) { if (!document.getElementsByName(Name)) return false; return document.getElementsByName(Name); } /** get 指定ClassName的对象,返回一个数组 * @param {*} ClassName 类名称 */ function getByClassNameArr(ClassName) { if (!document.getElementsByClassName(ClassName)) return false; return document.getElementsByClassName(ClassName); } /** get 筛选指定ClassName,利用getByClassNameArr数组返回一个数组 * @param {*} ClassName 类名称 */ function getClassUniqueArr(ClassName) { var oElements = getByClassNameArr(ClassName), boxArr = new Array(); for (var i = 0, len = oElements.length; i < len; i++) { if (oElements[i].className == ClassName) { boxArr.push(oElements[i]); } } return boxArr; } Element.prototype.remove = function() { // 像那些属性节点,注释节点,文本节点等等根本不可能做父节点,所以可以说parentNode返回的一般都是父元素节点 var Parent = this.parentNode; Parent.removeChild(this); //父元素节点里删除调用者 }; //--------------Function-------------- //--------------常用封装-------------------- (function() { 'use strict'; //运行逻辑 host.includes (t/f) func(){ (remove,ColorChange)} //搜索主页_主程序 function SearchIndex() { //百度搜索 function baidu() { getByQuerySelector("#s_tab").style.background = "rgb(255,255,255,0.5)"; //头部透明 getByQuerySelector("#foot").remove(); //脚注去除 //getByQuerySelector("#rs").remove(); //相关搜索去除???去除之后会出现不翻页 getClassUniqueArr("result-op c-container new-pmd")[0].remove(); //其他人还在搜???好像只会出现一次 } //谷歌搜索 function google() { } //改变颜色 function ColorChange(childrenClassName, parentClassName) { var SearchUrlArr = [ { name: "CSDN|csdn", color: "rgb(255,140,0,0.5)" }, { name: "知乎|zhihu", color: "rgb(65,105,225,0.5)" }, { name: "博客园|cnblogs", color: "rgb(240,0,0,0.5)" }, { name: "豆瓣|douban", color: "rgb(46,139,87,0.5)" }, { name: "百度|baidu", color: "rgb(165,165,165,0.5)" }, { name: "腾讯|qq", color: "rgb(165,165,165,0.5)" }, { name: "搜狐|sohu", color: "rgb(165,165,165,0.5)" }, ]; //定义子元素集合 var c = getByClassNameArr(childrenClassName), p; for (var i = 0, ilen = c.length; i < ilen; i++) { //查找指定父元素 if (c[i].parentNode.parentNode.className === parentClassName) { p = c[i].parentNode.parentNode; //console.log("2"); } else if (c[i].parentNode.parentNode.parentNode.className === parentClassName) { p = c[i].parentNode.parentNode.parentNode; //console.log("3"); } else if (c[i].parentNode.parentNode.parentNode.parentNode.className === parentClassName) { p = c[i].parentNode.parentNode.parentNode.parentNode; //console.log("4"); } else { console.log("找不到父元素"); } //p.style.background = "rgb(255,255,255,0.5)" for (var j = 0, jlen = SearchUrlArr.length; j < jlen; j++) { if (RegExp(SearchUrlArr[j].name).test(c[i].text)) { p.style.background = SearchUrlArr[j].color; //console.log("j--1"); break; } if (j == jlen - 1) { //console.log("j--2"); p.style.background = "rgb(255,255,255,0.5)"; break; } } //console.log("j--3"); /* if (j == jlen) { //恒等于最后一次输出即为 j=jlen; //p.style.background = "rgb(255,255,255,0.5)"; } */ } } if (host.includes("baidu")) { baidu(); ColorChange("c-showurl c-color-gray", "result c-container new-pmd"); } else if (host.includes("google")) { google(); ColorChange(document.getElementsByClassName("g"), document.getElementsByClassName("g")); } else { console.log("不存在"); } } //主程序 延迟 window.onload = function() { setTimeout(SearchIndex(), 0); }; //jQuery预载画面 $(document).ready(SearchIndex()); })();