Created
April 28, 2022 14:09
-
-
Save dewcked/c896c3004f483e4fa602054d097ad2a1 to your computer and use it in GitHub Desktop.
Enable dark theme (via firefox console - F12) in addon.mozilla.org aka AMO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Navigate to any AMO webpage and run the script in console | |
// AMO/blog, AMO/etc.... are not supported. | |
function decimalToHex(decimal) { | |
if (decimal < 16) | |
return "0" + decimal.toString(16); | |
else if (decimal > 255) | |
return "00"; | |
else | |
return decimal.toString(16); | |
} | |
var _elements = document.getElementsByTagName("*"); | |
var _colorClassList = [ | |
"SecondaryHero-message-headline", | |
"SecondaryHero-message-description", | |
"SecondaryHero-module-description", | |
"SecondaryHero-module-link", | |
"Card-header-text", | |
"SearchResult-link", | |
"SearchResult", | |
"Home-SubjectShelf-subheading", | |
"Home-SubjectShelf-link", | |
"LandingPage-addonType-name", | |
"LandingPage-heading-content", | |
"SearchContextCard-header", | |
"Paginate-item", | |
"Paginate-page-number", | |
"AddonTitle", | |
"PromotedBadge-label--recommended", | |
"Addon-summary", | |
"RatingManager-legend", | |
"ReportAbuseButton-show-more", | |
"Definition-dt", | |
"Definition-dd", | |
"DropdownMenuItem", | |
"SectionLinks-dropdownlink", | |
"SectionLinks-clientApp-android", | |
"Card-contents", | |
"LanguageTools-header", | |
"Home-heroHeader-title", | |
"Home-heroHeader-subtitle", | |
"SearchResult-summary", | |
"SearchResult--meta-section", | |
"SearchResult-users-text", | |
"ExpandableCard-ToggleLink", | |
"SearchFilters-label", | |
"MetadataCard-content", | |
"MetadataCard-title", | |
"AddonMeta-reviews-content-link", | |
"AddonMeta-reviews-title-link", | |
"AddonMeta-rating-title", | |
] | |
var _bgColorClassList = [ | |
"Page-content", | |
"SecondaryHero-module", | |
"Card-header", | |
"Card-contents", | |
"SearchResult", | |
"LandingPage-header", | |
"Card-footer", | |
"Paginate", | |
"AddonMeta-overallRating", | |
"AddonsCard-list", | |
"DropdownMenu-items", | |
"LanguageTools-header-row", | |
"LanguageTools-table-row", | |
] | |
var _bgColorEXClassList = [ | |
"SecondaryHero-module-icon", | |
"SearchResult-wrapper", | |
[ | |
"Paginate-item", | |
"Button--disabled" | |
] | |
] | |
var _colorNodeList = ["A", "H1", "H2", "H3", "H4", "H5", "H6"]; | |
var _bg_exception = ["Header-title"]; | |
for (var i = 0; i < _elements.length; i++) { | |
for (var k = 0; k < _colorClassList.length; k++) | |
if (_elements[i].classList.contains(_colorClassList[k])) { | |
var _colorStyle = window.getComputedStyle(_elements[i]).getPropertyValue('color'); | |
if (_colorStyle) { | |
var _color = _colorStyle.slice(_colorStyle.indexOf("(") + 1, _colorStyle.indexOf(")")).split(", "); | |
if (parseInt(_color[0]) < 128) { | |
for (var j = 0; j < _color.length; j++) { | |
_color[j] = 255 - _color[j] - 24; | |
} | |
_elements[i].style.color = "#" + decimalToHex(_color[0]) + decimalToHex(_color[1]) + decimalToHex(_color[2]); | |
} | |
} | |
} | |
var _backgroundStyle = window.getComputedStyle(_elements[i]).getPropertyValue('background'); | |
for (var k = 0; k < _colorClassList.length; k++) | |
if (_elements[i].classList.contains(_bgColorClassList[k])) { | |
if (_backgroundStyle) { | |
var _color = _backgroundStyle.slice(_backgroundStyle.indexOf("(") + 1, _backgroundStyle.indexOf(")")).split(", "); | |
if (parseInt(_color[0]) > 128) { | |
for (var j = 0; j < _color.length; j++) { | |
_color[j] = 255 - _color[j] + 24; | |
} | |
_elements[i].style.background = "#" + decimalToHex(_color[0]) + decimalToHex(_color[1]) + decimalToHex(_color[2]); | |
} | |
} | |
} | |
else if (_elements[i].classList.contains(_bgColorEXClassList[0])) { | |
/* if (_elements[i].style.background != "") | |
_elements[i].style.background = ""; | |
else */ | |
_elements[i].style.background = "#ffffff"; | |
} else if (_elements[i].classList.contains(_bgColorEXClassList[1])) { | |
var _color = _backgroundStyle.slice(_backgroundStyle.indexOf("(") + 1, _backgroundStyle.indexOf(")")).split(", "); | |
_elements[i].onmouseover = (function(target, color) { | |
return function() { | |
target.style.background = color; | |
}; | |
})(_elements[i], /* _color[0] == "255" ? "#f9f9fa" : */ "#1e1e1d"); | |
_elements[i].onmouseout = (function(target, color) { | |
return function() { | |
target.style.background = color; | |
}; | |
})(_elements[i], /* _color[0] == "255" ? "#ffffff" : */ "#181818"); | |
} else if (_elements[i].classList.contains(_bgColorEXClassList[2][0])) { | |
var _color = _backgroundStyle.slice(_backgroundStyle.indexOf("(") + 1, _backgroundStyle.indexOf(")")).split(", "); | |
_elements[i].onmouseover = (function(target, color) { | |
return function() { | |
target.style.background = color; | |
}; | |
})(_elements[i], /* _color[0] == "255" ? "#cbc5bf" : */ "#4c8258"); | |
_elements[i].onmouseout = (function(target, color) { | |
return function() { | |
target.style.background = color; | |
}; | |
})(_elements[i], /* _color[0] == "255" ? "#ffffff" : */ ""); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment