Skip to content

Instantly share code, notes, and snippets.

@jangxx
Last active October 6, 2020 16:13
Show Gist options
  • Save jangxx/0fc73153c89194adbc6710eecab1b734 to your computer and use it in GitHub Desktop.
Save jangxx/0fc73153c89194adbc6710eecab1b734 to your computer and use it in GitHub Desktop.
Changes the YouTube logo to a pumpkin
// ==UserScript==
// @name YouTube Pumpkin Logo
// @namespace http://literalchaos.de
// @version 1.0
// @description Changes the YouTube icon to a pumpkin
// @author jangxx
// @match https://www.youtube.com/*
// @grant none
// @downloadURL https://gist.github.com/jangxx/0fc73153c89194adbc6710eecab1b734/raw/youtube_pumpkin_logo.user.js
// @updateURL https://gist.github.com/jangxx/0fc73153c89194adbc6710eecab1b734/raw/youtube_pumpkin_logo.user.js
// ==/UserScript==
const NEW_LOGO = "https://i.imgur.com/NxZY8tI.png";
function addLogo(parentSelector, replaceSelector) {
const replaceElem = document.querySelector(replaceSelector);
if (replaceElem == null) return;
const parentElem = document.querySelector(parentSelector);
if (parentElem == null) return;
const size = replaceElem.getBoundingClientRect();
const parentSize = parentElem.getBoundingClientRect();
const logoImg = document.createElement("img");
logoImg.src = NEW_LOGO;
logoImg.width = size.width;
logoImg.style.position = "absolute";
logoImg.style.bottom = `${parentSize.bottom - size.bottom}px`;
logoImg.style.left = `${-parentSize.left + size.left}px`;
parentElem.appendChild(logoImg);
replaceElem.remove();
}
function waitForNonNull(checkFn) {
return new Promise(resolve => {
let interval = setInterval(() => {
let checkValue = checkFn();
if (checkValue != null) {
clearInterval(interval);
resolve(checkValue);
}
}, 50);
});
}
(function() {
'use strict';
document.querySelectorAll("link[rel='icon']").forEach(e => e.href= NEW_LOGO);
document.querySelectorAll("link[rel='shortcut icon']").forEach(e => e.href= NEW_LOGO);
waitForNonNull(() => document.querySelector("#logo-icon-container > svg > g > g:first-child")).then(() => {
addLogo("#logo-red-icon-container", "#logo-red-icon-container > svg > g > g:first-child");
addLogo("#logo-icon-container", "#logo-icon-container > svg > g > g:first-child");
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment