-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
99 lines (93 loc) · 3.79 KB
/
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
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
function focusTab(uuid) {
tab = document.getElementById(uuid)
console.log('ok')
document.getElementById("searchbar").value = ""
document.getElementById("searchbar").value = document.getElementById(`tabtop${window.lastuuid}`).dataset.src
window.lastuuid = uuid
// remove the hidden class to all the other elements with the protrety before
try {
tab.classList.add('hidden')
for (var i = 0; i < tab.parentElement.children.length; i++) {
if (tab.parentElement.children[i].id == uuid) {} else {
tab.parentElement.children[i].classList.remove('hidden')
}
}
} catch {
console.log('this tab was closed')
}
}
function newt() {
// create button for the tab
var uuid = crypto.randomUUID()
window.lastuuid = uuid
const tabtop = document.createElement('button')
tabtop.innerHTML = `<span id='tabtopt${uuid}'>New Tab</span><i class='bx bx-x tabclose' id='uuid${uuid}'></i>`
tabtop.addEventListener('click',(event)=>{focusTab(tabtop.dataset.uuid,event);focusTab(tabtop.dataset.uuid,event);window.it = event})
tabtop.dataset.uuid = uuid
tabtop.dataset.src = 'https://geoloupgome.netlify.app/app.html?uuid=' + uuid
tabtop.id = `tabtop${uuid}`
document.getElementById('tabtop').appendChild(tabtop)
// create iframe of the tab
iframe = document.createElement('iframe');
iframe.setAttribute('is','x-frame-bypass')
iframe.id = uuid;
iframe.src = 'https://geoloupgome.netlify.app/app.html?uuid=' + uuid
document.getElementById("tabs").appendChild(iframe)
document.getElementById("uuid" + uuid).addEventListener('click',()=>{closetab(tabtop.dataset.uuid)})
var contextMenuTwo = CtxMenu(tabtop);
contextMenuTwo.addItem("New tab", newt);
contextMenuTwo.addSeparator();
contextMenuTwo.addItem("Close tab", closectxtab);
// Add a separator
focusTab(uuid)
}
document.getElementById('tabtop').addEventListener("scroll", (event) => {
console.log(event)
});
function closetab(uuid) {
document.getElementById(uuid).remove()
document.getElementById('uuid' + uuid).remove()
document.getElementById(`tabtop${uuid}`).remove()
}
function burger(elm) {
uuid = elm.dataset.uuid
state = elm.dataset.state
if (state == "false") {
elm.dataset.state = "true"
// code here to switch the class
document.getElementById(uuid).classList.remove('Bhide')
document.getElementById(uuid).classList.add('Bshow')
} else {
elm.dataset.state = "false"
// code here to switch the class
document.getElementById(uuid).classList.add('Bhide')
document.getElementById(uuid).classList.remove('Bshow')
}
}
function search() {
var searchbar = document.getElementById("searchbar")
var search = searchbar.value
console.log(search)
if (search.includes("https://") || search.includes("http://")) {
// change the iframe src
document.getElementById(`tabtop${window.lastuuid}`).src = search
document.getElementById(`tabtop${window.lastuuid}`).dataset.src = search
document.getElementById(window.lastuuid).src = search
} else {
console.log('was not url so not supported')
searchbar.value = ""
}
}
/*<button onclick="focusTab(this.dataset.uuid)" data-uuid="21e86172-e87c-41c5-af3d-59fdeeeb7108">New Tab<i class='bx bx-x tabclose'></i></button>*/
document.getElementById('newtab').addEventListener('click',()=>{newt()})
document.getElementById('searchbar').addEventListener('keyup', function (e) {
if (e.key === 'Enter' || e.keyCode === 13) {
// Do something
search()
console.log('enter')
}
});
function refreshTab() {
tab = document.getElementById(window.lastuuid)
tab.src = document.getElementById('tabtop' + window.lastuuid).dataset.src
}