Optimize getURL() logic.

This commit is contained in:
Kenshin 2017-01-06 16:57:12 +08:00
parent 355b2d81c4
commit 1a87631fd6

View File

@ -137,11 +137,8 @@ function swap( source, target ) {
* @return {string} e.g. current site url is http://www.cnbeta.com/articles/1234.html return http://www.cnbeta.com/articles/
*/
function getURI() {
let arr = window.location.pathname.match( /[^\/]+/g );
if ( arr == null ) arr = [];
arr.pop();
const str = arr.join( "" ) === "" ? arr.join( "" ) : arr.join( "" ) + "/";
return `${ window.location.protocol }//${ window.location.hostname }/${ str }`;
const arr = window.location.pathname.match( /(\S+\/|^\/)/g );
return `${ window.location.protocol }//${ window.location.hostname }${ arr[0] }`;
}
/**