diff options
author | Blaise | 2022-10-31 13:07:08 -0500 |
---|---|---|
committer | Blaise | 2022-10-31 13:08:05 -0500 |
commit | 67028c34166e65ee95498c2d14496934bf68b16f (patch) | |
tree | 138c4a887327838e55469c0d700180715717ef3f | |
parent | a2c65f26ebeaf6d123a20e53e4a2c6995e2e55c6 (diff) |
-rw-r--r-- | proselight.js | 55 |
1 files changed, 17 insertions, 38 deletions
diff --git a/proselight.js b/proselight.js index b4df7f4..d92797b 100644 --- a/proselight.js +++ b/proselight.js | |||
@@ -9,41 +9,29 @@ | |||
9 | */ | 9 | */ |
10 | 10 | ||
11 | 11 | ||
12 | (function (root, factory) { | 12 | ( function () { |
13 | if (typeof define === 'function' && define.amd) { | ||
14 | define(['exports'], factory); | ||
15 | } else if (typeof exports !== 'undefined') { | ||
16 | factory(exports); | ||
17 | } else { | ||
18 | factory((root.proselight = {})); | ||
19 | } | ||
20 | }(this, function (exports) { | ||
21 | // for better compression | 13 | // for better compression |
22 | var _window = window, | 14 | var _window = window, |
23 | _document = document, | 15 | _document = document, |
24 | appendChild = 'appendChild', | 16 | appendChild = 'appendChild', |
25 | test = 'test', | 17 | test = 'test', |
26 | 18 | ||
27 | i, | 19 | i, j, |
28 | proselighted, | 20 | proselighted, |
29 | cn, //child nodes | 21 | cna, //child node array |
30 | el; // current proselighted element to run through | 22 | cn, //child node |
31 | 23 | el; // current proselighted element to run through | |
32 | 24 | ||
33 | 25 | // nodes to highlight | |
34 | var reset = function() { | 26 | proselighted = _document.querySelectorAll('p'); |
35 | // nodes to highlight | 27 | |
36 | proselighted = _document.querySelectorAll('p'); | 28 | for (i = 0; el = proselighted[i++];) { |
37 | 29 | cna = Array.from(el.childNodes); | |
38 | for (i = 0; el = proselighted[i++];) { | 30 | for (j = 0; cn = cna[j++];) { |
39 | cn = Array.from(el.childNodes); | 31 | el[appendChild](cn); |
40 | for (j = 0; j < cn.length; j++) { | 32 | if (cn.nodeType == Node.TEXT_NODE) { |
41 | if (cn[j].nodeType != Node.TEXT_NODE) { | 33 | el.removeChild(cn); |
42 | el.appendChild(cn[j]); | 34 | var text = cn.textContent, |
43 | continue; | ||
44 | } | ||
45 | el.removeChild(cn[j]); | ||
46 | var text = cn[j].textContent, | ||
47 | pos = 0, // current position | 35 | pos = 0, // current position |
48 | next1 = text[0], // next character | 36 | next1 = text[0], // next character |
49 | chr = 1, // current character | 37 | chr = 1, // current character |
@@ -110,13 +98,4 @@ | |||
110 | } | 98 | } |
111 | } | 99 | } |
112 | } | 100 | } |
113 | 101 | } )(); | |
114 | exports.reset = reset; | ||
115 | |||
116 | if (_document.readyState == 'complete') { | ||
117 | reset(); | ||
118 | } else { | ||
119 | _window.addEventListener('load', function(){reset()}, 0); | ||
120 | } | ||
121 | })); | ||
122 | |||