-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
31 lines (28 loc) · 892 Bytes
/
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
const { renderHtml } = require('./src/renderer');
const { generateCss } = require('./src/cssGenerator');
const { colors, registerColors } = require('./src/colors');
const { WORD_HIGHLIGHTER } = require('./src/constants');
const wordHighlighterRender = () => {
const doms = document.getElementsByClassName(WORD_HIGHLIGHTER);
for (let i = 0; i < doms.length; i += 1) {
const dom = doms.item(i);
dom.innerHTML = renderHtml(dom.innerText);
}
};
if (typeof document !== 'undefined') {
const css = generateCss();
const headDom = document.getElementsByTagName('head').item(0);
headDom.innerHTML += css;
window.wordHighlighterRender = wordHighlighterRender;
document.addEventListener('DOMContentLoaded', () => {
wordHighlighterRender();
});
}
module.exports = {
WORD_HIGHLIGHTER,
registerColors,
colors,
renderHtml,
generateCss,
wordHighlighterRender,
};