-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgiftexchange.html
More file actions
81 lines (81 loc) · 2.81 KB
/
giftexchange.html
File metadata and controls
81 lines (81 loc) · 2.81 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>I just want a fucking gift exchange name shuffler</title>
<script>
// ROTFL this whole thing is so horrible. Whatever.
function remove(arr, me) {
return arr.filter(e => e !== me);
}
function shufflethefuckingnames() {
var result = document.createElement("ol");
var names = [].slice
.call(document.querySelectorAll("input"))
.flatMap(function(e) {
return e.value;
});
let uniqueNames = [...new Set(names)];
if (names.length > uniqueNames.length) {
var sass = document.createElement("li");
sass.innerHTML =
"You're an idiot. Use unique names for christ' sake.";
result.appendChild(sass);
}
var givers = uniqueNames.slice(0);
var getters = uniqueNames.slice(0);
givers.forEach(function(giver) {
var candidates = remove(getters.slice(0), giver);
var giveridx = givers.indexOf(giver);
var getteridx;
if (
candidates.length == 2 &&
givers.indexOf(candidates[0]) < giveridx
) {
getteridx = 1;
} else {
getteridx = Math.floor(Math.random() * candidates.length);
}
var getter = candidates[getteridx];
getters = remove(getters, getter);
var newnameli = document.createElement("li");
newnameli.innerHTML = giver + " has " + getter;
result.appendChild(newnameli);
});
document.getElementById("results").innerHTML = "";
document.getElementById("results").appendChild(result);
}
function morenames() {
var newnameli = document.createElement("li");
var newnamelabel = document.createElement("label");
newnamelabel.innerHTML = "Name: ";
var newname = document.createElement("input");
newname.type = "text";
newnamelabel.appendChild(newname);
newnameli.appendChild(newnamelabel);
document.getElementById("names").appendChild(newnameli);
}
</script>
</head>
<body>
<h1>I just want a fucking gift exchange name shuffler</h1>
<ul id="names">
<li>
<label>Name: <input type="text" value="Little Cindy Lou"/></label>
</li>
<li>
<label>Name: <input type="text" value="Max"/></label>
</li>
<li>
<label>Name: <input type="text" value="Grinch"/></label>
</li>
</ul>
<button onclick="morenames()">
More names, goddammit! I don't have some tiny shit family, idiot.
</button>
<button onclick="shufflethefuckingnames()">
Just shuffle the fucking names into pairs.
</button>
<div id="results"></div>
</body>
</html>