Skip to content

Instantly share code, notes, and snippets.

@jenovs
Created September 23, 2019 18:26
Show Gist options
  • Select an option

  • Save jenovs/3e6c453dcc8923c90cb8db1ddbcbd4c6 to your computer and use it in GitHub Desktop.

Select an option

Save jenovs/3e6c453dcc8923c90cb8db1ddbcbd4c6 to your computer and use it in GitHub Desktop.
Add query param to the link
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