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=
"#add-' + proposal.id + '" 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
49 .sort((a, b) =
> b.total_occurrences - a.total_occurrences)
50 .forEach((proposal) =
> {
52 container.appendChild(generateProposalHTML(proposal));
57 * Simple dumb guard for multi-voting, stores a value.
60 var guard = function(proposal) {
61 if (localStorage.getItem(proposal)) {
65 localStorage.setItem(proposal, true);
70 * Creates a proposal in rollbar
72 var createProposal = function(proposal) {
74 if (guard(proposal)) {
76 var request = new XMLHttpRequest();
77 request.addEventListener('load', () =
> location.reload());
78 request.open('POST', 'https://api.rollbar.com/api/
1/item/');
79 request.send(JSON.stringify({
80 access_token: kProjectAccessToken,
82 environment: "production",
99 * Submits a new proposal
101 var onSubmit = function(event) {
103 event.preventDefault();
104 var proposal = event.target.querySelector('[
name="proposal"]').value;
107 alert("please. be serious")
111 createProposal(proposal);
112 setTimeout(Location.reload,
100);
118 var main = function(event) {
120 var form = document.querySelector('form');
121 form.addEventListener('submit', onSubmit);
126 window.addEventListener('load', main);
130 <h1>Help me decide what to do during quarantine
</h1>
131 <p>Vote on the recommendations, or
<a href=
"#add">add one
</a>.
</p>
132 <ol id=
"proposals"></ol>
133 <h1 id=
"add">Add a recommendation
</h1>
136 <label for=
"proposal">You should...
</label>
137 <input name=
"proposal">
139 <input type=
"submit" value=
"Do it.">