Skip to content

Instantly share code, notes, and snippets.

@mat-1
Last active April 3, 2020 09:41
Show Gist options
  • Save mat-1/fd4f5d6fd86588fff057af4c9f362649 to your computer and use it in GitHub Desktop.
Save mat-1/fd4f5d6fd86588fff057af4c9f362649 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Auto Imposter Bot
// @namespace https://matdoes.dev
// @version 0.2
// @description Plays r/imposter for you
// @author mat
// @match https://gremlins-api.reddit.com/*
// @grant none
// ==/UserScript==
async function checkAnswerOcean(element) {
const text = element.textContent.trim()
const r = await fetch('https://wave.ocean.rip/answers/answer?text=' + text)
const resp = await r.json()
element.isCorrect = true
if (resp.status === 404) {
element.style.opacity = 1
element.isCorrect = true
return true
} else if (resp.answer.is_correct === false) {
element.isCorrect = false
element.style.opacity = .1
return false
}
element.isCorrect = true
element.style.opacity = 1
return true
}
async function checkAnswersOcean(answerEls) {
const promises = []
for (const answerEl of answerEls) {
promises.push(checkAnswerOcean(answerEl))
}
await Promise.all(promises)
const correctAnswerEls = []
for (const answerEl of answerEls)
if (answerEl.isCorrect)
correctAnswerEls.push(answerEl)
return correctAnswerEls
}
async function checkAnswerSpacescience(element) {
const id = element.id
try {
var r = await fetch('https://spacescience.tech/check.php?id=' + id)
} catch(e) {
return true
}
const resp = await r.json()
console.log(resp)
element.isCorrect = true
if (resp.slow === 'yes') return true
for (const item of Object.values(resp)) {
if (item.flag) {
if (item.result === 'LOSE') {
element.style.opacity = .1
element.isCorrect = false
return false
}
/*else {
element.isCorrect = true
element.style.opacity = 1
return false
}*/
}
}
return true
}
async function checkAnswersSpacescience(answerEls) {
const promises = []
for (const answerEl of answerEls) {
promises.push(checkAnswerSpacescience(answerEl))
}
await Promise.all(promises)
const correctAnswerEls = []
for (const answerEl of answerEls)
if (answerEl.isCorrect)
correctAnswerEls.push(answerEl)
return correctAnswerEls
}
async function checkAnswersSneknet(answerEls) {
const r = await fetch('https://api.snakeroom.org/y20/query', {
method: 'POST',
body: JSON.stringify({
options: answerEls.map(answer => answer.innerHTML.trim()),
}),
})
const resp = await r.json()
const possibleAnswers = answerEls
for (const answer of resp.answers) {
const answerEl = answerEls[answer.i]
if (!answer.correct) {
var index = possibleAnswers.indexOf(answerEl)
answerEl.style.opacity = .1
if (index !== -1) possibleAnswers.splice(index, 1);
}
}
return possibleAnswers
}
async function checkAnswerAbraScore(element) {
const text = element.textContent.trim()
const r = await fetch('https://detector.abra.me/?' + text)
const resp = await r.json()
element.fake_probability = resp.fake_probability
return resp.fake_probability
}
async function getTopAbra(answerEls) {
const promises = []
for (const answerEl of answerEls) {
promises.push(checkAnswerAbraScore(answerEl))
}
var highestProbabilityEl
var highestProbabilityScore = -1
await Promise.all(promises)
for (const answerEl of answerEls) {
console.log(answerEl, answerEl.fake_probability)
if (answerEl.fake_probability > highestProbabilityScore) {
highestProbabilityEl = answerEl
highestProbabilityScore = answerEl.fake_probability
console.log('highestProbabilityEl', highestProbabilityEl)
}
}
return highestProbabilityEl
}
async function checkAnswersAbra(answerEls) {
const r = await fetch('https://librarian.abra.me/check', {
method: 'POST',
body: JSON.stringify({
texts: answerEls.map(answer => answer.innerHTML.trim()),
}),
headers: {
'content-type': 'application/json'
}
})
const resp = await r.json()
const possibleAnswers = []
for (let i = 0; i < answerEls.length; i++) {
if (resp.results[i] === 'unknown')
possibleAnswers.push(possibleAnswers)
}
return possibleAnswers
}
async function skip() {
const csrf = document.getElementsByTagName('gremlin-app')[0].getAttribute('csrf')
const noteId = document.getElementsByTagName('gremlin-note')[0].id
const params = new URLSearchParams({
'undefined': 'undefined',
'csrf_token': csrf,
'note_ids': noteId
});
const body = params.toString()
await fetch(
'https://gremlins-api.reddit.com/report_note',
{
method: 'POST',
body,
headers: {
'content-type': 'application/x-www-form-urlencoded',
'accept': 'gremlin/html'
}
}
)
location.reload()
}
function addSkipButton() {
const reportButtonEl = document.getElementsByTagName('gremlin-room')[0].shadowRoot.querySelector('gremlin-action')
const skipButtonEl = document.createElement('gremlin-action')
skipButtonEl.setAttribute('hollow', '')
skipButtonEl.setAttribute('type', '')
skipButtonEl.setAttribute('role', 'button')
reportButtonEl.parentNode.insertBefore(skipButtonEl, reportButtonEl.nextSibling);
skipButtonEl.textContent = 'Skip'
skipButtonEl.addEventListener('click', skip)
}
(async() => {
'use strict';
if (window.location.pathname == '/results') {
window.location.pathname = '/room'
return
}
const answerEls = document.getElementsByTagName('gremlin-note')
for (const element of answerEls) {
element.addEventListener('click', () => {
element.style.borderColor = '#46D160'
})
}
var correctAnswerEls = await checkAnswersOcean(answerEls)
if (correctAnswerEls.length === 1) {
correctAnswerEls[0].click()
} else {
if (correctAnswerEls.length == 0) correctAnswerEls = answerEls
var correctAnswerEls2 = await checkAnswersSpacescience(correctAnswerEls)
if (correctAnswerEls2.length === 1) {
correctAnswerEls2[0].click()
} else {
return skip()
// everything below has false positives
if (correctAnswerEls2.length == 0) correctAnswerEls2 = correctAnswerEls
var correctAnswerEls3 = await checkAnswersSneknet(correctAnswerEls2)
if (correctAnswerEls3.length === 1) {
correctAnswerEls3[0].click()
} else {
if (correctAnswerEls3.length == 0) correctAnswerEls3 = correctAnswerEls2
var correctAnswerEls4 = await checkAnswersAbra(correctAnswerEls3)
if (correctAnswerEls4.length === 1) {
correctAnswerEls4[0].click()
} else {
const topCorrectAnswer = await getTopAbra(correctAnswerEls3)
topCorrectAnswer.style.borderColor = '#46D160'
//topCorrectAnswer.click()
skip()
}
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment