-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnomAléatoire.html
180 lines (152 loc) · 12.6 KB
/
nomAléatoire.html
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>RandomNamePicker</title>
<style>
button:not([disabled]){background:#f9c412;color:#181818}body{background:#181818;color:#eee;font-size:1.2rem;font-family:'Source sans pro',Tahoma,Geneva,sans-serif}button{cursor:pointer;display:inline-block;padding:.75em 1.5em;text-align:center;margin:5px;border-radius:.3em;max-width:100%;overflow:visible;font-size:20px;border:none;opacity:.8;transition:all .2s}button[disabled]{background:#e6e6e6;color:#404040;cursor:not-allowed}#namesInput{border:solid 1px gray;border-radius:5px;padding:5px;margin:5px;min-height:15ch}#namesInput:empty:before{content:attr(data-placeholder);color:gray}.winner{font-size:100px!important;text-shadow:2px 2px 2px #ba9005}.winner::before{content:'❱ ';color:#ba9005}.winner::after{content:' ❰';color:#ba9005}#container{margin:auto}#nameDisplay{font-size:60px;text-align:center;transition:font-size 2s,text-shadow 2s;white-space:nowrap;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}#controls{position:fixed;bottom:0}button#pick{background:#4caf50;color:#fff}button#kick{background:#aa624c;color:#fff}button:hover{box-shadow:0 0 0 2px #fff;opacity:1}
</style>
<script>!function(t,e){!function t(e,n,a,i){var o=!!(e.Worker&&e.Blob&&e.Promise&&e.OffscreenCanvas&&e.OffscreenCanvasRenderingContext2D&&e.HTMLCanvasElement&&e.HTMLCanvasElement.prototype.transferControlToOffscreen&&e.URL&&e.URL.createObjectURL);function r(){}function l(t){var a=n.exports.Promise,i=void 0!==a?a:e.Promise;return"function"==typeof i?new i(t):(t(r,r),null)}var c,s,u,d,f,h,g,m,b=(u=Math.floor(1e3/60),d={},f=0,"function"==typeof requestAnimationFrame&&"function"==typeof cancelAnimationFrame?(c=function(t){var e=Math.random();return d[e]=requestAnimationFrame((function n(a){f===a||f+u-1<a?(f=a,delete d[e],t()):d[e]=requestAnimationFrame(n)})),e},s=function(t){d[t]&&cancelAnimationFrame(d[t])}):(c=function(t){return setTimeout(t,u)},s=function(t){return clearTimeout(t)}),{frame:c,cancel:s}),v=(m={},function(){if(h)return h;if(!a&&o){var e=["var CONFETTI, SIZE = {}, module = {};","("+t.toString()+")(this, module, true, SIZE);","onmessage = function(msg) {"," if (msg.data.options) {"," CONFETTI(msg.data.options).then(function () {"," if (msg.data.callback) {"," postMessage({ callback: msg.data.callback });"," }"," });"," } else if (msg.data.reset) {"," CONFETTI.reset();"," } else if (msg.data.resize) {"," SIZE.width = msg.data.resize.width;"," SIZE.height = msg.data.resize.height;"," } else if (msg.data.canvas) {"," SIZE.width = msg.data.canvas.width;"," SIZE.height = msg.data.canvas.height;"," CONFETTI = module.exports.create(msg.data.canvas);"," }","}"].join("\n");try{h=new Worker(URL.createObjectURL(new Blob([e])))}catch(t){return void 0!==typeof console&&"function"==typeof console.warn&&console.warn("🎊 Could not load worker",t),null}!function(t){function e(e,n){t.postMessage({options:e||{},callback:n})}t.init=function(e){var n=e.transferControlToOffscreen();t.postMessage({canvas:n},[n])},t.fire=function(n,a,i){if(g)return e(n,null),g;var o=Math.random().toString(36).slice(2);return g=l((function(a){function r(e){e.data.callback===o&&(delete m[o],t.removeEventListener("message",r),g=null,i(),a())}t.addEventListener("message",r),e(n,o),m[o]=r.bind(null,{data:{callback:o}})}))},t.reset=function(){for(var e in t.postMessage({reset:!0}),m)m[e](),delete m[e]}}(h)}return h}),y={particleCount:50,angle:90,spread:45,startVelocity:45,decay:.9,gravity:1,drift:0,ticks:200,x:.5,y:.5,shapes:["square","circle"],zIndex:100,colors:["#26ccff","#a25afd","#ff5e7e","#88ff5a","#fcff42","#ffa62d","#ff36ff"],disableForReducedMotion:!1,scalar:1};function p(t,e,n){return function(t,e){return e?e(t):t}(t&&null!=t[e]?t[e]:y[e],n)}function M(t){return t<0?0:Math.floor(t)}function w(t){return parseInt(t,16)}function x(t){return t.map(C)}function C(t){var e=String(t).replace(/[^0-9a-f]/gi,"");return e.length<6&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),{r:w(e.substring(0,2)),g:w(e.substring(2,4)),b:w(e.substring(4,6))}}function k(t){t.width=document.documentElement.clientWidth,t.height=document.documentElement.clientHeight}function I(t){var e=t.getBoundingClientRect();t.width=e.width,t.height=e.height}function T(t,e,n,o,r){var c,s,u=e.slice(),d=t.getContext("2d"),f=l((function(e){function l(){c=s=null,d.clearRect(0,0,o.width,o.height),r(),e()}c=b.frame((function e(){!a||o.width===i.width&&o.height===i.height||(o.width=t.width=i.width,o.height=t.height=i.height),o.width||o.height||(n(t),o.width=t.width,o.height=t.height),d.clearRect(0,0,o.width,o.height),(u=u.filter((function(t){return function(t,e){e.x+=Math.cos(e.angle2D)*e.velocity+e.drift,e.y+=Math.sin(e.angle2D)*e.velocity+e.gravity,e.wobble+=.1,e.velocity*=e.decay,e.tiltAngle+=.1,e.tiltSin=Math.sin(e.tiltAngle),e.tiltCos=Math.cos(e.tiltAngle),e.random=Math.random()+5,e.wobbleX=e.x+10*e.scalar*Math.cos(e.wobble),e.wobbleY=e.y+10*e.scalar*Math.sin(e.wobble);var n=e.tick++/e.totalTicks,a=e.x+e.random*e.tiltCos,i=e.y+e.random*e.tiltSin,o=e.wobbleX+e.random*e.tiltCos,r=e.wobbleY+e.random*e.tiltSin;return t.fillStyle="rgba("+e.color.r+", "+e.color.g+", "+e.color.b+", "+(1-n)+")",t.beginPath(),"circle"===e.shape?t.ellipse?t.ellipse(e.x,e.y,Math.abs(o-a)*e.ovalScalar,Math.abs(r-i)*e.ovalScalar,Math.PI/10*e.wobble,0,2*Math.PI):function(t,e,n,a,i,o,r,l,c){t.save(),t.translate(e,n),t.rotate(o),t.scale(a,i),t.arc(0,0,1,r,l,c),t.restore()}(t,e.x,e.y,Math.abs(o-a)*e.ovalScalar,Math.abs(r-i)*e.ovalScalar,Math.PI/10*e.wobble,0,2*Math.PI):(t.moveTo(Math.floor(e.x),Math.floor(e.y)),t.lineTo(Math.floor(e.wobbleX),Math.floor(i)),t.lineTo(Math.floor(o),Math.floor(r)),t.lineTo(Math.floor(a),Math.floor(e.wobbleY))),t.closePath(),t.fill(),e.tick<e.totalTicks}(d,t)}))).length?c=b.frame(e):l()})),s=l}));return{addFettis:function(t){return u=u.concat(t),f},canvas:t,promise:f,reset:function(){c&&b.cancel(c),s&&s()}}}function E(t,n){var a,i=!t,r=!!p(n||{},"resize"),c=p(n,"disableForReducedMotion",Boolean),s=o&&!!p(n||{},"useWorker")?v():null,u=i?k:I,d=!(!t||!s)&&!!t.__confetti_initialized,f="function"==typeof matchMedia&&matchMedia("(prefers-reduced-motion)").matches;function h(e,n,i){for(var o,r,l,c,s,d=p(e,"particleCount",M),f=p(e,"angle",Number),h=p(e,"spread",Number),g=p(e,"startVelocity",Number),m=p(e,"decay",Number),b=p(e,"gravity",Number),v=p(e,"drift",Number),y=p(e,"colors",x),w=p(e,"ticks",Number),C=p(e,"shapes"),k=p(e,"scalar"),I=function(t){var e=p(t,"origin",Object);return e.x=p(e,"x",Number),e.y=p(e,"y",Number),e}(e),E=d,S=[],F=t.width*I.x,N=t.height*I.y;E--;)S.push((o={x:F,y:N,angle:f,spread:h,startVelocity:g,color:y[E%y.length],shape:C[(c=0,s=C.length,Math.floor(Math.random()*(s-c))+c)],ticks:w,decay:m,gravity:b,drift:v,scalar:k},r=void 0,l=void 0,r=o.angle*(Math.PI/180),l=o.spread*(Math.PI/180),{x:o.x,y:o.y,wobble:10*Math.random(),velocity:.5*o.startVelocity+Math.random()*o.startVelocity,angle2D:-r+(.5*l-Math.random()*l),tiltAngle:Math.random()*Math.PI,color:o.color,shape:o.shape,tick:0,totalTicks:o.ticks,decay:o.decay,drift:o.drift,random:Math.random()+5,tiltSin:0,tiltCos:0,wobbleX:0,wobbleY:0,gravity:3*o.gravity,ovalScalar:.6,scalar:o.scalar}));return a?a.addFettis(S):(a=T(t,S,u,n,i)).promise}function g(n){var o=c||p(n,"disableForReducedMotion",Boolean),g=p(n,"zIndex",Number);if(o&&f)return l((function(t){t()}));i&&a?t=a.canvas:i&&!t&&(t=function(t){var e=document.createElement("canvas");return e.style.position="fixed",e.style.top="0px",e.style.left="0px",e.style.pointerEvents="none",e.style.zIndex=t,e}(g),document.body.appendChild(t)),r&&!d&&u(t);var m={width:t.width,height:t.height};function b(){if(s){var e={getBoundingClientRect:function(){if(!i)return t.getBoundingClientRect()}};return u(e),void s.postMessage({resize:{width:e.width,height:e.height}})}m.width=m.height=null}function v(){a=null,r&&e.removeEventListener("resize",b),i&&t&&(document.body.removeChild(t),t=null,d=!1)}return s&&!d&&s.init(t),d=!0,s&&(t.__confetti_initialized=!0),r&&e.addEventListener("resize",b,!1),s?s.fire(n,m,v):h(n,m,v)}return g.reset=function(){s&&s.reset(),a&&a.reset()},g}n.exports=E(null,{useWorker:!0,resize:!0}),n.exports.create=E}(function(){return void 0!==t?t:"undefined"!=typeof self?self:this||{}}(),e,!1),t.confetti=e.exports}(window,{});</script>
</head>
<body>
<div id="container">
<div id="namesInput" contenteditable="true" data-placeholder="noms séparés par des virgules ou des sauts de ligne."></div>
<button id="validate">
✓
</button>
<div id="nameDisplay">?</div>
<div id="controls">
<button id="pick">
Choisir
</button>
<button id="kick">
Enlever
</button>
</div>
</div>
<script>
function keyBind(e){
if (e.keyCode == 115) {
e.preventDefault();
history.back();
}
}
document.addEventListener('keydown', keyBind);
var namesArray = [];
var i=0;
var pickButton = document.querySelector('button#pick');
pickButton.style.display='none';
var kickButton = document.querySelector('button#kick');
kickButton.style.display = 'none';
kickButton.addEventListener('click',kickWinner);
var validateButton = document.querySelector('#validate');
validateButton.addEventListener('click',validNames);
var nameDisplayDiv = document.querySelector('#nameDisplay');
var namesInputDiv = document.querySelector('#namesInput');
function init(){
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
if (urlParams.has('names')){
const urlNames = urlParams.get('names')
namesArray = urlNames.split(',');
goForPicking();
}
}
function goForPicking(){
namesInputDiv.style.display = 'none';
validateButton.style.display = 'none';
pickButton.style.display='revert';
pickButton.addEventListener('click',function(){pickOne(namesArray);});
}
function kickWinner(){
let winner = document.querySelector('#nameDisplay').innerHTML;
namesArray = namesArray.filter(e => e !== winner);
kickButton.style.display = 'none';
console.log({namesArray});
}
function validNames() {
var namesArray = document.querySelector('#namesInput').innerText.split(/\r|\n/);
namesArray = namesArray.filter(item => item);
urlParamsStr = namesArray.join().replaceAll(/[\u202F\u00A0\u2000\u2001\u2003]/g, " ").replaceAll(/ *.EME./g,'').replaceAll('\"','');
var newUrl = location.protocol + '//' + location.host + location.pathname + '?names=' + urlParamsStr;
window.location.href = newUrl;
goForPicking();
}
function pickOne(names) {
kickButton.style.display = 'none';
document.querySelector('#nameDisplay').classList.remove('winner');
pickButton.style.display='none';
names=shuffleArray(names);
var randTime = (Math.floor(Math.random() * 2000) + 1000);
var randTime1 = (Math.floor(Math.random() * 2000) + 1000);
var randTime2 = (Math.floor(Math.random() * 500) + 500);
var serie1 = setInterval(function(){displayNextName(names);}, 100);
setTimeout(function(){
clearInterval(serie1);
var serie2 = setInterval(function(){displayNextName(names);}, 200);
setTimeout(function(){
clearInterval(serie2);
var serie3 = setInterval(function(){displayNextName(names);}, 500);
setTimeout(function(){
clearInterval(serie3);
setTimeout(function(){dispWinner()},500);
},randTime2);
},randTime1);
}, randTime);
}
function shuffleArray(array){
var currentIndex = array.length, temporaryValue, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
function displayNextName(names){
nameDisplayDiv.innerText = names[i];
if (((i+1)) >= names.length){
i=0;
}else{
((i++));
}
}
function dispWinner() {
pickButton.style.display='revert';
kickButton.style.display = 'revert';
document.querySelector('#nameDisplay').classList.add('winner');
confetti({
particleCount: 200,
spread: 80,
origin: { y: 0.6 }
});
confetti({particleCount: 200,spread: 80,origin: { x: 0.8,y: 0.6 }});
setTimeout(function(){confetti({particleCount: 200,spread: 80,origin: { x: 0.2,y: 0.6 }})},500);
setTimeout(function(){confetti({particleCount: 200,spread: 80,origin: { x: 0.5,y: 0.6 }})},800);
setTimeout(function(){confetti({particleCount: 200,spread: 80,origin: { x: 0.8,y: 0.6 }})},1100);
var end = Date.now() + (5 * 1000);
// go Buckeyes!
(function frame() {
confetti({
particleCount: 2,
angle: 60,
spread: 55,
origin: { x: 0 },
});
confetti({
particleCount: 2,
angle: 120,
spread: 55,
origin: { x: 1 },
});
if (Date.now() < end) {
requestAnimationFrame(frame);
}
}());
}
init();
</script>
</body>
</html>