// ==UserScript==
// @name GitHub: White favicon
// @version 1.10.0
// @author tobbez
// @match https://support.github.com/*
// @match https://github.blog/*
// @match https://opensource.guide/*
// @match https://www.githubstatus.com/*
// @match https://services.github.com/*
// @match https://desktop.github.com/*
// @match https://partner.github.com/*
// @match https://resources.github.com/*
// @match https://cli.github.com/*
// @match https://thegithubshop.com/*
// @grant none
// @downloadURL https://gist.github.com/tobbez/017bc8b455095f8e4b4f973b09d33ce2/raw/github_white_favicon.user.js
// @updateURL https://gist.github.com/tobbez/017bc8b455095f8e4b4f973b09d33ce2/raw/github_white_favicon.user.js
// @icon https://github.githubassets.com/favicons/favicon-dark.png
// ==/UserScript==
/*
* Replaces the icon for github sites with a white one.
*
* This is for browsers with the dark theme enabled.
*
* To install this script, first get the Violentmonkey or
* Tampermonkey addon, then click the 'Raw' link.
*/
function get_url_filename(url) {
let u = new URL(url);
let p = u.pathname.split('/');
return p[p.length - 1];
}
(function() {
'use strict';
let icon_data = `\
`;
let icon_data_pending = `\
`;
let icon_data_success = `\
`;
let icon_data_failure = `\
`;
let icon_map = new Map([
['favicon.svg', `data:image/svg+xml;base64,${btoa(icon_data)}`],
['favicon-pending.svg', `data:image/svg+xml;base64,${btoa(icon_data_pending)}`],
['favicon-success.svg', `data:image/svg+xml;base64,${btoa(icon_data_success)}`],
['favicon-failure.svg', `data:image/svg+xml;base64,${btoa(icon_data_failure)}`],
['25b1992f021c82f730efb5822ae795665d2e20d7_2_32x32.png', `data:image/svg+xml;base64,${btoa(icon_data)}`], // github.community
['favicon.ico', `data:image/svg+xml;base64,${btoa(icon_data)}`], // opensource.guide
['favicon-3dcd2c977a91b2e3f396b300c5ff0d572295ca632ddb7ba1adcacc1ea68dd5c0.ico', `data:image/svg+xml;base64,${btoa(icon_data)}`], // support.github.com
['cropped-github-favicon-512.png', `data:image/svg+xml;base64,${btoa(icon_data)}`], // github.blog
['favicon-success.png', `data:image/svg+xml;base64,${btoa(icon_data_success)}`], // githubstatus.com
['favicon-pending.png', `data:image/svg+xml;base64,${btoa(icon_data_pending)}`], // githubstatus.com (?)
['favicon-failure.png', `data:image/svg+xml;base64,${btoa(icon_data_failure)}`], // githubstatus.com (?)
['GitHub-Mark-120px-plus_32x32.png', `data:image/svg+xml;base64,${btoa(icon_data)}`], // thegithubshop.com
]);
function update_favicon () {
let icon_links = document.querySelectorAll('link[rel~="icon"]:not([rel~="alternate"])');
for (let icon_link of icon_links) {
let fname = icon_map.get(get_url_filename(icon_link.href));
if (fname !== undefined) {
icon_link.setAttribute('href', fname);
}
}
}
let icon_link = document.querySelector('link[rel~="icon"]:not([rel~="alternate"])');
if (icon_link === null) { // no favicon element on https://services.github.com/
let icon = document.createElement('link');
icon.setAttribute('rel', 'icon');
icon.setAttribute('href', `data:image/svg+xml;base64,${btoa(icon_data)}`);
document.head.appendChild(icon);
}
let mutobs = new MutationObserver(update_favicon);
mutobs.observe(icon_link, {
attributes: true,
});
update_favicon();
})();