Skip to content

Instantly share code, notes, and snippets.

@fanfare
Last active October 22, 2019 21:15
Show Gist options
  • Save fanfare/00f9ce6d797772d40127c31f5ee6c640 to your computer and use it in GitHub Desktop.
Save fanfare/00f9ce6d797772d40127c31f5ee6c640 to your computer and use it in GitHub Desktop.
run this to see which posts' first comment start with "I"
function get(url) {
return new Promise((resolve, reject) => {
try {
var startswith = false
var request = new XMLHttpRequest()
request.open('GET', url, true)
request.onload = function() {
if (this.status >= 200 && this.status < 400) {
var data = this.response
var html = document.createElement('html')
html.innerHTML = data
var comments = html.querySelectorAll('table.comment-tree tr table tr td.default div.comment span.commtext')
if (comments && comments[0] && comments[0].innerText) {
startswith = comments[0].innerText.substring(0,2).toLowerCase() === "i "
}
resolve(startswith)
}
}
request.send()
}
catch(e) {
resolve(false)
}
})
}
;(async function(){
var comments = document.querySelectorAll(`td > a[href*="item?"]:not(.storylink)`)
function colorize(val) {
comments[i].parentElement.parentElement.previousSibling.setAttribute("style", `background:${val}`)
}
for (var i=0;i<comments.length;i++) {
var url = comments[i].href
colorize("#93ffec7a")
var response = await get(url)
colorize("unset")
if (response) {
colorize("#df8fff")
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment