Skip to content

Instantly share code, notes, and snippets.

@dady8889
Created May 10, 2019 21:01
Show Gist options
  • Save dady8889/b3217868e0ae2cd88a1f9fb68caad548 to your computer and use it in GitHub Desktop.
Save dady8889/b3217868e0ae2cd88a1f9fb68caad548 to your computer and use it in GitHub Desktop.
MTGA Land Shuffler
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>MTGA Land Shuffler</title>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mouse0270-bootstrap-notify/3.1.7/bootstrap-notify.js" integrity="sha256-ZfyZUBGHlJunePNMsBqgGX3xHMv4kaCZ5Hj+8Txwd9c=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.0/animate.min.css" integrity="sha256-HtCCUh9Hkh//8U1OwcbD8epVEUdBvuI8wj1KtqMhNkI=" crossorigin="anonymous" />
<style>
#importArea {
height: 350px;
}
#wrapper {
min-height: 100vh;
padding: 5%;
}
video {
position: fixed;
top: 0;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
transform: translateX(calc((100% - 100vw) / 2));
z-index: -1;
}
</style>
<script>
let lands =
['Forest (DAR) 266',
'Forest (DAR) 267',
'Forest (DAR) 268',
'Forest (DAR) 269',
'Forest (GRN) 264',
'Forest (M19) 277',
'Forest (M19) 278',
'Forest (M19) 279',
'Forest (M19) 280',
'Forest (RIX) 196',
'Forest (RNA) 264',
'Forest (WAR) 262',
'Forest (WAR) 263',
'Forest (WAR) 264',
'Forest (XLN) 276',
'Forest (XLN) 277',
'Forest (XLN) 278',
'Forest (XLN) 279',
'Island (DAR) 254',
'Island (DAR) 255',
'Island (DAR) 256',
'Island (DAR) 257',
'Island (GRN) 261',
'Island (M19) 265',
'Island (M19) 266',
'Island (M19) 267',
'Island (M19) 268',
'Island (RIX) 193',
'Island (RNA) 261',
'Island (WAR) 253',
'Island (WAR) 254',
'Island (WAR) 255',
'Island (XLN) 264',
'Island (XLN) 265',
'Island (XLN) 266',
'Island (XLN) 267',
'Mountain (DAR) 262',
'Mountain (DAR) 263',
'Mountain (DAR) 264',
'Mountain (DAR) 265',
'Mountain (GRN) 263',
'Mountain (M19) 273',
'Mountain (M19) 274',
'Mountain (M19) 275',
'Mountain (M19) 276',
'Mountain (RIX) 195',
'Mountain (RNA) 263',
'Mountain (WAR) 259',
'Mountain (WAR) 260',
'Mountain (WAR) 261',
'Mountain (XLN) 272',
'Mountain (XLN) 273',
'Mountain (XLN) 274',
'Mountain (XLN) 275',
'Plains (DAR) 250',
'Plains (DAR) 251',
'Plains (DAR) 252',
'Plains (DAR) 253',
'Plains (GRN) 260',
'Plains (M19) 261',
'Plains (M19) 262',
'Plains (M19) 263',
'Plains (M19) 264',
'Plains (RIX) 192',
'Plains (RNA) 260',
'Plains (WAR) 250',
'Plains (WAR) 251',
'Plains (WAR) 252',
'Plains (XLN) 260',
'Plains (XLN) 261',
'Plains (XLN) 262',
'Plains (XLN) 263',
'Swamp (DAR) 258',
'Swamp (DAR) 259',
'Swamp (DAR) 260',
'Swamp (DAR) 261',
'Swamp (GRN) 262',
'Swamp (M19) 269',
'Swamp (M19) 270',
'Swamp (M19) 271',
'Swamp (M19) 272',
'Swamp (RIX) 194',
'Swamp (RNA) 262',
'Swamp (WAR) 256',
'Swamp (WAR) 257',
'Swamp (WAR) 258',
'Swamp (XLN) 268',
'Swamp (XLN) 269',
'Swamp (XLN) 270',
'Swamp (XLN) 271'];
let landsByColor = {};
let colors = [];
$.each(lands, function() {
let land = this;
let splitLand = land.split(' ');
let color = splitLand[0];
let identifier = splitLand[1] + ' ' + splitLand[2];
if (!landsByColor[color]) {
landsByColor[color] = [];
colors.push(color);
}
landsByColor[color].push(identifier);
});
$(document).ready(function() {
$('#importArea').on('input', function(e) {
if (e.target.value === '') {
$('#copyButton').attr('disabled', true);
} else {
$('#copyButton').attr('disabled', false);
}
});
$('#shuffleButton').click(function() {
let importArea = $('#importArea');
let newCardList = [];
if (importArea.val()) {
let lines = importArea.val().split('\n');
$.each(lines, function() {
let line = this;
let cardName = line.slice(line.indexOf(' ') + 1);
if ($.inArray(cardName, lands) != -1) {
let splitLand = line.split(' ');
let count = splitLand[0];
let color = splitLand[1];
for (let i = 0; i < count; i++) {
let randomIndex = Math.floor(Math.random() * landsByColor[color].length);
newCardList.push('1 ' + color + ' ' + landsByColor[color][randomIndex]);
}
//console.log(cardName);
} else if (line == "") {
//console.log('sideboard');
newCardList.push('');
} else {
newCardList.push(line);
}
});
importArea.val(newCardList.join('\n'));
}
});
$('#copyButton').click(function() {
$('#importArea').select();
document.execCommand('copy');
//$('#importArea').blur();
document.getSelection().removeAllRanges();
$.notify("Your deck has been copied into clipboard", {
animate: {
enter: 'animated bounceInDown',
exit: 'animated bounceOutUp'
},
placement: {
from: "top",
align: "center"
},
type: 'success',
delay: 1000,
allow_dismiss: false,
});
});
});
</script>
</head>
<body>
<div id="wrapper" class="d-flex flex-column justify-content-center align-items-center">
<textarea id="importArea" type="text" class="form-control" placeholder="Paste your deck here and click on shuffle..."></textarea>
<div class="d-flex w-100 mt-1">
<button id="shuffleButton" name="shuffleButton" type="button" class="btn btn-primary w-100 mr-1">Shuffle</button>
<button id="copyButton" name="copyButton" type="button" class="btn btn-success w-100 ml-1" disabled>Copy</button>
</div>
</div>
<video autoplay="autoplay" muted="muted" loop="loop" poster="https://media.wizards.com/2019/images/magic/war/AVS2efHWWj.jpg">
<source type="video/mp4" src="https://media.wizards.com/2019/images/magic/war/AVS2efHWWj.mp4" />
<img src="https://media.wizards.com/2019/images/magic/war/AVS2efHWWj.jpg" alt="" />
</video>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment