Created
June 16, 2020 08:44
-
-
Save Xatta-Trone/1668e992f26b2aa387a026fcc9c1352f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getIdFrom(url) { | |
| var id = ""; | |
| var parts = url.split(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/); | |
| if (url.indexOf('?id=') >= 0){ | |
| id = (parts[6].split("=")[1]).replace("&usp",""); | |
| return id; | |
| } else { | |
| id = parts[5].split("/"); | |
| //Using sort to get the id as it is the longest element. | |
| var sortArr = id.sort(function(a,b){return b.length - a.length}); | |
| id = sortArr[0]; | |
| return id; | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment