Skip to content

Commit 2ea30cc

Browse files
authored
Dat Domain error message
+ Added an error message to let the user know Dat domains aren't supported yet.
1 parent eb79f03 commit 2ea30cc

3 files changed

Lines changed: 40 additions & 12 deletions

File tree

chrome extension/background.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,21 +247,37 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
247247
chrome.omnibox.onInputChanged.addListener(function(text, suggest) {
248248
console.log('inputChanged: ' + text);
249249
if (text.substring(0, 6) == "dat://") {
250-
250+
251251
suggest([{
252252
content: text,
253-
description: "Open " + text + " with DatPart?" + chrome.runtime.getManifest().name[0] + "?" //Create as object in variable first
253+
description: "Open " + text + " with " + chrome.runtime.getManifest().short_name + "?"
254+
}]);
255+
256+
} else if (text.indexOf('.') !== -1) {
257+
258+
suggest([{
259+
content: text,
260+
description: "Dat Domains not supported yet."
254261
}]);
255262

256263
}
257264
});
258265

259266
chrome.omnibox.onInputEntered.addListener(function(text) {
260267
console.log('inputEntered: ' + text);
268+
if (text.indexOf('.') !== -1) {
269+
270+
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
271+
chrome.tabs.update(tabs[0].id, {url: "/dat_error.html?dat_domain=notyet&dat=" + encodeURIComponent(text)});
272+
});
261273

262-
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
263-
chrome.tabs.update(tabs[0].id, {url: "/redirector.html?dat=" + encodeURIComponent(text)});
264-
});
274+
} else {
275+
276+
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
277+
chrome.tabs.update(tabs[0].id, {url: "/redirector.html?dat=" + encodeURIComponent(text)});
278+
});
279+
280+
}
265281
});
266282

267283
chrome.webNavigation.onBeforeNavigate.addListener(function(details) {

chrome extension/dat_error.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
</head>
2525
<body>
2626
<h1>❗️ Error</h1>
27-
<br/>The server app might not be running. Open it and then try to load the page again.<br/><br/>If that doesn't work, try restarting it.<br/><br/>If you don't have the app, <a href="https://github.com/HughIsaacs2/DatPart/releases" target="_blank">you can get it here</a>.<br/><br/>
27+
<article id="message"><br/>The server app might not be running. Open it and then try to load the page again.<br/><br/>If that doesn't work, try restarting it.<br/><br/>If you don't have the app, <a href="https://github.com/HughIsaacs2/DatPart/releases" target="_blank">you can get it here</a>.<br/><br/></article>
2828
</body>
2929
</html>

chrome extension/dat_error.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,22 @@ function queryObj() {
1414

1515
var datLink = queryObj()["dat"];
1616

17+
var datDomainQuery = queryObj()["dat_domain"];
18+
1719
var datUrl = unescape(datLink);
1820

21+
var datDomain = unescape(datDomainQuery);
22+
1923
if (datUrl.substring(0, 4) == "web+") {
2024
datUrl = datUrl.substring(4, datUrl.length);
2125
}
2226

27+
if (datDomain == "notyet") {
28+
document.getElementById("message").textContent = "Sorry. Dat Domains aren't supported in " + chrome.runtime.getManifest().short_name + " yet.";
29+
}
30+
31+
document.body.appendChild(document.createElement('br'));
32+
2333
var siteInfo = document.createElement('span');
2434
siteInfo.id = "error-site-info";
2535
siteInfo.className = "info-box";
@@ -29,12 +39,14 @@ document.body.appendChild(siteInfo);
2939
document.body.appendChild(document.createElement('br'));
3040
document.body.appendChild(document.createElement('br'));
3141

32-
var retryLink = document.createElement('a');
33-
retryLink.href = "http://"+datUrl.substring(6, 70)+".dat_site"+datUrl.substring(70, datUrl.length);
34-
retryLink.innerText = "Retry";
35-
retryLink.title = "Try loading the page again";
36-
retryLink.className = "button";
37-
document.body.appendChild(retryLink);
42+
if (datDomain !== "notyet") {
43+
var retryLink = document.createElement('a');
44+
retryLink.href = "http://" + datUrl.substring(6, 70) + ".dat_site" + datUrl.substring(70, datUrl.length);
45+
retryLink.innerText = "Retry";
46+
retryLink.title = "Try loading the page again";
47+
retryLink.className = "button";
48+
document.body.appendChild(retryLink);
49+
}
3850

3951
document.body.appendChild(document.createElement('br'));
4052
document.body.appendChild(document.createElement('br'));

0 commit comments

Comments
 (0)