谷变饼 -- Google 使用 Bing 壁纸

Google 使用 Bing 壁纸。

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         谷变饼 -- Google 使用 Bing 壁纸
// @namespace    http://tampermonkey.net/
// @version      0.6-20240314
// @description  Google 使用 Bing 壁纸。
// @license      AGPL-3.0 License
// @author       plasma
// @grant        GM_xmlhttpRequest
// @grant        unsafeWindow
// @connect      global.bing.com
// @connect      www.bing.com
// @connect      cn.bing.com
// @include      *://www.google.com/
// @exclude      /^https?://www\.google\.com(\.[a-z]+)/.*search?q=.+/
// @exclude      /^https?://www\.google\.com(\.[a-z]+)/.*&q=.+/
// @exclude      /^https?://www\.google\.com\.hk/.*&q=.+/
// @exclude      /^https?://www.google.com/#newwindow=1&q=
// @exclude      /^https?://www.google.com.hk/#newwindow=1&q=

// ==/UserScript==

function removeElement(className) {
  try {
    let elements = document.getElementsByClassName(className);
    if (elements.length > 0) elements[0].remove();
  } catch(e) {
    console.error(`Error removing element with class ${className}:`, e);
  }
}

(function() {

    'use strict';

    //block float element
    removeElement("FPdoLc lJ9FBc");
    removeElement("vcVZ7d");
    removeElement("o3j99 c93Gbe");
    removeElement("LX3sZb");
    removeElement("lJ9FBc");
    removeElement("oBa0Fe aciXEb");
    try{
        document.getElementsByClassName("lnXdpd")[0].style.borderRadius='30px'
    } catch(e){
        console.error(`BorderRadiusError`);
    }
    //block end


    // Google2Bing, codes referenced from here:
    // https://greasyfork.org/zh-CN/scripts/30152-google%E8%B0%83%E7%94%A8bing%E5%A3%81%E7%BA%B8
    // https://greasyfork.org/zh-CN/scripts/25202-%E7%99%BEbing%E5%9B%BE

    var url="https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US"; //or 'mkt=zh-cn'

    GM_xmlhttpRequest({
        method: "GET",
        url: url,
        onload: function(response) {
            var jsonData = null;
            jsonData = JSON.parse(response.responseText);
            var bgUrl=jsonData.images[0].url;
            if(!/^https?:\/\//.test(bgUrl)){
                bgUrl="https://cn.bing.com"+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);
        }
    });

})();