Skip to content

Instantly share code, notes, and snippets.

@andersonbosa
Last active May 13, 2020 02:52
Show Gist options
  • Save andersonbosa/25a0b1c26132393c0bfb855b4ba80ea7 to your computer and use it in GitHub Desktop.
Save andersonbosa/25a0b1c26132393c0bfb855b4ba80ea7 to your computer and use it in GitHub Desktop.
/**
* Get task card from given search
* @param {String} searchString - string to find
* @param {String} [where] - selector context.
* default value is .task-title a
* @returns {Object[]}
*/
function getCardId(searchString, where) {
if (!searchString) {
return
}
searchString = ('card_id/' + searchString)
if (!where) {
where = '.task-title a'
}
let elements = Array.from(document.querySelectorAll(where));
if (elements.length) {
return elements.filter(element => element.href.replace(/http[?s]:\/\//gm, '') === searchString)[0]
} else {
return {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment