diff options
-rw-r--r-- | common/patterns.js | 9 | ||||
-rw-r--r-- | content/main.js | 2 |
2 files changed, 9 insertions, 2 deletions
diff --git a/common/patterns.js b/common/patterns.js index 0a322b0..ebb55ab 100644 --- a/common/patterns.js +++ b/common/patterns.js @@ -7,6 +7,7 @@ const proto_regex = /^(\w+):\/\/(.*)$/; +const user_re = "[^/?#@]+@" const domain_re = "[^/?#]+"; const path_re = "[^?#]*"; const query_re = "\\??[^#]*"; @@ -15,6 +16,8 @@ const http_regex = new RegExp(`^(${domain_re})(${path_re})(${query_re}).*`); const file_regex = new RegExp(`^(${path_re}).*`); +const ftp_regex = new RegExp(`^(${user_re})?(${domain_re})(${path_re}).*`); + function deconstruct_url(url) { const proto_match = proto_regex.exec(url); @@ -25,14 +28,18 @@ function deconstruct_url(url) if (deco.proto === "file") { deco.path = file_regex.exec(proto_match[2])[1]; + } else if (deco.proto === "ftp") { + [deco.domain, deco.path] = ftp_regex.exec(proto_match[2]).slice(2, 4); } else { const http_match = http_regex.exec(proto_match[2]); if (!http_match) return undefined; [deco.domain, deco.path, deco.query] = http_match.slice(1, 4); - deco.domain = deco.domain.split("."); } + if (deco.domain) + deco.domain = deco.domain.split("."); + const leading_dash = deco.path[0] === "/"; deco.trailing_dash = deco.path[deco.path.length - 1] === "/"; deco.path = deco.path.split("/").filter(s => s !== ""); diff --git a/content/main.js b/content/main.js index 06d3bf1..6c97350 100644 --- a/content/main.js +++ b/content/main.js @@ -109,7 +109,7 @@ if (!is_privileged_url(document.URL)) { document.cookie = `hachette-${signature}=; Max-Age=-1;`; } else { const scheme = /^([^:]*)/.exec(document.URL)[1]; - const known_scheme = ["file"].includes(scheme); + const known_scheme = ["file", "ftp"].includes(scheme); if (!known_scheme) console.warn(`Unknown url scheme: \`${scheme}'!`); |