json-object-editor
Version:
JOE the Json Object Editor | Platform Edition
51 lines (43 loc) • 1.5 kB
JavaScript
/**
* Environment-aware favicon changer
* Changes favicon based on localhost vs production environment
*/
(function() {
'use strict';
// Detect if running on localhost (development)
var isLocalhost = location.hostname === 'localhost' ||
location.hostname === '127.0.0.1' ||
location.hostname === '';
if (isLocalhost) {
// For development: use dev favicon file
var devFaviconPath = '/JsonObjectEditor/favicon-dev.png';
var updateFavicon = function(id) {
var link = document.getElementById(id);
if (link) {
link.href = devFaviconPath;
link.type = 'image/png';
}
};
// Update existing favicon links
updateFavicon('favicon-shortcut');
updateFavicon('favicon-icon');
// Also update any favicon links without IDs (fallback)
var allFavicons = document.querySelectorAll('link[rel="icon"], link[rel="shortcut icon"]');
allFavicons.forEach(function(link) {
if (!link.id || link.id.indexOf('favicon') === -1) {
link.href = devFaviconPath;
link.type = 'image/png';
}
});
// If no favicon links exist, create one
if (allFavicons.length === 0) {
var head = document.head || document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.rel = 'icon';
link.type = 'image/png';
link.href = devFaviconPath;
head.appendChild(link);
}
}
// For production, keep default favicon (no changes needed)
})();