Skip to content

Commit 426b6f9

Browse files
committed
Uses location.origin where applicable
1 parent fe05798 commit 426b6f9

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

htmlpreview.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,7 @@
5555
* @param {string} url - Any URL
5656
*/
5757
const rewrite = function (url) {
58-
let port_part;
59-
if (location.port.length) {
60-
port_part = ':' + location.port;
61-
} else {
62-
port_part = '';
63-
}
64-
return location.protocol + '//' + location.hostname + port_part + location.pathname + '?' + url;
58+
return location.origin + location.pathname + '?' + url;
6559
}
6660

6761
/**
@@ -116,7 +110,9 @@
116110
// Rewrite links to this document only
117111
if ((a[i].protocol + '//' + a[i].hostname + a[i].pathname) == rawFileUrl) {
118112
// Then rewrite URL with support for empty anchor
119-
a[i].href = location.protocol + '//' + location.hostname + ':' + location.port + location.pathname + location.search + '#' + a[i].hash.substring(1);
113+
a[i].href =
114+
location.origin + location.pathname + location.search
115+
+ '#' + a[i].hash.substring(1);
120116
}
121117
// Do not modify external URLs with fragment
122118
} else if (isGitForgeFileUrl(href) && isHtmlUrl(href)) {

0 commit comments

Comments
 (0)