Last active
November 28, 2018 21:20
-
-
Save timaschew/8de89a2c5ba338ee3ab9d539bb1af07f to your computer and use it in GitHub Desktop.
instagram contest analyzer and rollling the dice script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// roll the dice for instagram and wordpress comments | |
// you need to open web developer toolbar and open the console for these commands | |
//step 1: go to instagram post and ensure to load all comments | |
MIN_MENTION = 2;function unique(value, index, self) { return self.indexOf(value) === index;};copy(Array.prototype.slice.call($$(".k59kT li")).filter(e => e.querySelectorAll('.notranslate').length >= MIN_MENTION+1).map(e => e.querySelector('h3')).filter(e => e != null).map(e => e.textContent).filter(unique)) | |
// step 2: go to wordpress backend and use edit mode for the page | |
r1 = <PASTE YOUR CLIPBOARD CONTENT> | |
// step 3: ensure to scroll to the bottom and load all comments | |
r2 = jQuery.unique(jQuery("#the-comment-list tr td a").filter((_, a) => a.href.indexOf('mailto:') != -1).map((_, a) => a.textContent)) | |
// step 4: roll the dice | |
final = r1.concat(r2); index = Math.floor(Math.random() * final.length); console.log(final[index]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// run the commands in the browser console | |
// configuration (execute the line below) | |
MIN_MENTION = 2 | |
// to collect all comments, ensure you load (click load more) all the comments (by default some comments are not loaded) | |
// 1. go on first page and execute this | |
result1 = Array.prototype.slice.call($$("article ul li")).slice(1).filter(e => e.querySelectorAll("span > a").length >= MIN_MENTION).map(e => e.querySelector(":scope > a").textContent) | |
// 2. go on second page and execute this | |
result2 = Array.prototype.slice.call($$("article ul li")).slice(1).filter(e => e.querySelectorAll("span > a").length >= MIN_MENTION).map(e => e.querySelector(":scope > a").textContent) | |
// if you want to collect from more pages, just continue the same way | |
// 3. stay on the current page and execute everything below | |
map = {} | |
// adapt this line if you have more than two results | |
result1.concat(result2).forEach(name => map[name] = 1) | |
style = document.createElement("style") | |
style.textContent = ` | |
article ul li { | |
padding: 2px 2px; | |
} | |
.selected a { | |
color: white; | |
} | |
.selected { | |
background-color: red; | |
-webkit-transition: background-color 200ms linear; | |
-ms-transition: background-color 200ms linear; | |
transition: background-color 200ms linear; | |
} | |
.winner { | |
font-weight: bold; | |
padding: 20px 2px; | |
-webkit-transition: padding 200ms linear; | |
-ms-transition: padding 200ms linear; | |
transition: padding 200ms linear; | |
} | |
` | |
$("head").appendChild(style) | |
$(".M30cS").innerHTML = "" | |
button = document.createElement("button") | |
button.textContent = "roll the dice" | |
button.className = "dice _5f5mN jIbKX KUBKM yZn4P" | |
button.addEventListener('click', function(event) { | |
event.preventDefault() | |
list = document.querySelector("article ul") | |
// reset game if it was already triggered | |
if (lastCandidate) { | |
list.querySelector("li." + lastCandidate).classList.remove("selected") | |
list.querySelector("li." + lastCandidate).classList.remove("winner") | |
} | |
shuffle() | |
}) | |
$(".M30cS").appendChild(button) | |
names = Object.keys(map) | |
list = $("article ul") | |
list.innerHTML = "" | |
names.forEach(name => { | |
const a = document.createElement("a") | |
a.href = "/" + name + "/" | |
a.target = "_blank" | |
a.textContent = name | |
const li = document.createElement("li") | |
li.className = name.replace(/\./g, '--') | |
li.append(a) | |
list.appendChild(li) | |
}) | |
lastCandidate = null | |
function shuffle() { | |
const list = document.querySelector("article ul") | |
const intervalId = setInterval(() => { | |
const id = Math.floor(Math.random() * names.length) | |
const candidate = names[id].replace(/\./g, '--') | |
if (lastCandidate) { | |
list.querySelector("li." + lastCandidate).classList.remove("selected") | |
} | |
list.querySelector("li." + candidate).classList.add("selected") | |
list.querySelector("li." + candidate).scrollIntoViewIfNeeded() | |
lastCandidate = candidate | |
}, 200) | |
setTimeout(() => { | |
clearInterval(intervalId) | |
list.querySelector("li." + lastCandidate).classList.add("selected") | |
list.querySelector("li." + lastCandidate).classList.add("winner") | |
}, 10 * 1000) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment