Skip to content

Instantly share code, notes, and snippets.

@swkidd
Created May 1, 2020 16:53
Show Gist options
  • Save swkidd/d700f1f7132c2cc690d6f425473e306f to your computer and use it in GitHub Desktop.
Save swkidd/d700f1f7132c2cc690d6f425473e306f to your computer and use it in GitHub Desktop.
// first load the page so all reviews are showing (hold space bar until it stops loading reviews)
// then open up developer tools ctrl-l and type the following AFTER UNDERSTANDING WHAT IT DOES
// never paste code you don't understand into the developer tools
// grab all reviews (which have css class "we-customer-review"
let reviews = [...document.querySelectorAll(".we-customer-review")]
// grab the stars for each review
// stars have the css class "we-star-rating-stars"
// the last character of the full class string happens to have the number of stars
let stars = e => { return e.querySelector(".we-star-rating-stars").classList.value.slice(-1) }
// store review text and add number of stars to text
let review_text = reviews.map(e => {
const t = e.innerText
const index = t.indexOf(" ")
return t.slice(0, index) + " " + stars(e) + " stars, " + t.slice(index)
})
// remove "more" from each reviews text
// reviews that are too large have a 'more' button at the bottom
review_text = review_text.map(t => {
if (t.slice(-4) === 'more') {
return t.slice(0, -4)
}
return t
})
// store all reviewsseperated by ";"
review_string = ""
review_text.forEach(t => review_string += t + ";\n")
// now all the reviews are in your clip-board (ctrl-c)
copy(review_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment