aboutsummaryrefslogtreecommitdiff
path: root/src/content/navigates.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-09-17 12:52:24 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-09-17 12:52:24 +0900
commite9863299abf9498c67660e8a97c70ddb090baffe (patch)
treeda322c6d1cac671da59b34dac884905718503516 /src/content/navigates.js
parent0be9776cb3d9033bcd3ae569bec71b300f2d4073 (diff)
implement go-parent command
Diffstat (limited to 'src/content/navigates.js')
-rw-r--r--src/content/navigates.js21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/content/navigates.js b/src/content/navigates.js
index b68052d..692b7be 100644
--- a/src/content/navigates.js
+++ b/src/content/navigates.js
@@ -44,4 +44,23 @@ const linkNext = (win) => {
}
};
-export { historyPrev, historyNext, linkPrev, linkNext };
+const parent = (win) => {
+ let loc = win.location;
+ if (loc.hash !== '') {
+ loc.hash = '';
+ return;
+ } else if (loc.search !== '') {
+ loc.search = '';
+ return;
+ }
+
+ const basenamePattern = /\/[^/]+$/;
+ const lastDirPattern = /\/[^/]+\/$/;
+ if (basenamePattern.test(loc.pathname)) {
+ loc.pathname = loc.pathname.replace(basenamePattern, '/');
+ } else if (lastDirPattern.test(loc.pathname)) {
+ loc.pathname = loc.pathname.replace(lastDirPattern, '/');
+ }
+};
+
+export { historyPrev, historyNext, linkPrev, linkNext, parent };