Skip to content

Instantly share code, notes, and snippets.

@jixunmoe jixunmoe/autokun.js
Last active Aug 29, 2015

Embed
What would you like to do?
llpractice.autokun.js
(function (window, document) {
if (!window.ga) window.ga = function () {};
function getContent (url, cbSuccess, cbFail) {
var req = new XMLHttpRequest();
req.open ('GET', url);
req.onload = cbSuccess && cbSuccess.bind(req);
req.onerror = cbFail && cbFail .bind(req);
req.send ();
};
var autoKun = function (st, et) {
if (Math.abs(st - currenttime) < 20) {
touchdown(i, st);
}
if (Math.abs(et - currenttime) < 20) {
touchup (i, et);
}
};
var sprintf = function (str) {
var params = [].slice.call(arguments, 1);
var l = params.length;
for (var i = 0; i < l; i++)
str = str.replace('%s', String(params[i]));
return str;
};
var key = 'currentdrawingnotes[i].length>0';
var begin = '{';
var end = 'catch(ex){}}';
var expose = ['resize'];
var endInject = function () {
var _tv = document.getElementById('touchview');
var _each = [].forEach;
var _resize = resize;
var toCopy = 'top,left,width,height'.split(',');
resize = function () {
_resize();
var tvs = document.getElementsByClassName('t-view');
_each.call(toCopy, function(s) {
var sv = _tv.style[s];
_each.call(tvs, function (v) {
v.style[s] = sv;
});
});
};
};
getContent('scripts/LLpractice.min.js', function () {
var src = this.responseText;
var exposeFix = '';
expose.map(function(v) {
exposeFix += sprintf('try{window.%s=%s;}catch(ex){console.error("expose %s failed!")}', v, v, v);
});
var mod = src
.replace(key, key + sprintf('&&(%s)(currentdrawingnotes[i][0].starttime,currentdrawingnotes[i][0].endtime)', autoKun))
.replace('START!', 'AUTO')
.replace(end, end + sprintf(';(%s)();%s', endInject, exposeFix));
// 削除以前的事件绑定
document.body.innerHTML = '<img src=play_effect.png style=display:none id=spriteImg><div id=maindiv class=overlaydiv><div class=overlaydiv><div id=bgimg></div></div><div class=overlaydiv></div><div class=overlaydiv><canvas id=maincanvas></canvas><div id=touchview><div class=test style=display:table;text-align:center;cursor:pointer><span id=indicator style=display:table-cell;vertical-align:middle></span></div></div><div id=result style=background-color:rgba(0,0,0,.46)><h2 id=live_name></h2><p id=maxcombo></p><p id=perfectc></p><p id=greatc></p><p id=goodc></p><p id=badc></p><p id=missc></p><p id=delayc></p><p id=offsetc></p><div style=height:50px onclick=location.reload()><h2>再来一次</h2></div></div><div id=back onclick=history.back() ontouchend=history.back()>Back</div></div><div class=overlaydiv style=pointer-events:none><div class=t-view><div style=position:absolute;right:0;margin-right:25%;margin-top:10%;><img src=http://r.loli.io/jMVfqi.png style=opacity:.7;width:50%;height:50%></div></div></div></div>';
// 默认字体改为 Ubuntu + 雅黑
document.body.style.fontFamily = 'Ubuntu,"Microsoft YaHei UI Light",sans-serif';
var moded = new Function(mod);
moded();
// 重新初始化
window.loadlive();
// 写入 UNRANKED 字样
var pp = document.getElementById('back').parentNode;
var autoMode = document.createElement('div');
autoMode.textContent = '== UNRANKED ==';
autoMode.setAttribute('style', 'font-size: 2em; margin-top: 0.5em; text-shadow: 0 0 4px wheat;');
pp.appendChild(autoMode);
});
})(window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.