-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.js
More file actions
100 lines (97 loc) · 3.2 KB
/
Copy pathcontroller.js
File metadata and controls
100 lines (97 loc) · 3.2 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* @organization Console Art Cybernetic - https://cacybernetic.github.io
* @author Obrymec - https://obrymec.vercel.app
* @fileoverview The main controller of page.
* @supported DESKTOP, MOBILE
* @created 2025-02-10
* @updated 2026-06-19
* @file controller.js
* @version 0.0.8
*/
// Global attributes.
const linkNotFound = "The wrapper of the destination link doesn't exist.";
const hashTagNotFound = "The character used for spliting doesn't exist.";
const sourceNotFound = (
"The destination link to contact from this wrapper doesn't exist."
);
const jsonFilePaths = [
"african_female_soldier_blender",
"african_female_soldier_godot",
"destroyed_cars_blender_vol_1",
"destroyed_cars_godot_vol_1",
"buildings_blender_vol_1",
"buildings_blender_vol_2",
"buildings_godot_vol_1",
"buildings_godot_vol_2",
"axes_blender_vol_1",
"axes_godot_vol_1",
"assets_banks",
"sketchfab",
"networks"
];
/**
* @description Displays an error message inside an alert dialog.
* @param {string} message The text to display.
* @param {HTMLElement} tag The markup to hide.
* @function alertError
* @type {void}
* @public
* @returns {void}
*/
function alertError (message, tag) {
// Hides loader.
tag.classList.add("hidden");
// Displays message across an alert dialog.
window.alert(message);
// Shows loader.
tag.classList.remove("hidden");
// Goes last loaded website.
window.history.back();
}
// Whether page is fully loaded.
window.addEventListener("DOMContentLoaded", async function () {
// The main container html tag instance.
const mainContainer = this.document.querySelector("div#main-container");
// Gets browser search bar.
const searchInput = this.window.location.href;
// Whether browser link has no hashtag character.
if (!searchInput.includes('#')) alertError(hashTagNotFound, mainContainer);
// Otherwise.
else {
// Tries to get link wrapper.
let wrapper = searchInput.split('#')[1];
// Removes unexpected characters.
wrapper = (typeof wrapper === "string" ? wrapper.trim() : '');
// Whether wrapper is undefined.
if (wrapper.length <= 0) alertError(linkNotFound, mainContainer);
// Otherwise.
else {
// The last position index.
const lastIndex = (jsonFilePaths.length - 1);
// Searches provided link.
for (let i = 0; i < jsonFilePaths.length; i++) {
// The json file path.
const path = `./links/${jsonFilePaths[i]}.json`;
// Loads local data from static json file.
const data = await (await this.window.fetch(path)).json();
// Tries to get wrapper source link.
let source = data[wrapper]?.destination;
// Prints content of loaded data.
console.log({source, data});
// Corrects it whether it's possible.
source = (typeof source === "string" ? source.trim() : '');
// Whether source link is not defined in data.
if (source.length <= 0) {
// Undefined destination link.
if (i >= lastIndex) alertError(sourceNotFound, mainContainer);
// Otherwise.
} else {
// Goes to provided link.
this.window.location.href = source;
// Gets out of loop.
break;
}
}
}
}
});