2018 work :)
This commit is contained in:
parent
6ad707ddba
commit
48e55aafab
4 changed files with 197 additions and 40 deletions
|
@ -2,6 +2,7 @@ var SecretSanta = function () {
|
|||
|
||||
this.names = [];
|
||||
|
||||
this.enforced = Object.create( null );
|
||||
this.blacklists = Object.create( null );
|
||||
};
|
||||
|
||||
|
@ -15,6 +16,14 @@ SecretSanta.prototype.add = function ( name ) {
|
|||
|
||||
var subapi = { };
|
||||
|
||||
subapi.enforce = function ( other ) {
|
||||
|
||||
this.enforced[ name ] = other;
|
||||
|
||||
return subapi;
|
||||
|
||||
}.bind( this );
|
||||
|
||||
subapi.blacklist = function ( other ) {
|
||||
|
||||
if ( ! Object.prototype.hasOwnProperty.call( this.blacklists, name ) )
|
||||
|
@ -38,6 +47,25 @@ SecretSanta.prototype.generate = function () {
|
|||
|
||||
this.names.forEach( function ( name ) {
|
||||
|
||||
if ( Object.prototype.hasOwnProperty.call( this.enforced, name ) ) {
|
||||
|
||||
var enforced = this.enforced[ name ];
|
||||
|
||||
if ( this.names.indexOf( enforced ) === -1 )
|
||||
throw new Error( name + ' is paired with ' + enforced + ', which hasn\'t been declared as a possible pairing' );
|
||||
|
||||
Object.keys( pairings ).forEach( function ( name ) {
|
||||
|
||||
if ( pairings[ name ] === enforced ) {
|
||||
throw new Error( 'Per your rules, multiple persons are paired with ' + enforced );
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
pairings[ name ] = this.enforced[ name ];
|
||||
|
||||
} else {
|
||||
|
||||
var candidates = _.difference( this.names, [ name ] );
|
||||
|
||||
if ( Object.prototype.hasOwnProperty.call( this.blacklists, name ) )
|
||||
|
@ -45,6 +73,8 @@ SecretSanta.prototype.generate = function () {
|
|||
|
||||
candidatePairings[ name ] = candidates;
|
||||
|
||||
}
|
||||
|
||||
}, this );
|
||||
|
||||
var findNextGifter = function () {
|
||||
|
|
BIN
assets/snow.png
Normal file
BIN
assets/snow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
98
index.html
98
index.html
|
@ -152,16 +152,13 @@
|
|||
|
||||
<div class="main">
|
||||
|
||||
<div class="part">
|
||||
<div class="part" style="overflow-y: auto">
|
||||
<div class="instructions">
|
||||
<h1><img src="assets/mistletoe.png" style="vertical-align: middle" /> Secret Santa Generator</h1>
|
||||
<p>No signup, no email, no bullshit. Just a straightforward <a href="https://github.com/arcanis/secretsanta">open-source</a> tool to help you generate your secret santa pairings. Static page only.</p>
|
||||
<p>The DSL that is used to set the pairing rules is dead simple: in the most common use case (no special rule, pair each guest to another), you just have to enter the name of your guests, one line at a time. Once done, press "generate" and voilà, you will get a set of links that you will just have to give to each one of them (by mail, chat, whatever float your boat). Once they access the link, their pairing will be revealed (to them and only them).</p>
|
||||
<p>Should you have more complex needs (for example if you want to prevent a couple from being paired together, or want to prevent someone to be paired with someone else they don't know), just append <code>!<name></code> after a guest name, and he will never be paired with <code><name></code> (check on the right for an example).</p>
|
||||
<p>No signup, no email, no bullshit. Just a straightforward <a href="https://github.com/arcanis/secretsanta">open-source</a> tool to help you generate your secret santa pairings. One static page, and that's it.</p>
|
||||
<p>In the most common case (no exclusion rules, pair each guest with another at random), enter the name of your guests one line at a time. Once done, press "generate" and you're all set: send the generated links to your guests (by mail, chat, whatever floats your boat) and their pairing will be revealed to them (and only them) once they open the link.</p>
|
||||
<h2>Where does this tool come from?</h2>
|
||||
<p>I just wanted to make a Secret Santa over Facebook without giving up my guests email addresses to do so (so nothing that requires a backend). I also wanted to ignore who was paired with me, so I had to find a way to obfuscate it. And since I'm a developer, well, I just thought "Let's AES it, for fun and profits!". Classic.</p>
|
||||
<!-- <p>If you want to tip me, feel free to send me anything on the following Bitcoin address! I'll probably use it on some 3DS game (Fire Emblem, maybe?) :) Anyway, merry christmas!</p>
|
||||
<p><img src="assets/bitcoin.ico" style="vertical-align: middle" /> <a href="bitcoin:1HLgRVCGcXabWhMfdLazFVUWiH2W1kCDQK"><code>1HLgRVCGcXabWhMfdLazFVUWiH2W1kCDQK</code></a></p>-->
|
||||
<p>I wanted to make a Secret Santa over Facebook without having to reveal to anyone my guests email addresses (so nothing that would require a backend). I also wanted not to know who was paired with me, so I had to find a way to somehow obfuscate the information. And being a developer, well, my first thought was "Let's AES it, for fun and profits!". Classic.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -181,6 +178,13 @@
|
|||
Maël !Aurélie
|
||||
Aurélie !Maël
|
||||
|
||||
# You can also exclude someone from being paired with multiple people
|
||||
# Careful: too many exclusion rules can make your secret santa less interesting!
|
||||
Rudolph !Maël !Santa
|
||||
|
||||
# You can also cheat a bit and force someone to be paired with another
|
||||
Aurélie =Santa
|
||||
|
||||
...
|
||||
</script>
|
||||
|
||||
|
@ -188,13 +192,23 @@
|
|||
|
||||
<script>
|
||||
|
||||
function isAmazonEnabled() {
|
||||
|
||||
const checkBox = document.getElementById('amazon');
|
||||
|
||||
return checkBox ? checkBox.checked : false;
|
||||
|
||||
}
|
||||
|
||||
function persist() {
|
||||
|
||||
if ( ! window.localStorage )
|
||||
return ;
|
||||
|
||||
var amazon = isAmazonEnabled();
|
||||
var content = document.getElementById( 'input' ).value;
|
||||
|
||||
window.localStorage.setItem( 'amazon', amazon );
|
||||
window.localStorage.setItem( 'input', content );
|
||||
|
||||
}
|
||||
|
@ -204,7 +218,17 @@
|
|||
if ( ! window.localStorage )
|
||||
return ;
|
||||
|
||||
var content = window.localStorage.getItem( 'input' ) || '';
|
||||
var amazon = window.localStorage.getItem( 'amazon' );
|
||||
var content = window.localStorage.getItem( 'input' );
|
||||
|
||||
if (typeof amazon === 'undefined')
|
||||
amazon = true;
|
||||
|
||||
if (typeof content === 'undefined')
|
||||
content = '';
|
||||
|
||||
if ( document.getElementById( 'amazon' ) )
|
||||
document.getElementById( 'amazon' ).checked = amazon;
|
||||
|
||||
document.getElementById( 'input' ).value = content;
|
||||
|
||||
|
@ -270,6 +294,9 @@
|
|||
var pairingPath = window.location.pathname.replace( /[^/]+$/, '' ) + 'pairing.html';
|
||||
var pairingQueryString = '?name=' + encodeURIComponent( name ) + '&key=' + encodeURIComponent( key ) + '&pairing=' + encodeURIComponent( encryptedPairing );
|
||||
|
||||
if ( isAmazonEnabled() )
|
||||
pairingQueryString += '&extra=1';
|
||||
|
||||
tdName.innerText = name;
|
||||
|
||||
link.addEventListener( 'click', protect );
|
||||
|
@ -281,6 +308,26 @@
|
|||
|
||||
}
|
||||
|
||||
function updateAmazon() {
|
||||
|
||||
var result = document.getElementById( 'result' );
|
||||
var links = result.getElementsByTagName( 'a' );
|
||||
|
||||
for ( var t = 0; t < links.length; ++t ) {
|
||||
|
||||
var link = links[t];
|
||||
|
||||
if ( isAmazonEnabled() )
|
||||
link.href += '&extra=1';
|
||||
else
|
||||
link.href = link.href.replace( /&extra=[01]/, '' );
|
||||
|
||||
link.innerText = link.href;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function generate( e ) {
|
||||
|
||||
e.preventDefault();
|
||||
|
@ -302,11 +349,13 @@
|
|||
// Strip empty lines
|
||||
content = content.replace( /\n+/g, '\n' );
|
||||
|
||||
// Remove trailing newline
|
||||
content = content.replace( /\n$/, '' );
|
||||
// Remove leading/trailing newlines
|
||||
content = content.replace( /^\n|\n$/g, '' );
|
||||
|
||||
var lines = content.split( /\n/g );
|
||||
|
||||
console.log(lines);
|
||||
|
||||
if ( lines.length === 0 || lines.length === 1 && lines[ 0 ].length === 0 )
|
||||
return reset();
|
||||
|
||||
|
@ -314,18 +363,31 @@
|
|||
|
||||
for ( var t = 0, T = lines.length; t < T; ++ t ) {
|
||||
|
||||
var match = lines[ t ].match( /^([^ ]+)(?: ((?:![^ ]+)(?: ![^ ]+)*))?$/ );
|
||||
var match = lines[ t ].match( /^([^ ]+)((?: [!=][^ ]+)*)$/ );
|
||||
|
||||
if ( ! match )
|
||||
return error( 'Syntax error: "' + lines[ t ] + '" isn\'t a valid line' );
|
||||
return error( 'Syntax error: "' + lines[ t ] + '" isn\'t valid' );
|
||||
|
||||
var name = match[ 1 ];
|
||||
var exclusions = match[ 2 ] ? match[ 2 ].replace( /!/g, '' ).split( / /g ) : [];
|
||||
var rules = match[ 2 ] ? match[ 2 ].match(/[^ ]+/) : null;
|
||||
|
||||
var person = santa.add( name );
|
||||
|
||||
for ( var u = 0, U = exclusions.length; u < U; ++ u ) {
|
||||
person.blacklist( exclusions[ u ] );
|
||||
if (rules) {
|
||||
|
||||
for ( var u = 0, U = rules.length; u < U; ++ u ) {
|
||||
|
||||
var fnName = {
|
||||
|
||||
'=': 'enforce',
|
||||
'!': 'blacklist'
|
||||
|
||||
}[ rules[ u ].charAt( 0 ) ];
|
||||
|
||||
person[ fnName ]( rules[ u ].slice( 1 ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -355,6 +417,12 @@
|
|||
|
||||
document.getElementById( 'input' ).placeholder = document.getElementById( 'input-placeholder' ).innerHTML.trim().replace( /^[ \t]+/gm, '' );
|
||||
document.getElementById( 'input' ).addEventListener( 'change', persist );
|
||||
|
||||
if ( document.getElementById( 'amazon' ) ) {
|
||||
document.getElementById( 'amazon' ).addEventListener( 'change', updateAmazon );
|
||||
document.getElementById( 'amazon' ).addEventListener( 'change', persist );
|
||||
}
|
||||
|
||||
document.getElementById( 'form' ).addEventListener( 'submit', generate );
|
||||
|
||||
restore();
|
||||
|
|
89
pairing.html
89
pairing.html
|
@ -25,19 +25,71 @@
|
|||
}
|
||||
|
||||
body {
|
||||
background-image: url(assets/santa.png);
|
||||
background-position: bottom right;
|
||||
background-repeat: no-repeat;
|
||||
background: url(./assets/snow.png), url(./assets/santa.png), url(./assets/snow.png), radial-gradient(#FB3B3B, #EF3D3D);
|
||||
background-repeat: repeat, no-repeat, repeat, no-repeat;
|
||||
|
||||
animation-name: snow;
|
||||
animation-duration: 5s;
|
||||
animation-iteration-count: infinite;
|
||||
animation-timing-function: linear;
|
||||
|
||||
font-family: 'Comic Sans MS';
|
||||
}
|
||||
|
||||
@keyframes snow {
|
||||
from { background-position: 130px 40px, bottom right, 0 0, 0 0; }
|
||||
to { background-position: 130px 640px, bottom right, 0 300px, 0 0; }
|
||||
}
|
||||
|
||||
.spirit-of-christmas {
|
||||
display: block;
|
||||
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
|
||||
padding: 20px;
|
||||
|
||||
font-size: 10px;
|
||||
text-decoration: none;
|
||||
|
||||
color: #FFFFFF;
|
||||
}
|
||||
|
||||
.main {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.content {
|
||||
.background {
|
||||
position: absolute;
|
||||
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.wrapper {
|
||||
margin: auto;
|
||||
padding: 20px;
|
||||
|
||||
background: repeating-linear-gradient(
|
||||
45deg,
|
||||
#5CC48A,
|
||||
#5CC48A 30px,
|
||||
#FFFFFF 30px,
|
||||
#FFFFFF 60px,
|
||||
#EF3D3D 60px,
|
||||
#EF3D3D 90px,
|
||||
#FFFFFF 90px,
|
||||
#FFFFFF 120px
|
||||
);
|
||||
|
||||
box-shadow: 3px 3px 10px rgba(0, 0, 0, .5);
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 40px;
|
||||
|
||||
background: #ffffff;
|
||||
|
||||
text-align: center;
|
||||
}
|
||||
|
@ -54,10 +106,9 @@
|
|||
display: block;
|
||||
box-sizing: content-box;
|
||||
|
||||
margin-top: 70px;
|
||||
margin-top: 40px;
|
||||
|
||||
border: 10px solid #0CB50C;
|
||||
border-radius: 10px;
|
||||
border: none;
|
||||
|
||||
background: rgba(255, 255, 255, .7);
|
||||
}
|
||||
|
@ -68,7 +119,7 @@
|
|||
|
||||
</style>
|
||||
|
||||
<script>1
|
||||
<script>
|
||||
|
||||
var queryString = _.chain( location.search.slice( 1 ).split( /&/g ) )
|
||||
.map( function ( item ) { if ( item ) return item.split( /=/ ).map( function ( str ) { return decodeURIComponent( str ); } ); } )
|
||||
|
@ -85,21 +136,29 @@
|
|||
|
||||
<div class="main">
|
||||
|
||||
<div class="wrapper">
|
||||
<div class="content">
|
||||
|
||||
<h3 class="title">Hi <span id="name"></span>! You've been paired with</h3>
|
||||
<div class="title">Hi <span id="name"></span>! You've been paired with</div>
|
||||
<script>document.getElementById('name').innerText = name</script>
|
||||
|
||||
<h1 class="pairing"><span id="pairing"></span></h1>
|
||||
<div class="pairing"><span id="pairing"></span></div>
|
||||
<script>document.getElementById('pairing').innerText = pairing</script>
|
||||
|
||||
<h3 class="title">Good luck!</h3>
|
||||
<div class="title">Good luck!</div>
|
||||
|
||||
<script>
|
||||
if (queryString.extra) {
|
||||
document.write('<iframe class="affiliate" src="http://rcm-eu.amazon-adsystem.com/e/cm?t=secrsant02e-21&o=8&p=48&l=ur1&category=books&banner=10DQAXJ7D1D2VTXMR682&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" frameborder="0"></iframe>');
|
||||
}
|
||||
</script>
|
||||
|
||||
<!--
|
||||
<iframe class="affiliate" src="http://rcm-eu.amazon-adsystem.com/e/cm?t=secrsant02e-21&o=8&p=48&l=ur1&category=jeuxetjouets&banner=0HS03ACZ89HPK7F4F5G2&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" frameborder="0"></iframe>
|
||||
<iframe class="affiliate" src="http://rcm-eu.amazon-adsystem.com/e/cm?t=secrsant02e-21&o=8&p=48&l=ur1&category=books&banner=10DQAXJ7D1D2VTXMR682&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" frameborder="0"></iframe>
|
||||
-->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a href="http://arcanis.github.io/secretsanta/" class="spirit-of-christmas">
|
||||
Want to start your own Secret Santa with your friends? Click here to get started!
|
||||
</a>
|
||||
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in a new issue