aboutsummaryrefslogtreecommitdiff
path: root/lib/readability.js
diff options
context:
space:
mode:
authorBen Burwell <ben.burwell@trifecta.com>2016-09-14 12:30:04 -0400
committerBen Burwell <ben.burwell@trifecta.com>2016-09-14 12:30:04 -0400
commitfd5817a6bb3185314540825e3d665e94ffe188c0 (patch)
tree9b35138a18122ebfcb5cfa41ac0eadd27cb2c002 /lib/readability.js
Initial commit
Diffstat (limited to 'lib/readability.js')
-rw-r--r--lib/readability.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/readability.js b/lib/readability.js
new file mode 100644
index 0000000..06eb4ad
--- /dev/null
+++ b/lib/readability.js
@@ -0,0 +1,38 @@
+var appendText = function(node, text) {
+ var n = document.createElement('var');
+ n.innerText = text;
+ node.appendChild(n);
+};
+
+var readability = {
+ 'assign': function(e) {
+ return e.dataset.name;
+ },
+
+ 'variable': function(e) {
+ return e.dataset.name;
+ },
+
+ 'constant': function(e) {
+ return e.dataset.type + '(' + e.dataset.val + ')';
+ },
+
+ 'compare': function(e) {
+ return e.dataset.op;
+ },
+
+ 'bin-op': function(e) {
+ return e.dataset.op;
+ }
+};
+
+var makeReadable = function(root) {
+ var classes = Object.keys(readability);
+ for (var idx = 0; idx < classes.length; idx++) {
+ var klass = classes[idx];
+ var els = root.getElementsByClassName(klass);
+ els.forEach(function(el) {
+ appendText(el, readability[klass](el));
+ });
+ }
+};