-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload.js
More file actions
80 lines (65 loc) · 2.6 KB
/
Copy pathload.js
File metadata and controls
80 lines (65 loc) · 2.6 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// По готовности страницы запускаем функцию для подгрузки библиотек:
document.addEventListener('DOMContentLoaded', function() {
loader(1);
});
// Функция для ступенчатой загрузки необходимых для работы бота библиотек:
function loader(n) {
setTimeout(function() {
if (n === 1) {
console.log('Начинаем загрузку кода библиотеки jQuery');
var script_path = chrome.extension.getURL('jquery.js') + '?time=' + new Date().getTime();
var xhr = new XMLHttpRequest(); xhr.open('GET', script_path);
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
console.log('Библиотека jQuery успешно загружена');
window.eval(xhr.responseText);
loader(2);
}
else {
console.log('Не удалось загрузить библиотеку jQuery, повтореям попытку');
loader(1);
}
}
}
xhr.send();
}
if (n === 2) {
console.log('Начинаем загрузку кода библиотеки localForage');
var script_path = chrome.extension.getURL('localforage.js') + '?time=' + new Date().getTime();
var xhr = new XMLHttpRequest(); xhr.open('GET', script_path);
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
console.log('Библиотека localForage успешно загружена');
window.eval(xhr.responseText);
loader(3);
}
else {
console.log('Не удалось загрузить библиотку localForage, повторяем попытку');
loader(2);
}
}
}
xhr.send();
}
if (n === 3) {
console.log('Начинаем загрузку кода нашего бота');
var script_path = chrome.extension.getURL('bot.js') + '?time=' + new Date().getTime();
var xhr = new XMLHttpRequest(); xhr.open('GET', script_path);
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
console.log('Код от бота успешно загружен');
window.eval(xhr.responseText);
}
else {
console.log('Не удалось загрузить кот от бота, повторяем попытку');
loader(3);
}
}
}
xhr.send();
}
}, 200);
}