Skip to content

Instantly share code, notes, and snippets.

@eliasdorigoni
Last active September 15, 2022 18:23
Show Gist options
  • Save eliasdorigoni/3bd640ab0241d8b31c9f9c9f97378ac3 to your computer and use it in GitHub Desktop.
Save eliasdorigoni/3bd640ab0241d8b31c9f9c9f97378ac3 to your computer and use it in GitHub Desktop.
Light theme for Kibana users that can't change it. It changes dark CSS files to use light alternatives, forces CSS with !important or changes style attributes if that's not possible.
// ==UserScript==
// @name Elastic Light Theme
// @description Replaces dark themes with light ones
// @author Elias Dorigoni
// @include https://your.kibana.url/*
// @version 1.0
// ==/UserScript==
window.clearTimeout = window.clearTimeout.bind(window);
window.clearInterval = window.clearInterval.bind(window);
window.setTimeout = window.setTimeout.bind(window);
window.setInterval = window.setInterval.bind(window);
function replaceDarkThemes() {
Array.from(document.querySelectorAll('link[type="text/css"][href$="dark.css"]'))
.map(darkTheme => {
let head = document.getElementsByTagName('HEAD')[0]
let link = document.createElement('link')
link.rel = 'stylesheet'
link.type = 'text/css'
link.href = darkTheme.getAttribute('href').replace('dark', 'light')
head.appendChild(link)
darkTheme.remove()
})
}
function extractElementDarkClasses(element) {
return Array.from(element.classList).filter(className => className.includes('--dark'))
}
function replaceDarkClassNames() {
Array.from(document.querySelectorAll('*')).map(el => {
let darkClasses = extractElementDarkClasses(el)
if (darkClasses.length == 0) {
return
}
darkClasses.map(className => {
let newClassName = className.replace('dark', 'light')
document.querySelector('.' + className).classList.replace(className, newClassName)
})
})
}
function addInlineStyleBlock() {
const element = document.createElement('style')
element.textContent = "\
html {color: #555 !important;background-color:white !important}\
.dscFieldList--popular {background-color:#ccc !important}\
.dscFieldListHeader {background-color:#ccc !important}\
.globalFilterItem:not(.globalFilterItem-isDisabled){background-color:rgba(0,119,204,.2) !important}\
.globalFilterItem{color:inherit !important}\
.kbnFilterButtonGroup{background-color:rgba(0,119,204,.2) !important}\
.embPanel__title{color:inherit !important}\
.kbnTypeahead .kbnTypeahead__popover{background-color:#fafafa !important}\
.kbnTypeahead__item.active{background-color:rgba(0,119,204,.2) !important}\
.kbnSuggestionItem__text{color: #555 !important}\
.kbnTypeahead .kbnTypeahead__popover .kbnTypeahead__item.active .kbnSuggestionItem__text{color:#333}\
.css-fmamwg-euiAvatar-s-space{color:white !important}\
"
document.head.append(element);
}
function replaceInlineStyles(selector, styleContent) {
let el = document.querySelector(selector)
if (el != null) {
el.setAttribute('style', styleContent)
}
}
replaceDarkThemes()
replaceDarkClassNames()
addInlineStyleBlock()
window.setInterval(function() {
replaceInlineStyles('.echChartBackground', 'background-color:white')
}, 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment