-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
70 lines (67 loc) · 2.45 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-csv/1.0.40/jquery.csv.min.js" integrity="sha512-Y8iWYJDo6HiTo5xtml1g4QqHtl/PO1w+dmUpQfQSOTqKNsMhExfyPN2ncNAe9JuJUSKzwK/b6oaNPop4MXzkwg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css">
</head>
<body>
<div class="container">
<form id="form">
<div class="form-group">
<label for="name">請輸入 Hackfoldr 網址</label>
<input type="text" class="form-control" name="url">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<hr>
<textarea id="output" class="form-control" rows="10"></textarea>
</div>
<script>
$('#form').submit(function(e){
e.preventDefault();
var url = $(this).find('input[name="url"]').val();
// get gov-hackath62n from https://beta.hackfoldr.org/g0v-hackath62n
var hackfoldr = url.split('/')[3];
// csv url = https://ethercalc-cache.g0v.tw/_/g0v-hackath62n/csv
var csv_url = 'https://ethercalc-cache.g0v.tw/_/' + hackfoldr + '/csv';
var message = '';
$.get(csv_url, function(data){
let records = $.csv.toArrays(data);
records.shift();
records = records.filter((record) => {
if (record[0]) {
return true;
}
if (record[1]) {
return true;
}
return false;
});
// 第一個是 title
message += '# ' + records.shift()[1] + '\n';
for (let record of records) {
if (record[0]) {
title = record[1];
if (record[2]) {
if (record[2].match(':[a-z]+$')) {
record[2] = record[2].replace(/:[a-z]+$/, '');
}
title += ' `' + record[2] + '`';
}
message += '- [' + title + '](' + record[0] + ')';
message += '\n';
} else {
message += '\n';
message += record[1] + '\n';
message += '---\n';
}
}
$('#output').val(message);
});
});
</script>
</body>
</html>