-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdpacks_read_script.js
66 lines (55 loc) · 2.13 KB
/
dpacks_read_script.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
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
// -- class checker --
// let file_path_2 = document.getElementById("dpacks_read_script").src;
// let the_arr_2 = file_path_2.split('/');
// the_arr_2.pop();
const user_normal_check = JSON.parse(localStorage.getItem('user'));
if (!user_normal_check) {
dpacks()
}
function dpacks() {
// let tagsList = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'span', 'div', 'b', 'strong', 'i', 'em', 'mark', 'small', 'del', 'ins', 'sub', 'sup'];
let tagsList = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
const jsonData = document.querySelectorAll(tagsList);
for (let i = 0; i < jsonData.length; i++) {
// -- id declaration --
let id = jsonData[i].id;
axios.get(API_URL + '/api/v1/data-packets/check', {
headers: {
siteId: dpacks_key,
page: pageId,
element: id
}
}
).then(function (response) {
if (response.data.exists === 1) {
fetch('https://data.testcod.top/dpacks-3e038.appspot.com/' + dpacks_key + '_' + pageId + '_' + id + '.json')
.then(function (response) {
return response.json();
})
.then(function (data) {
appendData(data);
})
.catch(function (err) {
console.log('error: ' + err);
});
}
}).catch(function (error) {
console.log(error);
});
// -- append data from data files (view fetch) - function --
function appendData(data) {
// -- main container --
let mainContainer = document.getElementById(id);
// -- text --
mainContainer.innerText = data.text;
// -- attributes --
let atrArray = data.attributes;
if (atrArray.length !== {}) {
Object.keys(atrArray).forEach(key => {
mainContainer.removeAttribute(key);
mainContainer.setAttribute(key, atrArray[key]);
});
}
}
}
}