-
Notifications
You must be signed in to change notification settings - Fork 3
/
bookmarklet.js
1 lines (1 loc) · 4.8 KB
/
bookmarklet.js
1
javascript:!function(a,b){"use strict";function c(){}function d(a){return"HS-namegame-"+a}function e(a,b){return'<div class="'+d(a)+'">'+(b||"")+"</div>"}function f(a,c){return b(e.apply(this,arguments)).css(l[a]||{})}function g(a){var b,c,d,e=a.length;if(0===e)return!1;for(;--e;)b=Math.floor(Math.random()*(e+1)),c=a[e],d=a[b],a[e]=d,a[b]=c;return a}function h(){p.detach(),w.detach(),v.detach(),o.detach(),n.append(o).append(s)}function i(){s.detach(),v.detach(),n.append(p).append(w)}function j(){function a(){A={},q.find("input:checked").each(function(){A[b(this).val()]=!0});for(var a in z)if(A.hasOwnProperty(a))for(var c in z[a]){var d=z[a][c].right-z[a][c].wrong;z[a].hasOwnProperty(c)&&3>d&&(n[c]=z[a][c],p.push(c))}g(p)}function c(){for(var b in z)if(A.hasOwnProperty(b))for(var c in z[b])z[b][c].right=0,z[b][c].wrong=0;k.setItem("HS",JSON.stringify(z)),a(),h(),e(),y.detach(),r.detach()}function e(){var a=[],c=[],h=Math.min(4,p.length);!function(){if(C={pic:null,name:null},D=[],1>h)return m();for(var d=0;h>d;d++){var e=p[d];a.push('<img src="'+n[e].pic+'" />'),c.push(f("name",e))}g(a),g(c);for(var d=0;h>d;d++)t.append(b(a[d]).css(l.pic)),u.append(c[d])}(),t.find("img").click(function(a){C.pic=b(this).attr("src"),C.$pic=b(this),null===C.name&&t.find("img").css("opacity",1).not(b(this)).fadeTo(250,.2),i()}),u.find("div."+d("name")).click(function(a){C.name=b(this).html(),C.$name=b(this),null===C.pic&&u.find("div."+d("name")).css("opacity",1).not(b(this)).fadeTo(250,.2),i()}),x.unbind("click").click(function(){t.children().detach(),u.children().detach(),x.detach(),e()})}function i(){return null===C.pic||null===C.name?!1:(C.$pic.detach(),C.$name.detach(),D.push(C),C={pic:null,name:null},t.find("img").add(u.find("div")).css("opacity",1),1===t.find("img").length?(C={pic:t.find("img").attr("src"),$pic:t.find("img"),name:u.find("div."+d("name")).html(),$name:u.find("div."+d("name"))},i(C)):t.find("img").length?!0:j())}function j(){for(var a=0,b=D.length;b>a;a++){if(n[D[a].name].pic===D[a].pic)n[D[a].name].right++,D[a].win=!0,t.append(f("correct").append(D[a].$pic).append(D[a].$name.prepend("✔ ")));else{n[D[a].name].wrong++,D[a].win=!1;for(var c,d=0;b>d;d++)D[a].pic===n[D[d].name].pic&&(c=D[d].$name.clone());t.append(f("incorrect").append('<img src="'+n[D[a].name].pic+'" />').append(c.prepend("✖ ").css(l.wrongName)).append(D[a].$name))}B.push(D[a])}for(;a--;)p.shift();s.append(x)}function m(){for(var a=0,b=0,c=B.length;c>b;b++)B[b].win&&a++;o.detach();var d=B.length?"<h2>You got "+a+" right and "+(B.length-a)+" wrong.</h2>":"<h1>CONGRATULATIONS!</h1><h2>You know everybody in the selected batches.</h2>";s.append(v.html(d)),B.length<1?s.append(r).append(y):s.append(w),k.setItem("HS",JSON.stringify(z))}var n={},p=[],A={},B=[],C={pic:null,name:null},D=[];y.click(c),a(),e()}b("a.batch-emails").remove();var k="undefined"==typeof localStorage?{getItem:c,setItem:c,removeItem:c}:localStorage,l={container:{background:"rgba(0,0,0,1)",position:"absolute",top:0,left:0,width:b(document).width(),height:b(document).height()},mainPage:{width:"600px",background:"#fff",margin:"20px auto",padding:"10px 50px 50px","border-radius":"5px"},batchCheckboxes:{margin:"10px 0"},board:{display:"table","font-size":"13px"},pics:{margin:"20px 0 0"},pic:{width:"150px",height:"150px"},name:{border:"1px solid #aaa",background:"#eee",cursor:"pointer","text-align":"center","font-size":"14px",padding:"3px 0"},nextButton:{display:"block",position:"relative",bottom:0},correct:{"float":"left",background:"#00e837"},incorrect:{"float":"left",background:"#ed4044"},wrongName:{"text-decoration":"line-through"}},m=f("container"),n=f("mainPage").appendTo(m),o=f("title","<h1>Learn Your Hackers!</h1>").appendTo(n),p=f("startContent").appendTo(n),q=b('<ul class="'+d("batchCheckboxes")+'"></ul>').css(l.batchCheckboxes).appendTo(p),r=b('<input type="submit" value="select different batches" />').css(l.nextButton),s=f("board"),t=f("pics").appendTo(s),u=f("names").appendTo(s).css("clear","both"),v=f("scorecard"),w=b('<input type="submit" value="start game" />').appendTo(p),x=b('<input type="submit" value="next" />').css(l.nextButton),y=b('<input type="submit" value="reset" />').css(l.nextButton),z=a.HS=JSON.parse(k.getItem("HS"))||{};b("#batches").children().each(function(){var a=b("ul",this).first(),c=a.prev().html();q.append('<li><input type="checkbox" name="batch" value="'+c+'" /><label>'+c+"</label></li>");var d=z[c]=z[c]||{};b("li.person",a).each(function(){var a=b(".name a",this).html();d[a]=d[a]||{pic:b("img",this).attr("src"),right:0,wrong:0}})}),q.find("input").first().click(),m.hide().appendTo(b("body")).fadeTo(250,1),w.click(h).click(j).click(function(){w.unbind("click",j)}),r.click(i),b(document).on("keydown",function A(a){27===a.which&&m.fadeTo(250,0,function(){b(this).remove(),b(document).off("keydown",A)})}),b("html,body").animate({scrollTop:0},250)}(window,jQuery);