-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
74 lines (67 loc) · 2.42 KB
/
script.js
File metadata and controls
74 lines (67 loc) · 2.42 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
"use strict";
(() => {
class Alert {
#title;
#text;
#btnLabel;
#btnAction;
/***
* @constructs constructor
* @param {String} title
* @param {String} text
* @param {String} btnLabel
* @param {String} btnAction
* @returns {null} Constructor is not return
*/
constructor(title, text, btnLabel, btnAction) {
this.#title = title
this.#text = text
this.#btnLabel = btnLabel
this.#btnAction = btnAction
}
render() {
document.body.innerHTML += `
<div>
<div class="box-mensagem">
<div class="texto-pagina-centralizado-alt">
<h2 class="titulo-texto-pagina-centralizado">${this.#title}</span></h2>
<br>
<p class="label-texto-pagina-centralizado">${this.#text}</p>
<br>
${this.#btnLabel ? '<button data-action-pagina class="btn-principal" id="acao-pagina" name="acao-pagina">${this.#btnLabel}</button>' : ''}
</div>
</div>
</div>`
if (this.#btnAction && typeof this.#btnAction === 'string') {
if (this.#btnAction.trim().length > 1 && this.#btnAction.search('http') != -1) {
document.querySelector('#acao-pagina').addEventListener('click', () => {
window.location.replace(this.#btnAction)
})
}
} else {
setTimeout(this.#btnAction, 3000)
}
}
}
let resources = new Object();
fetch('./data.json').then((res) => res.json())
.then((ret) => {
resources = ret;
const params = new URL(window.location).searchParams
if (params.has('resource') && params.get('resource').toLowerCase() in resources) {
window.location.href = resources[params.get('resource').toLowerCase()]
} else if (params.has('resource') && !(params.get('resource').toLowerCase() in resources)) {
new Alert('There is no action for the reported resource!', 'Redirecting to github.io/gabriersdev...', null, () => {
window.location.href = 'https://www.github.com/gabriersdev'
}).render()
} else {
new Alert('Valid parameter not provided!', 'Redirecting to github.io/gabriersdev...', null, () => {
window.location.href = 'https://www.github.com/gabriersdev'
}).render()
}
})
.catch((err) => {
alert('An error occurred while trying to fetch the data.json file!')
console.error(err)
})
})();