diff --git a/static/navneleg.js b/static/navneleg.js index 2f4cca9c..41e0bf1e 100644 --- a/static/navneleg.js +++ b/static/navneleg.js @@ -1,225 +1,158 @@ var navneleg_activated = false; -var YEAR = 2016; -function P(year, name) { - var age = (YEAR - 2000) - year; - var prefix = ['', 'g', 'b', 'o', 'to']; - if (age < prefix.length) return prefix[age] + name; - else return 't' + (age - 3) + 'o' + name; -} + function navneleg() { - if (navneleg_activated) return; - navneleg_activated = true; - - var aliases = { - "Alexandra Aldershaab Hou Olsen": ["webfar"], - "Amalie Louise Stokholm": ["fust"], - "Anders Grøn Stensgaard": ["grøn"], - "Andreas Bendix Nuppenau": ["funu"], - "Asbjørn Stensgaard Nielsen": ["funi"], - "Asger Holm Agergaard": ["fugr"], - "Astrid Christiansen": ["fuis"], - "Benedikte Sofie Werk": ["fubi"], - "Burmor": ["morten", "morten kaj", "morten kaj degnebolig", "burfar"], - "Camilla Ulbæk Pedersen": ['fuul', P(14, 'sekr')], - "Casper Grønne Christensen": ["grønne"], - "Christian Bonar Zeuthen": ["fuzu", "zeuthen"], - "Christian Engelbrecht Larsen": ["gris", "grisen"], - "Christina Gøttsche": ["gøttsche", "mullemus", "gotye"], - "Christina Moeslund Madsen": ["fuhr"], - "Daniel Holst Hviid": ["hviid", "minihahn", "mini-hahn", "mini hahn"], - "Emma Hillgaard": ['ælling 2'], - "Esben Bo Mahler": ["humanist esben", "humanist", "esben humaniora"], - "Frederik Brinck Truelsen": ["ålen"], - "Frederik Jerløv": ["furi"], - "Freja Frederikke Pinderup": ["fupi"], - "Hans Christian Tankred": ["hc"], - "Hans-Martin Hannibal Lauridsen": ["hannibal"], - "Henrik Knakkegaard Christensen": ["knakke", "kendrik", "kenrik"], - "Henrik Lund Mortensen": ["fuan"], - "Jacob Albæk Schnedler": ["fuco", P(14, 'nf')], - "Jakob Grünewald Hjørringgaard": ["gotye"], - "Jakob Rørsted Mosumgaard": [P(12, "sekr"), "fuan", "lokalemus"], - "Jakob Ørhøj": ["ørhøj"], - "Janne Højmark Mønster": [P(15, "sekr")], - "Jens Ager Sørensen": ["printer jens"], - "Johan Johannes Johannessen": ["3j", "triple j", "triple-j", "jjj"], - "Jonas Termansen": ["sortie", "sortiecat", "sortie@cs.au.dk", "sortie@maxsi.org"], - "Julie Thiim Gadeberg": ["fuji"], - "Kasper Lynderup Jensen": ["jomfru jensen"], - "Katrin Debes Kristensen": ["solmor"], - "Kenneth Lund Kjærgaard": ["smør", 'gris',], - "Klaus Skovgaard Olesen": ["kalus"], - "Knud Valdemar Trøllund Lassen": ["kv", 'knude', 'knude vertex'], - "Kristoffer Winge": [P(10, "pr"), "fuan", "winge", "vinge"], - "Lasse Ellegaard Jørgensen": ["nano-peter"], - "Lauge Hoyer": ["gefuit", "burløs"], - "Laura Patricia Kaplan": ["lokalemis","lokalemiss"], - "Mads Fabricius": [P(12, "cerm"), "trefuan"], - "Mai Olsen": ['3. mai'], - "Maija Bindzus": ['øko'], - "Maiken Haahr Hansen": [P(11, "vc"), "fuma", "mølle"], - "Malene Machon Pedersen": ["machon"], - "Marianne Ostenfeldt Mortensen": ["fumo"], - "Marie Louisa Tølbøll Berthelsen": ["marie louisa", "burmor"], - "Marie Ulsø": ["øko", "økomor", "kromutter", "ulsø"], - "Martin Sand": ["furt", P(14, 'form')], - "Mathias Dannesbo": ["fuhi", P(13, 'vc')], - "Mathias Jaquet Mavraganis": ["tform", "mavraganis", "tantra", P(14, 'kass')], - "Mathias Rav": [P(13, "form"), "rav", "webfar", "webtumling", "webbaby", 'webtween', 'webteen', 'webmathias', 'amber'], - "Mette Lysgaard Schulz": [P(13, "pr"), "metten", "koorbaby"], - "Mette Galsgaard Malle": ['biomalle', 'malle','øko the outlaw malle - crusher of lions'], - "Morten Henriksen Birk": ["birk", 'brik'], - "Morten Stockmarr Liljegren": ["blomsterpenis","kone-laura", "tform", "tutorform", "formand", "form"], - "Nguyen Thien Anh Ly": ["an", "anh", "ann"], - "Nick Bakkegaard": ["justin", "bieber", "justin bieber", "web", "webfar"], - "Niclas Spas Sørensen": ["spas"], - "Nikolai Houlberg Øllegaard": ["webfar"], - "Nikolaj Voetmann Bruun": ["bruun"], - "Oliver Emil Harritslev Christensen": ["fuet", 'efuit'], - "Per Næsby Høgfeldt": [P(15, "fuan")], - "Peter Lystlund Matzen": ["matzen", "grisefar"], - "Philip Tchernavskij": ["tchernavskij", "mini-sean", "mini sean", "minisean", "gefuit"], - "Rune Terp": ['sten', 'runesten'], - "Sabrina Tang Christensen": [P(11, "cerm")], - "Sandra Bleuenn Picard S Pedersen": ["fubs"], - "Sofie Filskov Hermansen": ['ælling 1'], - "Thomas Skovlund Hansen": ['fuve'], - "Tobias Svangtun Nowak": ['toby', 'fucktoby', '#fucktoby'], - "Tómas Bragi Reynisson": ["tomas"] - }; - - var tutorelements = document.getElementsByClassName('tutoraddress'); - var tutors = []; - for (var i = 0, l = tutorelements.length; i < l; ++i) { - var e = tutorelements[i]; - var name = e.getElementsByClassName('name')[0].innerHTML.replace(/^[ \t\n\r]+|[ \t\n\r]+$/g, ''); - var pic = e.getElementsByClassName('tutorpicture'); - if (pic.length == 0) continue; - pic = pic[0].src; - tutors.push({'name': name, 'pic': pic}); - } - - var remainingTutors; - var level = 1; - - var reset_tutors = function reset_tutors() { - remainingTutors = []; - for (var i = 0, l = tutors.length; i < l; ++i) { - remainingTutors.push(tutors[i]); - } - }; - - reset_tutors(); - - var arto = document.getElementById('arto'); - if (arto) document.body.appendChild(arto); - var content = document.getElementById('content'); - content.innerHTML = '

Navneleg<\/h1>\n'+ - '

<\/p>\n'+ - '

<\/p>\n' - ; - - if (arto) { - var container = document.getElementById('navneleg_container'); - arto.style.position = 'absolute'; - arto.style.left = arto.style.bottom = '5px'; - arto.style.opacity = '0.5'; - arto.style.display = 'none'; - container.appendChild(arto); - } - - var currentIdx; - var wins = 0, losses = 0, streak = 0; - - var stats = document.getElementById('navneleg_stats'); - var status = document.getElementById('navneleg_status'); - var pic = document.getElementById('navneleg_tutorpicture'); - var input = document.getElementById('navneleg_input'); - var submitButton = document.getElementById('navneleg_submit'); - - var plural = function plural(n, noun) { - if (n == 1) return n+" "+noun; - else return n+" "+noun+"e"; - }; - - var next_timer = null; - - var next_tutor = function next_tutor() { - next_timer = null; - currentIdx = Math.floor(Math.random()*remainingTutors.length); - var t = remainingTutors[currentIdx]; - pic.src = t.pic; - input.value = ''; - var statString = plural(wins, "korrekt")+", "+plural(losses, "forkert"); - if (streak > 1) { - statString += ", "+plural(streak, "korrekt")+" i streg"; + if (navneleg_activated) return; + + navneleg_activated = true; + + var tutorelements = document.getElementsByClassName('tutoraddress'); + var tutors = []; + + for (var i = 0, l = tutorelements.length; i < l; ++i) { + var tutor = tutorelements[i]; + var name = tutor.getElementsByClassName('name')[0].innerHTML.trim(); + var pic = tutor.getElementsByClassName('tutorpicture'); + var alias = name; + if (tutor.getElementsByClassName('nickname').length > 0) { + alias = tutor.getElementsByClassName('nickname')[0].innerHTML; + alias = alias.substr(1, alias.length - 2); + } + + if (pic.length !== 0) { + pic = pic[0].src; + tutors.push({'name': name, 'pic': pic, 'alias': alias}); + } } - stats.innerHTML = statString; - var levelText = (level == 1) ? "" : (" (level "+level+")"); + + var remainingTutors; + var level = 1; + + var reset_tutors = function reset_tutors() { + remainingTutors = []; + tutors.forEach(tutor => remainingTutors.push(tutor)); + }; + + reset_tutors(); + + var arto = document.getElementById('arto'); + if (arto) document.body.appendChild(arto); + var content = document.getElementById('content'); + content.innerHTML = '

Navneleg<\/h1>\n' + + '

<\/p>\n' + + '

<\/p>\n' + ; + if (arto) { - arto.style.display = (level == 1) ? "none" : ""; - } - document.title = "Navneleg"+levelText+"! "+wins+"/"+losses+" ("+streak+")"; - status.innerHTML = "Hvem er følgende tutor? Indtast fornavnet eller et kendt kaldenavn."; - input.focus(); - }; - - var clear_next_timer = function clear_next_timer() { - if (next_timer) { - clearTimeout(next_timer); - next_timer = null; - } - }; - var set_next_timer = function set_next_timer() { - clear_next_timer(); - next_timer = setTimeout(next_tutor, 2000); - }; - var submit = function submit() { - var fullName = remainingTutors[currentIdx].name; - var currentName = remainingTutors[currentIdx].name.replace(/ .*/, ''); - var als = aliases[fullName] ? aliases[fullName] : []; - var guess = input.value.toLowerCase(); - if (guess == currentName.toLowerCase() || als.indexOf(guess) != -1) { - status.innerHTML = "Korrekt! Det fulde navn er "+remainingTutors[currentIdx].name+"."; - remainingTutors.splice(currentIdx, 1); - if (remainingTutors.length == 0) { - reset_tutors(); - ++level; - status.innerHTML = "Welcome to experience level "+level+"."; - } - ++wins; - ++streak; - } else if (guess == 'jeppe' || guess == 'henrijeppe') { - status.innerHTML = "Korrekt! Ish..."; - } else { - status.innerHTML = "Nej, det var "+remainingTutors[currentIdx].name+"."; - ++losses; - streak = 0; + var container = document.getElementById('navneleg_container'); + arto.style.position = 'absolute'; + arto.style.left = arto.style.bottom = '5px'; + arto.style.opacity = '0.5'; + arto.style.display = 'none'; + container.appendChild(arto); } - set_next_timer(); - }; - submitButton.onclick = submit; - next_tutor(); - - var input_key_down = function input_key_down(e) { - if (next_timer == null && e.keyCode == 13) { - submit(); - } - e.stopPropagation(); - }; - input.onkeydown = input_key_down; + + var currentIdx; + var wins = 0, losses = 0, streak = 0; + + var stats = document.getElementById('navneleg_stats'); + var status = document.getElementById('navneleg_status'); + var pic = document.getElementById('navneleg_tutorpicture'); + var input = document.getElementById('navneleg_input'); + var submitButton = document.getElementById('navneleg_submit'); + + var plural = function plural(n, noun) { + if (n == 1) return n + " " + noun; + else return n + " " + noun + "e"; + }; + + var next_timer = null; + + var next_tutor = function next_tutor() { + next_timer = null; + currentIdx = Math.floor(Math.random() * remainingTutors.length); + var t = remainingTutors[currentIdx]; + pic.src = t.pic; + input.value = ''; + var statString = plural(wins, "korrekt") + ", " + plural(losses, "forkert"); + if (streak > 1) { + statString += ", " + plural(streak, "korrekt") + " i streg"; + } + stats.innerHTML = statString; + var levelText = (level == 1) ? "" : (" (level " + level + ")"); + if (arto) { + arto.style.display = (level == 1) ? "none" : ""; + } + document.title = "Navneleg" + levelText + "! " + wins + "/" + losses + " (" + streak + ")"; + status.innerHTML = "Hvem er følgende tutor? Indtast fornavnet eller et kendt kaldenavn."; + input.focus(); + }; + + var clear_next_timer = function clear_next_timer() { + if (next_timer) { + clearTimeout(next_timer); + next_timer = null; + } + }; + + var set_next_timer = function set_next_timer() { + clear_next_timer(); + next_timer = setTimeout(next_tutor, 2000); + }; + + var submit = function submit() { + var fullName = remainingTutors[currentIdx].name; + var currentName = remainingTutors[currentIdx].name.replace(/ .*/, ''); + var als = remainingTutors[currentIdx].alias; + var guess = input.value.toLowerCase(); + + switch (guess) { + case currentName.toLowerCase(): + case als.toLowerCase(): + status.innerHTML = "Korrekt! Det fulde navn er " + fullName + + (als.toLowerCase() === fullName.toLowerCase() ? "." : " og kaldenavn er " + als + "."); + remainingTutors.splice(currentIdx, 1); + if (remainingTutors.length === 0) { + reset_tutors(); + ++level; + status.innerHTML = "Welcome to experience level " + level + "."; + } + ++wins; + ++streak; + break; + case 'jeppe' || 'henrijeppe': + status.innerHTML = "Korrekt! Ish..."; + break; + default: + status.innerHTML = "Nej, det var " + fullName + + (als.toLowerCase() === fullName.toLowerCase() ? "." : " og kaldenavn er " + als + "."); + ++losses; + streak = 0; + } + set_next_timer(); + }; + submitButton.onclick = submit; + next_tutor(); + + input.onkeydown = function (e) { + if (next_timer == null && e.keyCode === 13) { + submit(); + } + e.stopPropagation(); + }; } function win_key_down(e) { - if (!e) e = window.event; - if (e.keyCode == 78) { - navneleg(); - e.preventDefault(); - return false; - } - return true; + if (!e) e = window.event; + if (e.keyCode === 78) { + navneleg(); + e.preventDefault(); + return false; + } + return true; } + window.addEventListener('keydown', win_key_down, false); diff --git a/static/navneleg.min.js b/static/navneleg.min.js new file mode 100644 index 00000000..b46200b4 --- /dev/null +++ b/static/navneleg.min.js @@ -0,0 +1 @@ +var navneleg_activated=!1;function navneleg(){if(!navneleg_activated){navneleg_activated=!0;for(var e,n=document.getElementsByClassName("tutoraddress"),t=[],a=0,l=n.length;a0&&(s=(s=o.getElementsByClassName("nickname")[0].innerHTML).substr(1,s.length-2)),0!==i.length&&(i=i[0].src,t.push({name:r,pic:i,alias:s}))}var d=1,u=function(){e=[],t.forEach(n=>e.push(n))};u();var v,c=document.getElementById("arto");if(c&&document.body.appendChild(c),document.getElementById("content").innerHTML='

Navneleg

\n\n\n\n

\n

\n',c){var g=document.getElementById("navneleg_container");c.style.position="absolute",c.style.left=c.style.bottom="5px",c.style.opacity="0.5",c.style.display="none",g.appendChild(c)}var m=0,p=0,y=0,h=document.getElementById("navneleg_stats"),k=document.getElementById("navneleg_status"),f=(i=document.getElementById("navneleg_tutorpicture"),document.getElementById("navneleg_input")),w=document.getElementById("navneleg_submit"),_=function(e,n){return 1==e?e+" "+n:e+" "+n+"e"},L=null,C=function(){L=null,v=Math.floor(Math.random()*e.length);var n=e[v];i.src=n.pic,f.value="";var t=_(m,"korrekt")+", "+_(p,"forkert");y>1&&(t+=", "+_(y,"korrekt")+" i streg"),h.innerHTML=t;var a=1==d?"":" (level "+d+")";c&&(c.style.display=1==d?"none":""),document.title="Navneleg"+a+"! "+m+"/"+p+" ("+y+")",k.innerHTML="Hvem er følgende tutor? Indtast fornavnet eller et kendt kaldenavn.",f.focus()},E=function(){L&&(clearTimeout(L),L=null),L=setTimeout(C,2e3)},B=function(){var n=e[v].name,t=e[v].name.replace(/ .*/,""),a=e[v].alias;switch(f.value.toLowerCase()){case t.toLowerCase():case a.toLowerCase():k.innerHTML="Korrekt! Det fulde navn er "+n+(a.toLowerCase()===n.toLowerCase()?".":" og kaldenavn er "+a+"."),e.splice(v,1),0===e.length&&(u(),++d,k.innerHTML="Welcome to experience level "+d+"."),++m,++y;break;case"jeppe":k.innerHTML="Korrekt! Ish...";break;default:k.innerHTML="Nej, det var "+n+(a.toLowerCase()===n.toLowerCase()?".":" og kaldenavn er "+a+"."),++p,y=0}E()};w.onclick=B,C(),f.onkeydown=function(e){null==L&&13===e.keyCode&&B(),e.stopPropagation()}}}function win_key_down(e){return e||(e=window.event),78!==e.keyCode||(navneleg(),e.preventDefault(),!1)}window.addEventListener("keydown",win_key_down,!1); \ No newline at end of file