Skip to content

Commit eb2edd3

Browse files
committed
Support direct http urls for chrome extension
1 parent c8beb59 commit eb2edd3

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

js/SiteMenu.coffee

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ class SiteMenu extends Menu
4343
constructor: (elem, site) ->
4444
super($(".hamburger", elem))
4545
@elem.addClass("menu-site")
46-
@addItem "Update", (-> window.zero_hello.siteUpdate site.content.address )
46+
@addItem "Update", (-> window.zero_hello.siteUpdate site.address )
4747
if site.settings.serving
48-
@addItem "Pause", (-> window.zero_hello.sitePause site.content.address )
48+
@addItem "Pause", (-> window.zero_hello.sitePause site.address )
4949
else
50-
@addItem "Resume", (-> window.zero_hello.siteResume site.content.address )
51-
@addItem("Delete", (-> window.zero_hello.siteDelete site.content.address ) ).addClass("menu-item-separator")
50+
@addItem "Resume", (-> window.zero_hello.siteResume site.address )
51+
@addItem("Delete", (-> window.zero_hello.siteDelete site.address ) ).addClass("menu-item-separator")
5252

5353

5454
window.visible_menu = null

js/ZeroHello.coffee

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class ZeroHello extends ZeroFrame
33
@log "inited!"
44
@sites = {}
55
@local_storage = null
6+
@is_proxy_request = document.location.host == "zero" or document.location.pathname == "/" # Using Chrome extension
67
@cmd "wrapperGetLocalStorage", [], (res) =>
78
res ?= {}
89
@local_storage = res
@@ -95,9 +96,19 @@ class ZeroHello extends ZeroFrame
9596

9697
# Add href
9798
if @server_info.plugins? and ("Zeroname" in @server_info.plugins or "Dnschain" in @server_info.plugins) and site.content?.domain # Domain
98-
$(".site", elem).attr("href", "/"+site.content.domain)
99+
if @is_proxy_request
100+
href = "http://"+site.content.domain
101+
else
102+
href = "/"+site.content.domain
99103
else # Address
100-
$(".site", elem).attr("href", "/"+site.address)
104+
if @is_proxy_request
105+
href = "http://zero/"+site.address
106+
else
107+
href = "/"+site.address
108+
109+
$(".site", elem).attr("href", href)
110+
111+
101112

102113
$(elem).removeClass("site-seeding").removeClass("site-paused")
103114
if site.settings.serving and site.address # Seeding

js/all.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -844,19 +844,19 @@ jQuery.extend( jQuery.easing,
844844
SiteMenu.__super__.constructor.call(this, $(".hamburger", elem));
845845
this.elem.addClass("menu-site");
846846
this.addItem("Update", (function() {
847-
return window.zero_hello.siteUpdate(site.content.address);
847+
return window.zero_hello.siteUpdate(site.address);
848848
}));
849849
if (site.settings.serving) {
850850
this.addItem("Pause", (function() {
851-
return window.zero_hello.sitePause(site.content.address);
851+
return window.zero_hello.sitePause(site.address);
852852
}));
853853
} else {
854854
this.addItem("Resume", (function() {
855-
return window.zero_hello.siteResume(site.content.address);
855+
return window.zero_hello.siteResume(site.address);
856856
}));
857857
}
858858
this.addItem("Delete", (function() {
859-
return window.zero_hello.siteDelete(site.content.address);
859+
return window.zero_hello.siteDelete(site.address);
860860
})).addClass("menu-item-separator");
861861
}
862862

@@ -901,6 +901,7 @@ jQuery.extend( jQuery.easing,
901901
this.log("inited!");
902902
this.sites = {};
903903
this.local_storage = null;
904+
this.is_proxy_request = document.location.host === "zero" || document.location.pathname === "/";
904905
this.cmd("wrapperGetLocalStorage", [], (function(_this) {
905906
return function(res) {
906907
if (res == null) {
@@ -990,7 +991,7 @@ jQuery.extend( jQuery.easing,
990991
};
991992

992993
ZeroHello.prototype.applySitedata = function(elem, site) {
993-
var error, modified, success, _ref, _ref1, _ref2, _ref3;
994+
var error, href, modified, success, _ref, _ref1, _ref2, _ref3;
994995
if (typeof site.bad_files === "object") {
995996
site.bad_files = site.bad_files.length;
996997
}
@@ -1012,10 +1013,19 @@ jQuery.extend( jQuery.easing,
10121013
modified = site.settings.modified ? site.settings.modified : site.content.modified;
10131014
$(".modified-date", elem).html(this.formatSince(modified));
10141015
if ((this.server_info.plugins != null) && (__indexOf.call(this.server_info.plugins, "Zeroname") >= 0 || __indexOf.call(this.server_info.plugins, "Dnschain") >= 0) && ((_ref = site.content) != null ? _ref.domain : void 0)) {
1015-
$(".site", elem).attr("href", "/" + site.content.domain);
1016+
if (this.is_proxy_request) {
1017+
href = "http://" + site.content.domain;
1018+
} else {
1019+
href = "/" + site.content.domain;
1020+
}
10161021
} else {
1017-
$(".site", elem).attr("href", "/" + site.address);
1022+
if (this.is_proxy_request) {
1023+
href = "http://zero/" + site.address;
1024+
} else {
1025+
href = "/" + site.address;
1026+
}
10181027
}
1028+
$(".site", elem).attr("href", href);
10191029
$(elem).removeClass("site-seeding").removeClass("site-paused");
10201030
if (site.settings.serving && site.address) {
10211031
$(elem).addClass("site-seeding");

0 commit comments

Comments
 (0)