一个替换logo的脚本
目前為
// ==UserScript==
// @name 直播顺畅
// @version 0.1.2
// @description 一个替换logo的脚本
// @author You
// @match https://*.google.com/*
// @match https://www.google.co.jp/
// @icon https://www.google.com/s2/favicons?sz=64&domain=google.co.jp
// @license MIT
// @namespace http://tampermonkey.net/
// ==/UserScript==
(function () {
'use strict';
// Your code here...
var search_page_logo_xpath = '/html/body/div[4]/div[2]/form/div[1]/div[1]/div[1]/a/img';
var main_page_logo_xpath = "/html/body/div[1]/div[2]/div/img";
var word_xpath = "/html/body/div[1]/div[3]/form/div[1]/div[1]/div[4]/center/input[1]";
var main_page_classname = "lnXdpd";
var baidu_logo = "https://www.baidu.com/img/pcdoodle_2a77789e1a67227122be09c5be16fe46.png";
// 检测是主页面还是搜索洁面
var currentUrl = window.location.href;
var pattern = /^https?:\/\/(www\.)?google\.[a-z]{2,3}(?:\.[a-z]{2})?(?:\/|$)/;
if (pattern.test(currentUrl)) {
// 主页
var result = document.getElementsByClassName(main_page_classname);
var logoImg = result.item(0);
var newLogoImg = document.createElement('img');
newLogoImg.src = baidu_logo;
newLogoImg.width = 272;
console.log(logoImg);
console.log(logoImg.parentNode);
logoImg.parentNode.removeChild(logoImg.parentNode.firstChild);
logoImg.parentNode.replaceChild(newLogoImg, logoImg);
} else {
// 搜索页
console.log("该网址不是 Google 的网址");
}
// {
// // 修改搜索页面左上角的小logo
// result = document.evaluate(search_page_logo_xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
// logoImg = result.snapshotItem(0);
// newLogoImg = document.createElement('img');
// newLogoImg.src = baidu_logo;
// newLogoImg.width = 96;
// newLogoImg.height = 30;
// logoImg.parentNode.replaceChild(newLogoImg, logoImg);
})();