Wis / "StackExchange" sticky header image to SE site's logo

// ==UserScript==
// @name         "StackExchange" sticky header image to SE site's logo
// @namespace    http://tampermonkey.net/
// @version      0.1
// @icon         https://www.google.com/s2/favicons?domain=stackexchange.com
// @description  change the sticky logo to the SE site's logo
// @author       Wis
// @match        https://*.stackexchange.com/**
// @match        https://*.askubuntu.com/**
// @match        https://*.superuser.com/**
// @match        https://*.serverfault.com/**
// @grant        none
// @license      MIT
// ==/UserScript==
let sub;
const logo = document.querySelector("body > header.site-header > div > a > img");
if (logo === null) {
    sub = document.querySelector("body > header.site-header > div > a").cloneNode(true);
} else {
    const img = document.createElement('img');
    img.src = logo.src;
    sub = img;
}
const stickyHeaderImg = document.querySelector("body > header.top-bar.js-top-bar.top-bar__network._fixed > div > div > a.-logo.js-gps-track.js-network-logo.network-logo");
const stackExchangeLogo = stickyHeaderImg.children[0];
const logo_size = logo.getBoundingClientRect();
document.addEventListener('scroll', function() {
    if (window.scrollY > logo_size.height) {
        stickyHeaderImg.removeChild(stackExchangeLogo);
        stickyHeaderImg.prepend(sub);
    } else {
        stickyHeaderImg.removeChild(sub);
        stickyHeaderImg.prepend(stackExchangeLogo);
    }
});