Greasy Fork

Greasy Fork is available in English.

Google调用bing壁纸

google搜索时随机使用bing壁纸,参考:http://greasyfork.icu/zh-CN/scripts/25202-%E7%99%BEbing%E5%9B%BE

当前为 2017-05-31 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Google调用bing壁纸
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  google搜索时随机使用bing壁纸,参考:http://greasyfork.icu/zh-CN/scripts/25202-%E7%99%BEbing%E5%9B%BE
// @author       darkz
// @grant        GM_xmlhttpRequest
// @grant        GM_log
// @grant        unsafeWindow
// @connect      global.bing.com
// @connect      www.bing.com
// @include      *://www.google.com/
// @include      *://www.google.com.hk/
// @exclude      /^https?://www\.google\.com(\.[a-z]+)/.*search?q=.+/
// @exclude      /^https?://www\.google\.com(\.[a-z]+)/.*&q=.+/
// @exclude      /^https?://www\.google\.com\.hk/.*&q=.+/

// ==/UserScript==

(function() {
    'use strict';
    //GM_log('就是测试下输出呀,需要提前在前面增加grant');
    // Your code here...
    var idx=Math.floor(Math.random()*5);
    var url="http://www.bing.com/HPImageArchive.aspx?format=js&idx="+idx+"&n=1&mkt=en-US";
    GM_log('随机壁纸');

    GM_xmlhttpRequest({

        method: "GET",
        url: url,
        onload: function(response) {

            GM_log('bing bg idx is ' +idx);
            var jsonData = null;
            try {
                jsonData = JSON.parse(response.responseText);
                var bgUrl=jsonData.images[0].url;
                if(!/^https?:\/\//.test(bgUrl)){
                    bgUrl="http://global.bing.com"+bgUrl;
                }
                GM_log('bing bg image url is ' +bgUrl);
                var newHTML         = document.createElement ('div');
                newHTML.innerHTML   = '<div id="cpBackgroundDiv" style="position: fixed;top: 0%;left: 0%; width: 100%;height: 100%;z-index: -1; visibility: visible;"><img id="cpBackgroundImg" src="'+bgUrl+'" style="width: 100%;height: 100%;"></div>';
                document.body.appendChild (newHTML);

            }catch (e) {
                console.log(e);
            }

        }
    });

})();