It is a text file in JSON (JavaScript Object Notation) format that contains certain details about the extension you will be developing. Google uses this file to acquire details about your extension when you will publish it. There are required, recommended and optional fields.
It is basically the meta data of your extension
Many creative applications allow users to pick colors from parts of the app window or even from the entire screen, typically using an eyedropper metaphor.
To use the API, create an EyeDropper object and then call its open() method.
const eyeDropper = new EyeDropper();
The open() method returns a promise that resolves after the user selects a pixel on the screen, and the resolved value provides access to the pixel's color in sRGBHex format (#RRGGBB). The promise is rejected if the user leaves the eyedropper mode by pressing the esc key.
try {
const result = await eyeDropper.open();
// The user selected a pixel, here is its color:
const colorHexValue = result.sRGBHex;
} catch (err) {
// The user escaped the eyedropper mode.
}
- Resources :
The Navigator interface represents the state and the identity of the user agent. It allows scripts to query it and to register themselves to carry on some activities.
A Navigator object can be retrieved using the read-only window.navigator property.
-
Resources : MDN Reference
Source : Stackoverflow
Simple One ✅
function invertColor(hex) {
if (hex.indexOf('#') === 0) {
hex = hex.slice(1);
}
// convert 3-digit hex to 6-digits.
if (hex.length === 3) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
}
if (hex.length !== 6) {
throw new Error('Invalid HEX color.');
}
// invert color components
var r = (255 - parseInt(hex.slice(0, 2), 16)).toString(16),
g = (255 - parseInt(hex.slice(2, 4), 16)).toString(16),
b = (255 - parseInt(hex.slice(4, 6), 16)).toString(16);
// pad each with zeros and return
return '#' + padZero(r) + padZero(g) + padZero(b);
}
function padZero(str, len) {
len = len || 2;
var zeros = new Array(len).join('0');
return (zeros + str).slice(-len);
}
This has a bw
option that will decide whether to invert to black or white;
so you'll get more contrast which is generally better for the human eye.
function invertColor(hex, bw) {
if (hex.indexOf('#') === 0) {
hex = hex.slice(1);
}
// convert 3-digit hex to 6-digits.
if (hex.length === 3) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
}
if (hex.length !== 6) {
throw new Error('Invalid HEX color.');
}
var r = parseInt(hex.slice(0, 2), 16),
g = parseInt(hex.slice(2, 4), 16),
b = parseInt(hex.slice(4, 6), 16);
if (bw) {
// https://stackoverflow.com/a/3943023/112731
return (r * 0.299 + g * 0.587 + b * 0.114) > 186
? '#000000'
: '#FFFFFF';
}
// invert color components
r = (255 - r).toString(16);
g = (255 - g).toString(16);
b = (255 - b).toString(16);
// pad each with zeros and return
return "#" + padZero(r) + padZero(g) + padZero(b);
}
(255 - parseInt(hex.slice(0, 2), 16)).toString(16) | --->
-
hex.slice(0, 2)
extracts the first two characters from the stringhex
, which is assumed to be a hexadecimal color code. For example, ifhex
is#FFA500
, then this operation would returnFF
. -
parseInt(hex.slice(0, 2), 16)
converts the extracted substring to an integer using base 16 (i.e., hexadecimal) representation. In the example above, this would return the integer value255
. -
255 - parseInt(hex.slice(0, 2), 16)
subtracts the integer value from255
, effectively computing the complement of the red component of the color. -
.toString(16)
converts the resulting integer value back to a string representation in hexadecimal format. In the example above, this would return0
, since255 - 255
equals0
.
Therefore, the code effectively computes the complement of the red component of a given hexadecimal color code. Note that this assumes that the color code is in the format "#RRGGBB"
, where RR
, GG
, and BB
represent the red, green, and blue components, respectively. If the code is used with a different format, it may produce unexpected results.
The function works as follows:
-
len = len || 2;
sets the value oflen
to 2 if it is not specified or is falsy (e.g., undefined, null, 0). -
var zeros = new Array(len).join('0');
creates a new array of lengthlen
filled with the string "0", and then joins the elements of the array with an empty separator to form a string oflen
zeros. For example, if1en
is 5, thenzeros
would be"00000"
. -
(zeros + str).slice(-len)
concatenateszeros
andstr
, and then extracts the lastlen
characters of the resulting string. Ifstr
is shorter thanlen
, the remaining characters are filled with zeros fromzeros
. Ifstr
is longer thanlen
, the function returns the lastlen
characters ofstr
. For example, ifstr
is"7"
andlen
is 5, then the function would return "00007". If
stris
"123456"and
lenis 3, then the function would return "456"
.
- As I don't have a Chome Developer Account so i can't publish it on Chrome web Store. Here are Some Screenshot of the Extesnsion ScreenShots of the Extension's Woring
Developer : RahulB
Contact : rahulbishtrb1012@gamil.com