Created
September 23, 2019 18:26
-
-
Save jenovs/3e6c453dcc8923c90cb8db1ddbcbd4c6 to your computer and use it in GitHub Desktop.
Add query param to the link
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
| const parser = (str, time) => { | |
| if (!time) { | |
| return str; | |
| } | |
| const re = /src="([^"]+)"/; | |
| const match = re.exec(str); | |
| if (!match) { | |
| return str; | |
| } | |
| try { | |
| const [, url] = match; | |
| const newUrl = new URL(url); | |
| newUrl.searchParams.set('t', time); | |
| return str.replace(url, newUrl); | |
| } catch (e) { | |
| console.log(e.message); | |
| } | |
| return str; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment