Skip to content

Instantly share code, notes, and snippets.

@iurevych
Created May 16, 2020 19:56
Show Gist options
  • Save iurevych/3d368db3280ba3f70fed46ca69458c08 to your computer and use it in GitHub Desktop.
Save iurevych/3d368db3280ba3f70fed46ca69458c08 to your computer and use it in GitHub Desktop.
// Функция принимает всего лишь один аргумент: порядковый номер коммента, который надо найти
// Она сама тыкает на плюсик если надо еще подгрузить комеентов
// Найденный коммент выделяется желтым и страница сама к нему проскролится
// With <3 from iurevych
function findComment(commentToFind) {
const commentsCount = document.querySelectorAll('ul [role="button"]').length - 1
if (commentsCount < (commentToFind - 1)) {
const expandMore = document.querySelector('[aria-label="Load more comments"]')
expandMore && expandMore.click()
setTimeout(() => { findComment(commentToFind) }, 3000)
} else {
const desiredComment = document.querySelectorAll('ul [role="button"]')[commentToFind - 1]
if (desiredComment) {
desiredComment.parentNode.setAttribute('style', 'background-color: yellow;')
desiredComment.scrollIntoView({block: "center", behavior: "smooth"})
}
}
}
// Пример использования
findComment(132) // найдет 132 коммент и проскролит к нему, выделив коммент желтым цветом
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment