one repeated array slice and one repeated eval of function call lesser

This commit is contained in:
Simon Grim 2015-05-25 18:05:30 +05:00
parent 498470f436
commit 3b6be26184

View File

@ -77,7 +77,7 @@ var InterfaceFunctions = function() {
loadFollowing( function(args) { loadFollowing( function(args) {
$(".mini-profile .following-count").text(followingUsers.length-1); $(".mini-profile .following-count").text(followingUsers.length-1);
requestLastHave(); requestLastHave();
setInterval("requestLastHave()", 1000); setInterval(requestLastHave, 1000);
initMentionsCount(); initMentionsCount();
initDMsCount(); initDMsCount();
requestTimelineUpdate("latestFirstTime",postsPerRefresh,followingUsers,promotedPostsOnly); requestTimelineUpdate("latestFirstTime",postsPerRefresh,followingUsers,promotedPostsOnly);
@ -227,92 +227,94 @@ function initTwistdayReminder() {
} }
function refreshTwistdayReminder() { function refreshTwistdayReminder() {
var $module = $('.module.twistday-reminder'); var module = $('.module.twistday-reminder');
var $list = $module.find('.list'); var list = module.find('.list');
if ($list.length) { if (list.length) {
$module.find('.refresh').hide(); module.find('.refresh').hide();
$module.find('.loading-roller').show(); module.find('.loading-roller').show();
if (defaultScreenName && typeof(followingUsers) !== 'undefined') { if (defaultScreenName && typeof followingUsers !== 'undefined' && followingUsers.length) {
var suggests = followingUsers.slice(); var suggests = [];
if (suggests.length > 0) { for (var i = 0; i < followingUsers.length; i++) {
for (var i = 0; i < suggests.length; i++) { suggests[i] = {username: followingUsers[i], max_id: 0};
suggests[i] = {'username': suggests[i], 'max_id': 0}; }
} twisterRpc('getposts', [suggests.length + 1, suggests],
twisterRpc('getposts', [suggests.length + 1,suggests], function(arg, posts) {
function(arg, posts) { function addLuckyToList(list, post, time) {
function addLuckyToList(list, post, time) { var lucky = post.userpost.n;
var lucky = post.userpost.n; if (!list.find('[data-screen-name=' + lucky + ']').length) {
if (list.find('[data-screen-name='+lucky+']').length < 1) { var item = $('#twistday-reminder-suggestion-template').clone(true)
var item = $('#twistday-reminder-suggestion-template').clone(true); .removeAttr('id');
item.removeAttr('id'); item.find('.twister-user-info').attr('data-screen-name', lucky);
item.find('.twister-user-info').attr('data-screen-name', lucky); item.find('.twister-user-name').attr('href', $.MAL.userUrl(lucky));
item.find('.twister-user-name').attr('href', $.MAL.userUrl(lucky)); item.find('.twister-user-tag').text('@' + lucky);
item.find('.twister-user-tag').text('@' +lucky); itemTwisterday = item.find('.twisterday');
itemTwisterday = item.find('.twisterday'); itemTwisterday.on('click', (function(e) {replyInitPopup(e, post);}).bind(post));
itemTwisterday.bind('click', (function(e) { replyInitPopup(e, post); }).bind(post)); if (typeof time !== 'undefined')
if (typeof(time) !== 'undefined') itemTwisterday.text(timeGmtToText(time));
itemTwisterday.text(timeGmtToText(time)); else
else itemTwisterday.text(timeGmtToText(post.userpost.time));
itemTwisterday.text(timeGmtToText(post.userpost.time));
getAvatar(lucky, item.find('.twister-user-photo')); getAvatar(lucky, item.find('.twister-user-photo'));
getFullname(lucky, item.find('.twister-user-full')); getFullname(lucky, item.find('.twister-user-full'));
list.append(item); list.append(item);
}
}
function removeLuckyFromList(list, lucky) {
list.find('[data-screen-name='+lucky+']').closest('li').remove();
} }
}
function removeLuckyFromList(list, lucky) {
list.find('[data-screen-name=' + lucky + ']').closest('li').remove();
}
var showUpcomingTimer = ($.Options.TwistdayReminderShowUpcoming.val === 'enable') ? $.Options.TwistdayReminderShowUpcomingTimer.val * 3600 : 0; var showUpcomingTimer = ($.Options.TwistdayReminderShowUpcoming.val === 'enable') ?
var listCurrent = $module.find('.current .list'); $.Options.TwistdayReminderShowUpcomingTimer.val * 3600 : 0;
var listUpcoming = $module.find('.upcoming .list'); var listCurrent = module.find('.current .list');
var d = new Date(); var listUpcoming = module.find('.upcoming .list');
var todayYear = d.getUTCFullYear(); var d = new Date();
var todayMonth = d.getUTCMonth(); var todayYear = d.getUTCFullYear();
var todayDate = d.getUTCDate(); var todayMonth = d.getUTCMonth();
var todaySec = Date.UTC(todayYear,todayMonth,todayDate,d.getUTCHours(),d.getUTCMinutes(),d.getUTCSeconds()) /1000; var todayDate = d.getUTCDate();
var thatSec; var todaySec = Date.UTC(todayYear, todayMonth, todayDate,
d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds()) /1000;
var thatSec;
posts.sort(function(a,b) { posts.sort(function(a, b) {
return (parseInt(a.userpost.time) > parseInt(b.userpost.time)) ? 1 : -1; return (parseInt(a.userpost.time) > parseInt(b.userpost.time)) ? 1 : -1;
}); });
for (var i = 0; i < posts.length; i++) { for (var i = 0; i < posts.length; i++) {
if (followingUsers.indexOf(posts[i].userpost.n) > -1) { if (followingUsers.indexOf(posts[i].userpost.n) > -1) {
d.setTime(0); d.setTime(0);
d.setUTCSeconds(posts[i].userpost.time); d.setUTCSeconds(posts[i].userpost.time);
if (d.getUTCMonth() === todayMonth && d.getUTCDate() === todayDate) { if (d.getUTCMonth() === todayMonth && d.getUTCDate() === todayDate) {
addLuckyToList(listCurrent, posts[i]); addLuckyToList(listCurrent, posts[i]);
removeLuckyFromList(listUpcoming, posts[i].userpost.n); removeLuckyFromList(listUpcoming, posts[i].userpost.n);
} else if (showUpcomingTimer > 0) { } else if (showUpcomingTimer > 0) {
thatSec = Date.UTC(todayYear,d.getUTCMonth(),d.getUTCDate(),d.getUTCHours(),d.getUTCMinutes(),d.getUTCSeconds()) /1000; thatSec = Date.UTC(todayYear, d.getUTCMonth(), d.getUTCDate(),
if (thatSec > todaySec && thatSec -todaySec <= showUpcomingTimer) { d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds()) /1000;
d.setTime(0); if (thatSec > todaySec && thatSec -todaySec <= showUpcomingTimer) {
d.setUTCSeconds(thatSec); d.setTime(0);
addLuckyToList(listUpcoming, posts[i], d.getTime() /1000); d.setUTCSeconds(thatSec);
} else { addLuckyToList(listUpcoming, posts[i], d.getTime() /1000);
removeLuckyFromList(listCurrent, posts[i].userpost.n);
removeLuckyFromList(listUpcoming, posts[i].userpost.n);
}
} else { } else {
removeLuckyFromList(listCurrent, posts[i].userpost.n); removeLuckyFromList(listCurrent, posts[i].userpost.n);
removeLuckyFromList(listUpcoming, posts[i].userpost.n); removeLuckyFromList(listUpcoming, posts[i].userpost.n);
} }
} else {
removeLuckyFromList(listCurrent, posts[i].userpost.n);
removeLuckyFromList(listUpcoming, posts[i].userpost.n);
} }
} }
}
if (listCurrent.children().length) if (listCurrent.children().length)
listCurrent.parent().show(); listCurrent.parent().show();
if (listUpcoming.children().length) if (listUpcoming.children().length)
listUpcoming.parent().show(); listUpcoming.parent().show();
$module.find('.refresh').show(); module.find('.refresh').show();
$module.find('.loading-roller').hide(); module.find('.loading-roller').hide();
}, null, }, null,
function(arg, ret) { console.log('ajax error:' + ret); }, null); function(arg, ret) {console.log('ajax error:' + ret);}, null
} );
} }
if ($.Options.TwistdayReminderAutoUpdate.val === 'enable' && $.Options.TwistdayReminderAutoUpdateTimer.val > 0) if ($.Options.TwistdayReminderAutoUpdate.val === 'enable' && $.Options.TwistdayReminderAutoUpdateTimer.val > 0)
setTimeout(refreshTwistdayReminder, $.Options.TwistdayReminderAutoUpdateTimer.val * 1000); setTimeout(refreshTwistdayReminder, $.Options.TwistdayReminderAutoUpdateTimer.val * 1000);