forked from yncoder/yncoder.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
99 lines (82 loc) · 2.68 KB
/
Copy pathindex.html
File metadata and controls
99 lines (82 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
---
layout: page
type: list
---
<div class="container">
<aside>
<a href="https://github.com/yncoder/yncoder.github.io/issues/new" target="yncoder_new_issue">
<span>+</span>发布新消息
</a>
</aside>
<main>
<ul id="label-list"></ul>
<ul id="issue-list"></ul>
</main>
</div>
<script>
(function () {
function ajax (url, options, callback) {
options = options || {};
var query = Object.keys(options.query || {}).map(function (key) {
return key + '=' + encodeURIComponent(options.query[key]);
}).join('&');
var request = new XMLHttpRequest();
request.responseType = options.responseType || 'json';
request.open(options.method || 'GET', url + (query ? '?' + query : ''), true);
request.onreadystatechange = function () {
if (this.readyState != 4) {
return;
}
if (this.status >= 200 && this.status < 300) {
callback(this.response);
} else if(this.status == 403) {
doucment.queryAllSelector('.page-list .container main').innerHTML = "<h1 class='alert-error'>别刷了,快去干活</h1>";
}
};
request.send(options.data || null);
}
function escapeHTML (str) {
return str.replace(/([&<>'"])/g, function (matcher, symbol) {
return '&#' + symbol.charCodeAt(0) + ';';
});
}
function format (template, data) {
return template.replace(/\{(\s*\w+\s*)\}/g, function (matcher, name) {
var value = data[name.trim()];
return typeof value != 'undefined' ? value : '';
});
}
ajax('//api.github.com/repos/yncoder/yncoder.github.io/issues', {
query: {
state: 'open'
}
}, function (data) {
var template = '<li class="{labelClasses} {statusClass}">' +
'<figure><img src="{authorAvatarUrl}" /></figure>' +
'<div class="title"><h4><a href="{link}">{title}</h4>' +
'<p>{labelElements} <a class="author" href="{authorLink}" target="_blank">{authorName}</a><i>{comments} 条评论</i></p></div>';
var labelTemplate = '<a href="{url}" class="label" style="backbround-color: #{color}">{name}</a>';
function renderLabelItem (label) {
return format(labelTemplate, label);
}
function renderLabelClass (label) {
return 'label-' + label.name;
}
var html = data.map(function (item) {
return format(template, {
labelClasses: item.labels.map(renderLabelClass).join(''),
labelElements: item.labels.map(renderLabelItem).join(''),
title: escapeHTML(item.title),
link: item.html_url,
authorAvatarUrl: item.user.avatar_url,
authorName: item.user.login,
authorLink: item.user.html_url,
comments: item.comments
});
}).join('');
document.getElementById('issue-list').innerHTML = html;
});
// ajax('//api.github.com/repos/yncoder/yncoder.github.io/labels', null, function (data) {
// });
})();
</script>