-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (29 loc) · 1.06 KB
/
app.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
32
33
34
35
'use strict';
const gen = require('./lib/generator.js');
const domInjector = require('./lib/dom-injector');
const pr = require('./lib/css-parser');
window.onload = function() {
let cssProps = {};
const generate = () => {
gen(document, cssProps);
};
document.getElementById('genButton').onclick = generate;
var timer;
document.getElementById('family').onkeyup = (e) => {
clearTimeout(timer);
timer = setTimeout(function() {
const link = 'https://fonts.googleapis.com/css?family=' + e.target.value;
const httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
cssProps = pr(this.responseText);
domInjector(document, e.target.value, link, cssProps);
// console.log(cssProps);
}
}
httpRequest.open('GET', link, true);
httpRequest.send();
}, 600);
};
};
/* global document window */