您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
我只想把百度首页背景换成Bing的
当前为
// ==UserScript== // @name 百Bing图 // @namespace hoothin // @version 0.1 // @description 我只想把百度首页背景换成Bing的 // @author hoothin // @match http://*/* // @grant GM_xmlhttpRequest // @grant GM_setValue // @grant GM_getValue // @connect cn.bing.com // @include *://www.baidu.com/ // @include *://www.baidu.com/home* // @include *://www.baidu.com/?tn=* // @include *://www.baidu.com/index.php* // ==/UserScript== (function() { 'use strict'; var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; if(GM_getValue("baiBing")){ setBingBg(); } var setObserver = new MutationObserver(function(records){ var definedBtn=document.querySelector(".defined-btn-no"); var check=document.querySelector("#bingCheck"); if(definedBtn && !check){ var label=document.createElement("label"); label.setAttribute("style","float:left;margin-top:25px;margin-left:10px;"); label.innerHTML="<input id='bingCheck' type='checkbox'>Bing图"; label.classList.add("recommend"); definedBtn.after(label); check=document.querySelector("#bingCheck"); document.querySelector(".defined-btn-yes").addEventListener("click", function(){ if(check.checked){ if(!GM_getValue("baiBing"))setBingBg(); }else{ if(GM_getValue("baiBing"))location.reload(); } GM_setValue("baiBing",check.checked); }); check.checked=!!GM_getValue("baiBing"); } }); var option = { 'childList': true }; var head=document.querySelector("#head"); setObserver.observe(head, option); function setBingBg(){ GM_xmlhttpRequest({ method: 'GET', url: "http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&pid=hp&video=1&n=1", onload: function(result) { var jsonData = null; try { jsonData = JSON.parse(result.responseText); var bgUrl="url(\""+jsonData.images[0].url+"\")"; var skinContainer=document.querySelector(".s-skin-container"); if(!skinContainer){ return; } if(skinContainer.style.backgroundImage != bgUrl){ skinContainer.style.backgroundImage = bgUrl; } var observer = new MutationObserver(function(records){ if(skinContainer.style.backgroundImage != bgUrl){ skinContainer.style.backgroundImage = bgUrl; } }); var option = { 'attributes': true }; observer.observe(skinContainer, option); }catch (e) { console.log(e); } } }); } })();