-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
52 lines (49 loc) · 2.09 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function str(t) {
return t.toString()
}
function httpGet(theUrl) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", theUrl, false); // false for synchronous request
xmlHttp.send(null);
return xmlHttp.responseText;
}
function getIdea() {
console.log("grabbing idea")
res = httpGet("http://api.reddit.com/r/AppIdeas/random/.json")
res = JSON.parse(res)[0]['data']['children'][0]['data']
data = JSON.stringify(res).toLowerCase()
critUnmatch = document.getElementById("critUnmatch")
pageTitle = document.getElementById("ptitle")
titleEl = document.getElementById("title")
bodyEl = document.getElementById("body")
postEl = document.getElementById("post")
titleEl.innerText = res.title
bodyEl.innerText = res.selftext
postEl.href = "https://www.reddit.com" + res.permalink
feedbackRequest = data.includes('Feedback request')
dating = data.includes('dating')
download = data.includes('download')
alreadybuilt = data.includes('i built') || data.includes('introducing') || data.includes('i created')
omegle = data.includes('omegle')
findingDev = data.includes('find') && data.includes('dev')
poll = data.includes('reddit.com/poll')
askingFor = data.includes('tell me')
testers = data.includes('testers')
unsureIfRight = data.includes('right place to ask this question')
stringied = str(feedbackRequest) + str(dating) + str(findingDev) + str(alreadybuilt) + str(omegle) + str(findingDev) + str(poll) + str(testers) + str(unsureIfRight)
arrayd = [dating, feedbackRequest, alreadybuilt, omegle, askingFor, findingDev, poll, testers]
console.log(stringied)
if (stringied.includes("true")) {
pageTitle.innerText = "This idea does not meet the criteria"
critUnmatch.hidden = false
i = 0
for (let el of document.querySelectorAll("#critUnmatch input")) {
el.checked = arrayd[i]
i++
}
} else {
pageTitle.innerText = "Here is your idea!"
critUnmatch.hidden = true
}
}
document.getElementById("rollAgain").addEventListener("click", getIdea)