mirror of
https://github.com/wassname/Mostly-Harmless.git
synced 2026-07-14 01:10:21 +08:00
Pushing things into an array and joining it at the end is faster
than concatenating strings, because JS creates a new string for every concatenatiion, and discards the old one.
This commit is contained in:
@@ -35,37 +35,37 @@ function buildPage(pageUrl) {
|
||||
if (data.likes === 'true') voteDir = 1;
|
||||
if (data.likes === null) voteDir = 0;
|
||||
if (data.likes === 'false') voteDir = -1;
|
||||
var entry = new String();
|
||||
var entry = new Array();
|
||||
var hiddenText = data.saved === 'true' ? 'hidden' : 'hide';
|
||||
var saveText = data.saved === 'true' ? 'saved' : 'save';
|
||||
entry += '<li id="' + data.name + '" class="' + hiddenText + ' ' + saveText + '" data-dir="' + voteDir.toString() + '">';
|
||||
entry += '<div class="votes">';
|
||||
entry += '<a class="upmod" onclick="apiCall(\'upmod\', \'' + data.name + '\')"></a>';
|
||||
entry += '<span class="count" id="count_' + data.name + '" title="' + data.ups + ' up votes, ' + data.downs + ' down votes">' + data.score + '</span>';
|
||||
entry += '<a class="downmod" onclick="apiCall(\'downmod\', \'' + data.name + '\')"></a>';
|
||||
entry += '</div>';
|
||||
entry += '<a class="thumblink" href="http://www.reddit.com' + data.permalink + '" target="_blank" title="View this post on reddit">';
|
||||
entry.push('<li id="' + data.name + '" class="' + hiddenText + ' ' + saveText + '" data-dir="' + voteDir.toString() + '">');
|
||||
entry.push('<div class="votes">');
|
||||
entry.push('<a class="upmod" onclick="apiCall(\'upmod\', \'' + data.name + '\')"></a>');
|
||||
entry.push('<span class="count" id="count_' + data.name + '" title="' + data.ups + ' up votes, ' + data.downs + ' down votes">' + data.score + '</span>');
|
||||
entry.push('<a class="downmod" onclick="apiCall(\'downmod\', \'' + data.name + '\')"></a>');
|
||||
entry.push('</div>');
|
||||
entry.push('<a class="thumblink" href="http://www.reddit.com' + data.permalink + '" target="_blank" title="View this post on reddit">');
|
||||
var thumbSrc = data.thumbnail.indexOf('/') === 0 ? 'http://www.reddit.com' + data.thumbnail : data.thumbnail;
|
||||
entry += '<img class="thumb" src="' + thumbSrc + '" alt="' + data.title + '" width="70"/>';
|
||||
entry += '</a>';
|
||||
entry += '<div class="post">';
|
||||
entry += '<a class="link" href="http://www.reddit.com' + data.permalink + '" target="_blank" title="View this post on reddit">' + data.title + '</a> ';
|
||||
entry += '<a class="domain" href="http://www.reddit.com/domain/' + data.domain + '" target="_blank">(' + data.domain + ')</a>';
|
||||
entry += '<div class="meta">';
|
||||
entry += '<span class="timestamp">submitted ' + prettyDate(ISODateString(new Date(data.created_utc * 1000))) + '</span> by ';
|
||||
entry += '<a class="submitter" href="http://www.reddit.com/user/' + data.author + '" target="_blank">' + data.author + '</a> to';
|
||||
entry += '<a class="subreddit" href="http://www.reddit.com/r/' + data.subreddit + '/" target="_blank">' + data.subreddit + '</a>';
|
||||
entry += '</div>';
|
||||
entry += '<div class="actions">';
|
||||
entry += '<a class="comments" href="http://www.reddit.com' + data.permalink + '" target="_blank">' + data.num_comments + ' comments</a>';
|
||||
entry += '<a class="share">share</a>';
|
||||
entry += '<a class="save">' + saveText + '</a>';
|
||||
entry += '<a class="hide">' + hiddenText + '</a>';
|
||||
entry += '<a class="report">report</a>';
|
||||
entry += '</div>';
|
||||
entry += '</div>'
|
||||
entry += '</li>';
|
||||
document.getElementById('posts').innerHTML += entry;
|
||||
entry.push('<img class="thumb" src="' + thumbSrc + '" alt="' + data.title + '" width="70"/>');
|
||||
entry.push('</a>');
|
||||
entry.push('<div class="post">');
|
||||
entry.push('<a class="link" href="http://www.reddit.com' + data.permalink + '" target="_blank" title="View this post on reddit">' + data.title + '</a> ');
|
||||
entry.push('<a class="domain" href="http://www.reddit.com/domain/' + data.domain + '" target="_blank">(' + data.domain + ')</a>');
|
||||
entry.push('<div class="meta">');
|
||||
entry.push('<span class="timestamp">submitted ' + prettyDate(ISODateString(new Date(data.created_utc * 1000))) + '</span> by ');
|
||||
entry.push('<a class="submitter" href="http://www.reddit.com/user/' + data.author + '" target="_blank">' + data.author + '</a> to');
|
||||
entry.push('<a class="subreddit" href="http://www.reddit.com/r/' + data.subreddit + '/" target="_blank">' + data.subreddit + '</a>');
|
||||
entry.push('</div>');
|
||||
entry.push('<div class="actions">');
|
||||
entry.push('<a class="comments" href="http://www.reddit.com' + data.permalink + '" target="_blank">' + data.num_comments + ' comments</a>');
|
||||
entry.push('<a class="share">share</a>');
|
||||
entry.push('<a class="save">' + saveText + '</a>');
|
||||
entry.push('<a class="hide">' + hiddenText + '</a>');
|
||||
entry.push('<a class="report">report</a>');
|
||||
entry.push('</div>');
|
||||
entry.push('</div>');
|
||||
entry.push('</li>');
|
||||
document.getElementById('posts').innerHTML += entry.join('');
|
||||
}
|
||||
if(!isCommentsPage) {
|
||||
document.getElementById('submit').href = 'http://www.reddit.com/submit?resubmit=true&url=' + encodeURI(document.getElementById('posts').getAttribute('data-url'));
|
||||
|
||||
Reference in New Issue
Block a user