Skip to content

Instantly share code, notes, and snippets.

@zyzsdy
Created December 7, 2015 13:40
Show Gist options
  • Save zyzsdy/0315678fb4380123d970 to your computer and use it in GitHub Desktop.
Save zyzsdy/0315678fb4380123d970 to your computer and use it in GitHub Desktop.
grunt极速教程配套代码。
/* global mw */
//Widget:BilibiliMoe/Today
window.RLQ = window.RLQ || [];
window.RLQ.push(function() {
mw.loader.implement('widgetBilibiliMoeToday', function($, jQuery) {
if (window.navigator.userAgent.toLowerCase().indexOf('mobile') != -1) $('#BilibiliMoe').text('移动端不支持实时获取战绩,请到官网查看!');
else {
var self = $('#BilibiliMoe'),
femaleTable = self.find('.female table'),
maleTable = self.find('.male table'),
errorFun = function(XHR, eT, eO) {
if (eT) self.text('实时战绩获取出错,请刷新页面喵!(' + eT + ')');
else self.text('实时战绩获取出错,请刷新页面喵!');
},
date = new Date(),
dateY = new Date();
date.setTime(date.getTime() + (8 * 60 + date.getTimezoneOffset()) * 60 * 1000); //China Standard Time UT+8:00
dateY.setTime(date.getTime() - 24 * 60 * 60 * 1000);
$.ajax({
url: 'https://annangela.moe/MoegirlPedia/BilibiliMoe.php?type=ScheduleState&callback=?&date=' + dateY.getFullYear() + '-' + (dateY.getMonth() + 1) + (dateY.getDate() < 10 ? '-0' : '-') + dateY.getDate(),
type: 'GET',
dataType: 'jsonp',
success: function(data) {
var status = data.scheduleState.status,
gameName = data.scheduleState.sname;
self.find('.BilibiliMoeGameIntroduce .yesterday').html(status == '休息日' ? '昨日是休息日!' : '昨日进行的是' + gameName + ',请访问<a href="/Bilibili_2015%E5%8A%A8%E7%94%BB%E8%A7%92%E8%89%B2%E4%BA%BA%E6%B0%94%E5%A4%A7%E8%B5%8F/%E6%98%A8%E6%97%A5%E6%88%98%E5%86%B5" title="Bilibili 2015动画角色人气大赏/昨日战况">昨日战况</a>了解详情!');
},
timeout: 71300
});
$.ajax({
url: 'https://annangela.moe/MoegirlPedia/BilibiliMoe.php?type=Result&callback=?&date=' + date.getFullYear() + '-' + (date.getMonth() + 1) + (date.getDate() < 10 ? '-0' : '-') + date.getDate(),
type: 'GET',
dataType: 'jsonp',
error: errorFun,
success: function(data) {
if (typeof data == 'string') return errorFun({}, data);
if (String(data.state)[0] != '2') return errorFun({}, data.state || '-1');
var compare = function(a, b) {
return Number(a.votes_count) < Number(b.votes_count) ? 1 : -1;
},
addLine = function(s, r, siu, n, b, no, v) {
s.append('<tr><td>' + r + '</td><td data-imgsrc="' + siu + '"><div>' + n + '</div></td><td>' + b + '</td><td>' + (parseInt(no) + 1) + (vote_flag ? '</td><td>' + v + '</td></tr>' : '</td></tr>'));
},
status = data.scheduleState.status,
gameName = data.scheduleState.sname,
femaleArray = [],
maleArray = [],
vote_flag = false,
time = data.time,
length, temp, index, text, keys;
if (status == '休息日') {
self.find('.BilibiliMoeGameIntroduce .today').text('今日是休息日!');
self.find('.BilibiliMoe').css('text-align', 'center').text('无结果');
} else {
keys = Object.keys(data.data);
length = keys.length
for (index = 0; index < length; index++) data.data[keys[index]][0].sex == '1' ? maleArray = data.data[keys[index]] : femaleArray = data.data[keys[index]];
maleArray.sort(compare);
femaleArray.sort(compare);
text = '今日的比赛是<span style="font-weight: bold;margin: 0 7px;">' + gameName + '(' + status + ')</span>[' + time + ']';
if (status != '进行中' || mw.config.values.wgUserGroups.indexOf('sysop') + mw.config.values.wgUserGroups.indexOf('patroller') > -2) {
self.find('.thead').append('<th>票数</th>');
vote_flag = true;
} else text += '<br />(根据大赛规则,本页面不提供实时票数显示,只显示实时排名,请在深夜11:00后再次访问本页面以查看总票数或到<a rel="nofollow" target="_blank" class="external text" href="http://bilibili.com/html/moe2015-vote.html">官网投票</a>后查看,感谢你的理解!)';
self.find('.BilibiliMoeGameIntroduce .today').html(text);
length = femaleArray.length;
for (index = 0; index < length; index++) {
temp = femaleArray[index];
addLine(femaleTable, index + 1, temp.small_image_url, temp.name, temp.bangumi, temp.rank, temp.votes_count);
}
length = maleArray.length;
for (index = 0; index < length; index++) {
temp = maleArray[index];
addLine(maleTable, index + 1, temp.small_image_url, temp.name, temp.bangumi, temp.rank, temp.votes_count);
}
}
$(window).bind('load', function() {
self.find('td[data-imgsrc]').each(function() {
$(this).prepend($('<img/>', {
attr: {
src: $(this).attr('data-imgsrc')
},
css: {
width: '100px',
height: '100px'
}
}));
});
});
},
complete: function() {
self.attr('class', 'loaded');
},
timeout: 71300
});
}
});
});
window.RLQ=window.RLQ||[],window.RLQ.push(function(){mw.loader.implement("widgetBilibiliMoeToday",function(a,b){if(-1!=window.navigator.userAgent.toLowerCase().indexOf("mobile"))a("#BilibiliMoe").text("移动端不支持实时获取战绩,请到官网查看!");else{var c=a("#BilibiliMoe"),d=c.find(".female table"),e=c.find(".male table"),f=function(a,b,d){b?c.text("实时战绩获取出错,请刷新页面喵!("+b+")"):c.text("实时战绩获取出错,请刷新页面喵!")},g=new Date,h=new Date;g.setTime(g.getTime()+60*(480+g.getTimezoneOffset())*1e3),h.setTime(g.getTime()-864e5),a.ajax({url:"https://annangela.moe/MoegirlPedia/BilibiliMoe.php?type=ScheduleState&callback=?&date="+h.getFullYear()+"-"+(h.getMonth()+1)+(h.getDate()<10?"-0":"-")+h.getDate(),type:"GET",dataType:"jsonp",success:function(a){var b=a.scheduleState.status,d=a.scheduleState.sname;c.find(".BilibiliMoeGameIntroduce .yesterday").html("休息日"==b?"昨日是休息日!":"昨日进行的是"+d+',请访问<a href="/Bilibili_2015%E5%8A%A8%E7%94%BB%E8%A7%92%E8%89%B2%E4%BA%BA%E6%B0%94%E5%A4%A7%E8%B5%8F/%E6%98%A8%E6%97%A5%E6%88%98%E5%86%B5" title="Bilibili 2015动画角色人气大赏/昨日战况">昨日战况</a>了解详情!')},timeout:71300}),a.ajax({url:"https://annangela.moe/MoegirlPedia/BilibiliMoe.php?type=Result&callback=?&date="+g.getFullYear()+"-"+(g.getMonth()+1)+(g.getDate()<10?"-0":"-")+g.getDate(),type:"GET",dataType:"jsonp",error:f,success:function(b){if("string"==typeof b)return f({},b);if("2"!=String(b.state)[0])return f({},b.state||"-1");var g,h,i,j,k,l=function(a,b){return Number(a.votes_count)<Number(b.votes_count)?1:-1},m=function(a,b,c,d,e,f,g){a.append("<tr><td>"+b+'</td><td data-imgsrc="'+c+'"><div>'+d+"</div></td><td>"+e+"</td><td>"+(parseInt(f)+1)+(r?"</td><td>"+g+"</td></tr>":"</td></tr>"))},n=b.scheduleState.status,o=b.scheduleState.sname,p=[],q=[],r=!1,s=b.time;if("休息日"==n)c.find(".BilibiliMoeGameIntroduce .today").text("今日是休息日!"),c.find(".BilibiliMoe").css("text-align","center").text("无结果");else{for(k=Object.keys(b.data),g=k.length,i=0;g>i;i++)"1"==b.data[k[i]][0].sex?q=b.data[k[i]]:p=b.data[k[i]];for(q.sort(l),p.sort(l),j='今日的比赛是<span style="font-weight: bold;margin: 0 7px;">'+o+"("+n+")</span>["+s+"]","进行中"!=n||mw.config.values.wgUserGroups.indexOf("sysop")+mw.config.values.wgUserGroups.indexOf("patroller")>-2?(c.find(".thead").append("<th>票数</th>"),r=!0):j+='<br />(根据大赛规则,本页面不提供实时票数显示,只显示实时排名,请在深夜11:00后再次访问本页面以查看总票数或到<a rel="nofollow" target="_blank" class="external text" href="http://bilibili.com/html/moe2015-vote.html">官网投票</a>后查看,感谢你的理解!)',c.find(".BilibiliMoeGameIntroduce .today").html(j),g=p.length,i=0;g>i;i++)h=p[i],m(d,i+1,h.small_image_url,h.name,h.bangumi,h.rank,h.votes_count);for(g=q.length,i=0;g>i;i++)h=q[i],m(e,i+1,h.small_image_url,h.name,h.bangumi,h.rank,h.votes_count)}a(window).bind("load",function(){c.find("td[data-imgsrc]").each(function(){a(this).prepend(a("<img/>",{attr:{src:a(this).attr("data-imgsrc")},css:{width:"100px",height:"100px"}}))})})},complete:function(){c.attr("class","loaded")},timeout:71300})}})});
module.exports = function (grunt){
grunt.initConfig({
uglify: {
options:{
},
app_task:{
files:{
'./anna.min.js': './anna.js'
}
}
},
watch: {
another: {
files: ['./anna.js'],
tasks: ['uglify'],
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['watch']);
}
{
"name" : "Anna-Script",
"version": "0.0.1",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-uglify": "~0.11.0",
"grunt-contrib-watch": "^0.6.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment