Skip to content

Instantly share code, notes, and snippets.

@lucamug
Last active October 1, 2016 16:34
Show Gist options
  • Save lucamug/559928a374b9d103719152abe4d36cf7 to your computer and use it in GitHub Desktop.
Save lucamug/559928a374b9d103719152abe4d36cf7 to your computer and use it in GitHub Desktop.
var 凸 = (function(凸) {
"use strict";
var W = window,
D = document,
minFontSize,
floatMinFontSize,
newColor,
walkDOM = function (node, func) {
if (node.nodeType === 1) {
func(node);
}
node = node.firstChild;
while(node) {
walkDOM(node,func);
node = node.nextSibling;
}
},
markElement = function(node) {
var min = minFontSize || "14px";
var fontSize;
if (! node.getAttribute("sfc-originalStyle")) {
fontSize = W.getComputedStyle(node, null).getPropertyValue("font-size");
if (parseFloat(fontSize) < floatMinFontSize) {
node.setAttribute("sfc-originalStyle", node.getAttribute("style"));
}
}
},
resetElement = function(node) {
if (node.getAttribute("sfc-originalStyle")) {
if (node.getAttribute("sfc-originalStyle") === "null") {
node.removeAttribute("style");
} else {
node.setAttribute("style", node.getAttribute("sfc-originalStyle"));
}
node.removeAttribute("sfc-originalStyle");
}
},
activateElement = function(node) {
if (node.getAttribute("sfc-originalStyle")) {
node.style.fontSize = minFontSize;
node.style.color = newColor;
}
};
凸.SmallFontChecker = {
highlight: function(size, color) {
minFontSize = size || "14px";
floatMinFontSize = parseFloat(minFontSize);
newColor = color || "rgba(200, 0, 255, 1)";
walkDOM(D.body, markElement);
walkDOM(D.body, activateElement);
},
reset: function() {
walkDOM(D.body, resetElement);
},
};
return 凸;
}(凸 || {}));
@lucamug
Copy link
Author

lucamug commented Oct 1, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment