油猴脚本首战---给百度加一个皮肤

4 篇文章 0 订阅

油猴脚本首战—给百度加一个皮肤

先上代码:

// ==UserScript==
// @name         给百度加个皮肤
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  去除chrome浏览器百度的每日新闻,设置背景和颜色主题
// @author       Michael
// @match       https://www.baidu.com/
// @match       https://www.baidu.com/*
// @run-at      document-start
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    // Your code here..
     var test = window.location.href;

      if(test!="https://www.baidu.com/")//如果不是主页的话,不执行
      {
         var x = document.getElementsByTagName("body");
          x[0].style.backgroundColor = "#DCDCDC";
          x[0].style.backgroundImage = "url(https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1046555063,1533124755&fm=26&gp=0.jpg)";
          x[0].style.backgroundSize= "1400px 900px" ;
          x[0].style.backgroundRepeat = "no-repeat";
          x[0].style.backgroundAttachment= "fixed";
          x[0].style.opacity = "1.4";
      }else{
        var y = document.getElementById("s_main");
     y.remove();
     var z = document.getElementById("s_top_wrap")
     z.remove();
     var e = document.getElementById("bottom_layer")
    e.remove();

    var w = document.getElementById("hotsearch-content-wrapper")
    w.remove();
    var s = document.getElementById("su")
    s.style.backgroundColor = "#fffff";
  
    var xx = document.getElementsByTagName("body");
       xx[0].style.backgroundImage = "url(https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1046555063,1533124755&fm=26&gp=0.jpg)";
        xx[0].style.backgroundSize= "1300px 900px" ;
        xx[0].style.backgroundRepeat = "no-repeat";
       xx[0].style.backgroundAttachment= "fixed";
      }

})();

写的并不是很好,作为自己的第一个作品,先做一下记录。

记录一下使用到的几个方法和积累的一些经验
1.var test = window.location.href;
获取当前的url的方法

2.浏览器网页有很多ajax的方法,会导致页面不能够刷新
其实使用 if(test!=“https://www.baidu.com/”)
的方法是不妥的,会造成背景的失灵。

3.背景图片的设置方法
这里有详细的解释:css设置背景图片格式

`
由于对于Ajax的理解并不是非常的好,这里没有使用,也没有非常好的解决应对百度ajax的方法,这里以后也会加强学习。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值