我正在尝试开发博客模板,我需要帮助来优化我的代码,现在我在xml中遇到了一些问题:
function labelthumbs(e) {
document.write('<ul class="' + outerclass + '">');
for (var t = 0; t < numposts; t++) {
var r, i = e.feed.entry[t],
n = i.title.$t,
l = i.category[0].term,
l2 = i.category[1].term;
if (t == e.feed.entry.length) break;
for (var o = 0; o < i.link.length; o++)
if ("alternate" == i.link[o].rel) {
r = i.link[o].href;
break
}
var u;
try {
u = i.media$thumbnail.url
} catch (p) {
s = i.content.$t, a = s.indexOf("<img"), b = s.indexOf('src="', a), c = s.indexOf('"', b + 5), d = s.substr(b + 5, c - b - 5), u = -1 != a && -1 != b && -1 != c && "" != d ? d : "http://1.bp.blogspot.com/-pmtmCl8EbTI/UoY33J0Dp9I/AAAAAAAAAAA/fbchARjKIDg/s500-c/grey.gif"
}
var m = i.published.$t,
v = m.substring(0, 4),
g = m.substring(5, 7),
h = m.substring(8, 10),
f = new Array;
f[1] = "January",
f[2] = "February",
f[3] = "March",
f[4] = "April",
f[5] = "May",
f[6] = "June",
f[7] = "July",
f[8] = "August",
f[9] = "September",
f[10] = "October",
f[11] = "November",
f[12] = "December";
var A = f[parseInt(g, 10)] + " " + h + ", " + v;
if (l == "pc")
{
document.write(starttag + "<" + intag + ' class="post">'),
document.write('<div class="post-media"><div class="image-wrap"><img src="' + u.replace("/s72-c/", "/s400-p/") + '" alt="' + n + '"/></div></div><div class="post-body">'), "featured-slider" == outerclass &&
document.write('<span class="cat"><a style="background:red" href="/search/label/' + l + '">' + l + '</a><a href="/search/label/' + l2 + '">' + l2 + '</a></span><div class="post-title"><h4><a href="' + r + '">' + n + '</a></h4></div><div class="post-meta"><span class="post-date">' + A + "</span></div></div>"), "sub-menu" == outerclass &&
document.write('<div class="post-title"><h2><a href="' + r + '">' + n + '</a></h2></div><span class="post-date">' + A + "</span></div>"),
document.write("</" + intag + ">" + endtag)
}
else if (l == "ps4")
{
document.write(starttag + "<" + intag + ' class="post">'),
document.write('<div class="post-media"><div class="image-wrap"><img src="' + u.replace("/s72-c/", "/s400-p/") + '" alt="' + n + '"/></div></div><div class="post-body">'), "featured-slider" == outerclass &&
document.write('<span class="cat"><a style="background:blue" href="/search/label/' + l + '">' + l + '</a><a href="/search/label/' + l2 + '">' + l2 + '</a></span><div class="post-title"><h4><a href="' + r + '">' + n + '</a></h4></div><div class="post-meta"><span class="post-date">' + A + "</span></div></div>"), "sub-menu" == outerclass &&
document.write('<div class="post-title"><h2><a href="' + r + '">' + n + '</a></h2></div><span class="post-date">' + A + "</span></div>"),
document.write("</" + intag + ">" + endtag)
}
else if (l == "xbox")
{
document.write(starttag + "<" + intag + ' class="post">'),
document.write('<div class="post-media"><div class="image-wrap"><img src="' + u.replace("/s72-c/", "/s400-p/") + '" alt="' + n + '"/></div></div><div class="post-body">'), "featured-slider" == outerclass &&
document.write('<span class="cat"><a style="background:green" href="/search/label/' + l + '">' + l + '</a><a href="/search/label/' + l2 + '">' + l2 + '</a></span><div class="post-title"><h4><a href="' + r + '">' + n + '</a></h4></div><div class="post-meta"><span class="post-date">' + A + "</span></div></div>"), "sub-menu" == outerclass &&
document.write('<div class="post-title"><h2><a href="' + r + '">' + n + '</a></h2></div><span class="post-date">' + A + "</span></div>"),
document.write("</" + intag + ">" + endtag)
}
else if (l == "wii")
{
document.write(starttag + "<" + intag + ' class="post">'),
document.write('<div class="post-media"><div class="image-wrap"><img src="' + u.replace("/s72-c/", "/s400-p/") + '" alt="' + n + '"/></div></div><div class="post-body">'), "featured-slider" == outerclass &&
document.write('<span class="cat"><a style="background:grey" href="/search/label/' + l + '">' + l + '</a><a href="/search/label/' + l2 + '">' + l2 + '</a></span><div class="post-title"><h4><a href="' + r + '">' + n + '</a></h4></div><div class="post-meta"><span class="post-date">' + A + "</span></div></div>"), "sub-menu" == outerclass &&
document.write('<div class="post-title"><h2><a href="' + r + '">' + n + '</a></h2></div><span class="post-date">' + A + "</span></div>"),
document.write("</" + intag + ">" + endtag)
}
else
{
document.write(starttag + "<" + intag + ' class="post">'),
document.write('<div class="post-media"><div class="image-wrap"><img src="' + u.replace("/s72-c/", "/s400-p/") + '" alt="' + n + '"/></div></div><div class="post-body">'), "featured-slider" == outerclass &&
document.write('<span class="cat"><a style="background:yellow" href="/search/label/' + l + '">' + l + '</a><a href="/search/label/' + l2 + '">' + l2 + '</a></span><div class="post-title"><h4><a href="' + r + '">' + n + '</a></h4></div><div class="post-meta"><span class="post-date">' + A + "</span></div></div>"), "sub-menu" == outerclass &&
document.write('<div class="post-title"><h2><a href="' + r + '">' + n + '</a></h2></div><span class="post-date">' + A + "</span></div>"),
document.write("</" + intag + ">" + endtag)
}
}
document.write("</ul>")
};
是否可以通过任何方式进行更好的条件使用?在所有条件仅适用于一个变量之后,不确定将if放在document.write中。 您可以访问我的测试博客:http://pruebaxweb.blogspot.pe/ 我想得到的是,带有“PC,ps4,xbox等”标签的帖子首先显示,然后“动作,射击,RPG,街机”标签显示。 如果有人可以帮助我,我会非常感激
谢谢你们