-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathurlhighlight.min.js
5 lines (5 loc) · 2.34 KB
/
urlhighlight.min.js
1
2
3
4
5
(function(g,b){if(typeof define==="function"&&define.amd)define(b);else g.urlhighlight=b()})(this,function(){function g(a){d.href=a;a={source:a,protocol:d.protocol,host:d.hostname,port:d.port,query:d.search,params:function(){for(var c={},e=d.search.replace(/^\?/,"").split("&"),f=e.length;f--;)if(e[f]){var h=e[f].split("=");c[h[0]]=h[1]}return c}(),file:(d.pathname.match(/\/([^\/?#]+)$/i)||[,""])[1],hash:d.hash.replace("#",""),path:d.pathname.replace(/^([^\/])/,"/$1"),relative:(d.href.match(/tps?:\/\/[^\/]+(.+)/)||
[,""])[1],segments:d.pathname.replace(/^\//,"").split("/")};if(a.protocol==="data-uri:"){a.mimeType=d.pathname.replace(/,.*$/,"");a.encoding=d.pathname.replace(/(^.*,)(.*)(;.*$)/,"$2");a.data=d.pathname.replace(/(^.*,)(.*)(;.*$)/,"$3").substring(1)}return a}function b(a,c){return a.replace(/{{.*}}/,c)}var d=document.createElement("a");return function(a){var c=g(a.url);if(c.data)return[b(a.protocol||'<span class="url-protocol">{{protocol}}</span>',c.protocol),b(a.mimeType||'<span class="url-mime-type">{{mimeType}}</span>',
c.mimeType),b(a.urlmimeTypeDelimiter||'<span class="url-mime-type-delimiter">,</span>'),b(a.encoding||'<span class="url-encoding">{{encoding}}</span>',c.encoding),b(a.encodingDelimiter||'<span class="url-encoding-delimiter">;</span>'),b(a.data||'<span class="url-data">{{data}}</span>',c.data)].join("");var e=[],f;for(f in c.params)e.push([b(a.queryParamName||'<span class="url-query-param-name">{{name}}</span>',f),b(a.queryParamAssign||'<span class="url-query-param-assign">=</span>'),b(a.queryParamValue||
'<span class="url-query-param-value">{{value}}</span>',c.params[f])].join(""));return[b(a.protocol||'<span class="url-protocol">{{protocol}}</span>',c.protocol),b(a.protocolDelimiter||'<span class="url-protocol-delimiter">//</span>'),b(a.host||'<span class="url-host">{{host}}</span>',c.host),c.port?b(a.portDelimiter||'<span class="url-port-delimiter">:</span>'):"",c.port?b(a.port||'<span class="url-port">{{port}}</span>',c.port):"",c.path!=="/"?b(a.path||'<span class="url-path">{{path}}</span>',c.path):
"",e.length?b(a.queryDelimiter||'<span class="url-query-delimiter">?</span>'):"",e.join(b(a.queryParamDelimiter||'<span class="url-query-param-delimiter">&</span>')),c.hash?b(a.hashDelimiter||'<span class="url-hash-delimiter">#</span>'):"",c.hash?b(a.hash||'<span class="url-hash">{{hash}}</span>',c.hash):""].join("")}});