-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaLocal.min.js
6 lines (6 loc) · 1.05 KB
/
aLocal.min.js
1
2
3
4
5
6
'use strict';var aLocal=function(){let err='[aLocal.js]\n\n';this.local='http://localhost/';this.path='file:///C:/xampp/htdocs/';this.reg_path;this.current=()=>{return window.location.toString()}
this.root=()=>{if(this.path){let fetch=this.path.split('/');return fetch[fetch.length-2]}}
aLocal.prototype.change=()=>{if(this.current().match(this.path)){let modified=this.local+this.current().substring(this.current().lastIndexOf((()=>{var folder=this.current().substring(this.current().lastIndexOf('/'+this.root()+'/')+1);return folder.split('/')[1]})()));window.location.href=modified}else if(!this.current().match(this.local)){alert(err+'Could not fetch the root path:\n'+this.reg_path)}}
aLocal.prototype.setLocal=(local)=>{if(local.match(/^http:\/\/\w+\//gi)){this.local=local}else{alert(err+local+' must be a valid URL\n')}}
aLocal.prototype.setPath=(path)=>{if(path!=null){this.reg_path=path;let new_path=new RegExp(this.reg_path,'g');this.path=new_path.toString();this.path=this.path.replace(/\\\/+g/g,'/').replace(/\//,'')}}}
var alocal=new aLocal();alocal.change()