Created
March 7, 2016 16:18
-
-
Save mrjacobbloom/283975c0878308de997a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Kernt Events | |
| // @version 1 | |
| // @description Make all the kerning bad | |
| // @author NickyNouse | |
| // @match *://*/* | |
| // @grant none | |
| // ==/UserScript== | |
| 'use strict'; | |
| //from http://stackoverflow.com/a/29301739/1784306 | |
| var matchText = function(node, regex, callback, excludeElements) { | |
| excludeElements || (excludeElements = ['krn', 'script', 'style', 'iframe', 'canvas', 'textarea']); | |
| var child = node.firstChild; | |
| while (child) { | |
| switch (child.nodeType) { | |
| case 1: | |
| if (excludeElements.indexOf(child.tagName.toLowerCase()) > -1) | |
| break; | |
| matchText(child, regex, callback, excludeElements); | |
| break; | |
| case 3: | |
| var bk = 0; | |
| child.data.replace(regex, function(all) { | |
| var args = [].slice.call(arguments), | |
| offset = args[args.length - 2], | |
| newTextNode = child.splitText(offset+bk), tag; | |
| bk -= child.data.length + all.length; | |
| newTextNode.data = newTextNode.data.substr(all.length); | |
| tag = callback.apply(window, [child].concat(args)); | |
| child.parentNode.insertBefore(tag, newTextNode); | |
| child = newTextNode; | |
| }); | |
| break; | |
| } | |
| child = child.nextSibling; | |
| } | |
| return node; | |
| }; | |
| matchText(document.body, /\w\w/g, function(node, match, offset) { | |
| var span = document.createElement("krn"); | |
| span.style.letterSpacing = (0.17*(Math.random() - .5)) + "em"; | |
| span.textContent = match; | |
| return span; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment