8月20日,阿里校园招聘前端岗位的在线笔试将统一开始。在这之前,我们先玩一下热身赛吧! http://t.cn/zQRFjtd 截至8月18日11:00之前成功通关并且表现优异的同学,将有机会收到我们的惊喜邮件!
以上是阿里巴巴集团校园招聘的某一条微博的内容。
我虽然看到了美女,但不知道那是不是 true ending。即使如此,我也将我的解题方法公布出来。
其实每题都可以在 console 中用 JavaScript 代码来解决,下面就是除了猜图之外的执行代码。
location.href = Base64.decode( document.getElementById("page").getAttribute("data-t") );
(function() {
var pharaoh = getNode("pharaoh");
var sacrifice = getNode("sacrifice");
var sacrificeCoord = getDotCoord( sacrifice );
ejaculate();
// 射出
function ejaculate() {
var mirrors = document.getElementsByClassName( "mirror" );
[].forEach.call( mirrors, magicMirror );
}
// 镜子魔法
function magicMirror( mirror ) {
setCssStyle( mirror, mirrorStyles( mirror ) );
}
// 镜子样式
function mirrorStyles( mirror ) {
var id = mirror.id;
var position = mirrorPosition( id );
return {
"webkitTransformOrigin": "50% 0 0",
"webkitTransform": "rotate(" + (id === "ma" ? -67.5 : 180) + "deg)",
"left": position.left,
"top": position.top
}
}
// 镜子位置
function mirrorPosition( id ) {
var position;
if ( id === "ma" ) {
position = getMaCoord();
}
else {
position = getMbCoord();
}
return position;
}
// 通过 id 获取节点
function getNode( id ) {
return document.getElementById( id );
}
// 获取样式
function getCssStyle( node, ruleKey ) {
return getComputedStyle(node, null)[ruleKey];
}
// 设置样式
function setCssStyle( node, rules ) {
for ( var key in rules ) {
node.style[ key ] = rules[key];
}
}
// 获取黑点坐标
function getDotCoord( node ) {
return {
x: parseFloat( getCssStyle(node, "left") ) + parseFloat( getCssStyle(node, "width") )/2,
y: parseFloat( getCssStyle(node, "top") ) + parseFloat( getCssStyle(node, "height") )/2
};
}
// 计算 ma 镜子的图形中心坐标
function getMaCoord() {
var mirror = getNode("ma");
var light = getNode("source");
var coord_y = parseFloat( getCssStyle(light, "top") ) + parseFloat( getCssStyle(light, "height") )/2;
var dot2ray = coord_y - sacrificeCoord.y;
return {
left: sacrificeCoord.x + dot2ray - parseFloat( getCssStyle(mirror, "width") )/2 + "px",
top: coord_y + "px"
};
}
// 计算 mb 镜子的图形中心坐标
function getMbCoord() {
var pharaohCoord = getDotCoord( pharaoh );
var mirror = getNode( "mb" );
var dot2dot = (sacrificeCoord.x - pharaohCoord.x)/2;
var coor_x = pharaohCoord.x + dot2dot - parseFloat(getCssStyle(mirror, "width"))/2;
return {
left: coor_x + "px",
top: pharaohCoord.y - dot2dot + "px"
};
}
})();
(function() {
var qrdata = getQrData().split(" ");
var ctx = document.getElementById("qr-canvas").getContext("2d");
qrdata.forEach(function( code ) {
ctx.fillRect.apply( ctx, code.split( "," ) );
});
function getQrData() {
var data;
[].forEach.call(document.body.childNodes, function( node ) {
if ( node.nodeType === document.COMMENT_NODE ) {
data = node.data.replace(/\r|\n/g, "");
}
});
return data;
}
})();
(function( $ ) {
var currentRoom = $("#next-room").text();
var stack = [currentRoom];
trace( currentRoom );
function trace( room ) {
$.ajax({
url: location.pathname + location.search.replace(/room\=\d+/, function() {
return "room=" + room;
}),
dataType: "html",
success: function( res ) {
var nextRoom = $("#next-room", $(res)).text();
if ( nextRoom !== "" ) {
stack.push( $("#message", $(res)).text() );
console.log( "正在进入第 " + nextRoom + " 号房间..." );
setTimeout(function() {
trace( nextRoom );
}, 3000);
}
else {
var url = quizUrl();
console.log( "已经取得通往西天的地址 " + url + ",5 秒后前往西天!" );
setTimeout(function() {
location.href = url;
}, 5000);
}
}
});
}
function quizUrl() {
var str = stack.join("");
return str.substring( str.indexOf("/quiz") );
}
})(jQuery);
var c = document.getElementById('qr-canvas').getContext('2d');
var s= "请自行复制源码中一大段注释中的数字字符串";
var a=s.split(' ');
alert(a.length);
for(i=0;i<a.length;i++){
var b=a[i].split(',');
c.fillRect(b[0],b[1],b[2],b[3]);
}