5 <meta name=
"viewport" content=
"width=device-width, initial-scale=1">
6 <meta name=
"author" content=
"Rubén Beltrán del Río">
7 <meta name=
"description" content=
"crowdsourcing quarantine software">
9 <meta name=
"theme-color" content=
"#ffffff">
11 <title>Help me decide what to do during quarantine
</title>
15 var kProjectAccessToken = 'd42555177ceb4395a2679dae0c622100';
16 var kReadToken = 'e5c2d4b6ceab453aaf38f6930e6550cf';
19 * Fetches the proposals
21 var fetchProposals = function() {
23 var request = new XMLHttpRequest();
24 request.addEventListener('load', renderEvents);
25 request.open('GET', 'https://api.rollbar.com/api/
1/items/?access_token=' + kReadToken + '&environment=production&status=active');
30 * Given a single proposal, generates HTML
32 var generateProposalHTML = function(proposal) {
34 var listItem = document.createElement('li');
35 listItem.innerHTML = proposal.title + ' (' + proposal.total_occurrences + ' votes)
<a href=
"#" onclick=
"createProposal(\'' + proposal.title.replace(/'/g, '\\\'')+ '\')">I agree.
</a> </li>'
40 * Renders the events from the rollbar response
42 var renderEvents = function(response) {
44 const parsedResponse = JSON.parse(this.response);
46 const container = document.getElementById('proposals');
48 parsedResponse.result.items.forEach((proposal) =
> {
50 container.appendChild(generateProposalHTML(proposal));
55 * Simple dumb guard for multi-voting, stores a value.
58 var guard = function(proposal) {
59 if (localStorage.getItem(proposal)) {
63 localStorage.setItem(proposal, true);
68 * Creates a proposal in rollbar
70 var createProposal = function(proposal) {
72 if (guard(proposal)) {
74 var request = new XMLHttpRequest();
75 request.addEventListener('load', () =
> location.reload());
76 request.open('POST', 'https://api.rollbar.com/api/
1/item/');
77 request.send(JSON.stringify({
78 access_token: kProjectAccessToken,
80 environment: "production",
97 * Submits a new proposal
99 var onSubmit = function(event) {
101 event.preventDefault();
102 var proposal = event.target.querySelector('[
name="proposal"]').value;
105 alert("please. be serious")
109 createProposal(proposal);
110 setTimeout(Location.reload,
100);
116 var main = function(event) {
118 var form = document.querySelector('form');
119 form.addEventListener('submit', onSubmit);
124 window.addEventListener('load', main);
128 <h1>Help me decide what to do during quarantine
</h1>
129 <p>Vote on the recommendations, or
<a href=
"#add">add one
</a>.
</p>
130 <ul id=
"proposals"></ul>
131 <h1 id=
"add">Add a recommendation
</h1>
134 <label for=
"proposal">You should...
</label>
135 <input name=
"proposal">
137 <input type=
"submit" value=
"Do it.">