-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (37 loc) · 1.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*jshint esversion: 6 */
let rootsize = 16;
window.onload = () => {
chrome.storage.sync.get(["rootsize"], function(result) {
rootsize = result.rootsize;
});
document.onpointermove = e => {
findAndReplace();
};
document.body.addEventListener("click", findAndReplace, true);
};
//a function that loops through every single item
function findAndReplace() {
setTimeout(() => {
[
...document.querySelectorAll(
".layerWidth,.layerHeight,.token.number, .propertyValue.ellipsis, .value"
)
].forEach(element => {
element.childNodes.forEach(child => {
if (child.nodeType === 3) {
requestIdleCallback(() => {
//The text
let px = child.nodeValue.match(/^\d*\.?\d*px/g);
if (px && px.length === 1) {
let value = child.nodeValue.replace(
new RegExp(`^\\d*\\.?\\d*px`, "g"),
(parseInt(px.slice(-2)) / (rootsize || 16)).toFixed(2) + "rem"
);
child.nodeValue = value;
}
});
}
});
});
});
}