Skip to content

Instantly share code, notes, and snippets.

@mr5z
Created December 26, 2023 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mr5z/c4afa1a184a3e541e75dd4dc62565ac5 to your computer and use it in GitHub Desktop.
Save mr5z/c4afa1a184a3e541e75dd4dc62565ac5 to your computer and use it in GitHub Desktop.
class SecretSong {
constructor(items) {
this.items = items || [];
this.lyrics = '';
this.itemsGiven = [];
}
init() {
let when = atob('T24gdGhl');
let verb = atob('ZGF5IG9mIENocmlzdG1hcyBteSB0cnVlIGxvdmUgc2VudCB0byBtZTo=');
const from = atob('ZG92ZXMsIGE='), to = atob('ZG92ZXMsIGFuZCBh');
for(let i = 1;i <= this.items.length; ++i) {
let num = i == 1 ? 'a' : i;
this.itemsGiven.unshift(num + ' ' + this.items[i - 1]);
let verse =
`${when} ${this.nth(i)} ${verb} ${this.itemsGiven.join(', ')}`;
this.lyrics += verse.replace(from, to) + '. ';
}
}
nth(n) {
let s = ['th', 'st', 'nd', 'rd'];
return n + (s[(n - 20) % 100] || s[n] || s[0]);
}
sing() {
console.log(this.lyrics);
var msg = new SpeechSynthesisUtterance();
msg.text = this.lyrics;
window.speechSynthesis.speak(msg);
}
}
const items = [
'cGFydHJpZGdlIGluIGEgcGVhciB0cmVl',
'dHVydGxlIGRvdmVz',
'ZnJlbmNoIGhlbnM=',
'Y2FsbGluZyBiaXJkcw==',
'Z29sZCByaW5ncw==',
'Z2Vlc2UgYS1sYXlpbmc=',
'c3dhbnMgYS1zd2ltbWluZw==',
'bWFpZHMgYS1taWxraW5n',
'bGFkaWVzIERhbmNpbmc=',
'bG9yZHMgYS1sZWFwaW5n',
'cGlwZXJzIHBpcGluZw==',
'ZHJ1bW1lcnMgZHJ1bW1pbmc='
];
const song = new SecretSong(items.map(atob));
song.init();
song.sing();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment