Skip to content

Commit 7990f52

Browse files
The URL bar now works, Tab changes title and icon
1 parent 2416d82 commit 7990f52

File tree

4 files changed

+69
-28
lines changed

4 files changed

+69
-28
lines changed

src/public/js/controls.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,24 @@ function popout() {
4747
win.focus();
4848
} catch (err) {};
4949
}
50-
function pageLoaded() {
50+
function updateURLBar(val) {
5151
let currentTab = getCurrentTab();
5252
let iframe = document.querySelector(`[data-iframe-id="${currentTab}"]`);
53-
iframe.addEventListener('load', function() {
54-
let val = iframe.contentWindow.location.href;
55-
let currentProx = localStorage.getItem('proxy');
56-
//remove the https:// or http:// and the prefix
57-
val = val.replace(window.location.origin, '');
58-
if (currentProx === 'uv') {
59-
val = val.replace(__uv$config.prefix, '');
60-
val = __uv$config.decodeUrl(val);
61-
}
62-
if (currentProx === 'dynamic') {
63-
val = val.replace(__dynam$ic.prefix + 'route/?url=', '');
64-
val = __dynam$ic.decodeUrl(val);
65-
}
66-
updateSearch(val);
67-
});
53+
let currentProx = localStorage.getItem('proxy');
54+
//remove the https:// or http:// and the prefix
55+
val = val.replace(window.location.origin, '');
56+
if (currentProx === 'uv') {
57+
val = val.replace(__uv$config.prefix, '');
58+
val = __uv$config.decodeUrl(val);
59+
}
60+
if (currentProx === 'dynamic') {
61+
val = val.replace(__dynam$ic.prefix + 'route/?url=', '');
62+
val = __dynam$ic.decodeUrl(val);
63+
}
64+
if (val === "a`owt8bnalk") {
65+
val = "";
66+
}
67+
updateSearch(val);
6868
}
6969
function fullscreen() {
7070
//this has two options, fullscreen the page, and fullscreen the tab to the window (add later)
@@ -108,8 +108,18 @@ function searchBar(value) {
108108
const i = document.getElementById('uv-address');
109109
i.value = value;
110110
f.dispatchEvent(new Event('submit'));
111+
resetOmniBox();
111112
}
112113
function updateSearch(value) {
113114
const s = document.getElementById('search-input');
115+
//update the placeholder
114116
s.value = value;
117+
}
118+
function isIframeLoaded() {
119+
let currentTab = getCurrentTab();
120+
let iframe = document.querySelector(`[data-iframe-id="${currentTab}"]`);
121+
updateTabDetail("Loading...", "loading.gif");
122+
iframe.addEventListener('load', function() {
123+
updateTabDetail(iframe.contentWindow.document.title, iframe.contentWindow.document.querySelector('link[rel="favicon"]') ? iframe.contentWindow.document.querySelector('link[rel="favicon"]').href : "favicon.ico", currentTab);
124+
});
115125
}

src/public/js/omnibox.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ function omniBoxSelect(value) {
3535
document.getElementById("uv-address").focus();
3636
document.getElementById("uv-form").dispatchEvent(new Event('submit'));
3737
}
38+
function resetOmniBox() {
39+
document.getElementById("uv-form").style.marginTop = "20px";
40+
document.getElementById("omnibox").setAttribute("class", "dnone");
41+
document.getElementById("omnibox-list").innerHTML = ''
42+
}

src/public/js/tabs.js

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
let el = document.querySelector('.chrome-tabs');
22
let chromeTabs = new ChromeTabs();
33
let tabs = [];
4+
let deletedTabs = [];
45
chromeTabs.init(el);
56
document.getElementById('add-tab').addEventListener('click', function (e) {
67
chromeTabs.addTab({
@@ -20,9 +21,12 @@ el.addEventListener('activeTabChange', function ({ detail }) {
2021
let iframes = document.querySelectorAll('[data-iframe-id]');
2122
iframes.forEach((iframe) => {
2223
iframe.classList.add('dnone');
24+
updateURLBar("");
2325
})
2426
if (iframeID) {
2527
showIframe(tabId);
28+
updateURLBar(iframeID.contentWindow.location.href);
29+
updateTabDetail(iframeID.contentWindow.document.title, iframeID.contentWindow.document.querySelector('link[rel="favicon"]') ? iframeID.contentWindow.document.querySelector('link[rel="favicon"]').href : 'favicon.ico', tabId);
2630
}
2731
});
2832
function showIframe(tabId) {
@@ -58,7 +62,8 @@ function hideIframe(tabId) {
5862
}
5963
}
6064
function tabAdded(detail) {
61-
let tabLength = tabs.length;
65+
let tabLength = tabs.length + deletedTabs.length;
66+
console.log(tabLength);
6267
//add a id to the tab
6368
detail.tabEl.setAttribute('data-tab-id', tabLength);
6469
tabs.push({
@@ -71,25 +76,32 @@ function tabAdded(detail) {
7176
function tabRemoved(detail) {
7277
let tabId = detail.tabEl.getAttribute('data-tab-id');
7378
tabs = tabs.filter((tab) => tab.id != tabId);
79+
let iframe = document.querySelector(`[data-iframe-id="${tabId}"]`);
80+
if (iframe) {
81+
iframe.remove();
82+
}
83+
deletedTabs.push(tabId);
7484
}
7585
function handoffToTABS(url) {
86+
//if there is a current iframe, delete it
87+
let i = chromeTabs.activeTabEl.getAttribute('data-tab-id');
88+
let isCurentTabHaveIframe = document.querySelector(`[data-iframe-id="${i}"]`);
89+
if (isCurentTabHaveIframe) {
90+
isCurentTabHaveIframe.remove();
91+
}
7692
let iframe = document.createElement('iframe');
7793
iframe.setAttribute('src', url);
7894
iframe.setAttribute('id', 'iframe');
7995
let tabId = chromeTabs.activeTabEl.getAttribute('data-tab-id');
8096
iframe.setAttribute('data-iframe-id', tabId);
8197
document.body.appendChild(iframe);
82-
pageLoaded();
83-
}
84-
function changeTabDetail(title, favicon) {
85-
let tabId = chromeTabs.activeTabEl
86-
//get the div chrome-tab-content
87-
let tabContent = tabId.querySelector('.chrome-tab-content');
88-
let tabTitle = tabContent.querySelector('.chrome-tab-title');
89-
let tabFavicon = tabContent.querySelector('.chrome-tab-favicon');
90-
tabTitle.innerHTML = title;
91-
//the tab favicon is set with a background image
92-
tabFavicon.style.backgroundImage = `url(${favicon})`;
98+
isIframeLoaded()
99+
function resetOmniBox() {
100+
document.getElementById("uv-form").style.marginTop = "20px";
101+
document.getElementById("omnibox").setAttribute("class", "dnone");
102+
document.getElementById("omnibox-list").innerHTML = ''
103+
}
104+
resetOmniBox();
93105
}
94106

95107
function restoreTabs() {
@@ -153,6 +165,20 @@ function keybinds() {
153165
// localStorage.setItem('iframes', JSON.stringify(iframeJSON));
154166
// }
155167
//});
168+
function updateTabDetail(title, favicon, tabID) {
169+
let previousTabID = tabID || chromeTabs.activeTabEl.getAttribute('data-tab-id');
170+
const tabTitle = document.querySelector(`.chrome-tab[data-tab-id="${previousTabID}"] .chrome-tab-title`);
171+
const tabFavicon = document.querySelector(`.chrome-tab[data-tab-id="${previousTabID}"] .chrome-tab-favicon`);
172+
if (title == "" || title == null) { title = "Search"; }
173+
if (favicon == "" || favicon == null) { favicon = "favicon.ico"; }
174+
if (tabTitle && tabFavicon) {
175+
tabTitle.innerHTML = title;
176+
tabFavicon.style.backgroundImage = `url(${favicon})`;
177+
}
178+
else {
179+
console.log('tabTitle is null');
180+
}
181+
}
156182
function init() {
157183
chromeTabs.removeTab(chromeTabs.activeTabEl);
158184
chromeTabs.addTab({

src/public/loading.gif

42.9 KB
Loading

0 commit comments

Comments
 (0)