crawler.hbs
3.18 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
<div class="pageheader">
<div class="media">
<div class="pageicon pull-left">
<i class="fa fa-th-list"></i>
</div>
<div class="media-body">
<ul class="breadcrumb">
<li><a href=""><i class="glyphicon glyphicon-home"></i></a></li>
<li><a href="">防爬虫设置</a></li>
<li>{{main_name}}{{listName}}</li>
</ul>
<h4>{{main_name}}{{listName}}设置</h4>
</div>
</div>
<!-- media -->
</div>
<!-- pageheader -->
<div class="contentpanel page-servers">
<div class="panel panel-primary-head">
<!-- panel-heading -->
<div class="input-group" style="margin: 20px 20px 20px 0">
<input id="val" type="text" class="form-control" placeholder="请输入..." style="width: 500px;">
<span class="input-group-btn" style="float: left;">
<button class="btn btn-default" type="button" id="add_black">添加至{{listName}}</button>
</span>
</div>
<table id="table-servers" class="table table-striped table-bordered responsive" style="border: 1px solid #ddd;">
<thead class="">
<tr>
<th>{{main_name}}</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{{#each list}}
<tr>
<td>{{name}}</td>
<td>
<button class="btn btn-danger btn-xs server-del">删除</button>
</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
<!-- panel -->
</div>
<script>
var isBlack = '{{listName}}' === '黑名单';
var path = location.pathname.match(/\/crawler_(white|black)\/(.*)/)[2];
$('#add_black').on('click', function() {
var val = $('#val').val();
if (!val)return;
var dataId = $($("tbody").find("tr")[$("tbody").find("tr").length - 1]).find('[data-id]').attr('data-id');
$('tbody').append('<tr><td>' + val + '</td><td><button class="btn btn-danger btn-xs server-del">删除</button></td></tr>');
$('#val').val('');
var vallists = [];
$('tr td:first-child').each(function() {
vallists.push($(this).html());
});
vallists = JSON.stringify(vallists);
if (isBlack) {
$.get('/crawler_black/change_' + path + '?path=/crawler/' + path + '_blacklists&val=' + vallists);
} else {
$.get('/crawler_white/change_' + path + '?path=/crawler/' + path + '_whitelists&val=' + vallists);
}
});
$('tbody').on('click', '.server-del', function() {
$(this).parent().parent().remove();
var vallists = [];
$('tr td:first-child').each(function() {
vallists.push($(this).html());
});
vallists = (vallists.length ? JSON.stringify(vallists) : '');
if (isBlack) {
$.get('/crawler_black/change_' + path + '?path=/crawler/' + path + '_blacklists&val=' + vallists);
} else {
$.get('/crawler_white/change_' + path + '?path=/crawler/' + path + '_whitelists&val=' + vallists);
}
});
</script>