Skip to content

Instantly share code, notes, and snippets.

@ebinnion
Forked from snake66/Fix invisible inputs
Created November 16, 2022 16:08
Show Gist options
  • Save ebinnion/4f7b89f08753ec9c0f63beb2ceedbf1b to your computer and use it in GitHub Desktop.
Save ebinnion/4f7b89f08753ec9c0f63beb2ceedbf1b to your computer and use it in GitHub Desktop.
Fix styling for "invisible" input fields in firefox.
// ==UserScript==
// @name Fix input fields
// @namespace snake66
// @description Fix input fields with unreadable text
// @include http://*/*
// @include https://*/*
// @version 2
// @grant none
// ==/UserScript==
function normalizedColor(color)
{
let argstart = color.indexOf("(") + 1;
let arglen = color.lastIndexOf(")") - argstart;
let type = color.substr(0, argstart - 1);
let args = color.substr(argstart, arglen).split(", ").map(function(v) {
return parseInt(v);
});
return {type: type, val: args}
}
function isBright(color)
{
if (!color || color == "")
return false;
let c = normalizedColor(color);
if (c.type != "rgb")
return false;
let avg = (c.val[0] + c.val[1] + c.val[2]) / 3;
return avg > 90;
}
function fixInputFields()
{
let inputs = document.getElementsByTagName("input");
console.log("Fix input fields found " + inputs.length + " inputs...");
for (let i = 0; i < inputs.length; i++) {
let input = inputs[i];
let style = getComputedStyle(input);
let fg = style.getPropertyValue("color");
let bg = style.getPropertyValue("background-color");
let image = style.getPropertyValue("background-image");
if (image) {
input.style.backgroundImage = "none";
}
if (isBright(bg)) {
if (isBright(fg)) {
input.style.color = "darkslategray";
}
} else if (!isBright(fg)) {
input.style.color = "lightgray";
}
}
console.log("Fix input fields end...");
}
fixInputFields();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment