forked from nemoTyrant/manong
-
Notifications
You must be signed in to change notification settings - Fork 1
/
manong.php
114 lines (107 loc) · 2.32 KB
/
manong.php
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>码农周刊抓取首页</title>
<style>
#content input{
width:1000px;
}
#content input.newcate{
width:100px;
}
</style>
</head>
<body>
<div id="start">
<form id="startform">
请输入抓取期数:
<input id="number" type="text" name="number">
<input type="submit" value="开始">
<button id="open">打开网页</button>
<button id="render">输出markdown</button>
</form>
</div>
<div id="content"></div>
</body>
<script src="jquery2.1.1.js"></script>
<script>
// 打开本期
$('#open').click(function(){
window.open('http://weekly.manong.io/issues/'+$('#number').val(),'_blank');
return false;
});
// 输出markdown
$('#render').click(function(){
var _this=$(this);
_this.text('处理中...');
$.getJSON('index.php?a=render',function(data){
if(data.res){
window.open('readme.md','_blank');
}else{
alert(data.msg);
}
_this.text('输出markdown');
});
return false;
});
// 分类列表
var catelist=[];
function updateCategory(cate){
if(catelist.indexOf(cate) < 0){
catelist.push(cate);
$('.add').siblings('select').append('<option value="'+cate+'">'+cate+'</option>');
}
}
//开始
$('#startform').submit(function(e){
$.post('index.php?a=crawl',$(this).serialize(),function(data){
$('#content').html(data);
// 读取分类
$.getJSON('index.php?a=cate',function(data){
$('.add').each(function(){
$(this).before(data.html);
catelist=data.cate;
});
});
});
e.preventDefault();
});
//添加
$('#content').on('click','.add',function(e){
var _this=$(this);
var data=_this.parent().serialize();
_this.text('添加中...');
$.getJSON('index.php?a=add',data,function(rs){
if(rs.res){
_this.closest('.item').hide(200);
updateCategory(rs.cate);
}else{
alert(rs.msg);
}
_this.text('添加');
});
e.preventDefault();
});
// 删除
$('#content').on('click','.del',function(e){
var _this=$(this);
var id=_this.siblings('input[name="id"]').val();
_this.text('删除中...');
$.getJSON('index.php?a=del',{id:id},function(rs){
if(rs.res){
_this.closest('.item').hide(200);
}else{
alert('删除失败');
}
});
e.preventDefault();
});
// 打开
$('#content').on('click','.openurl',function(){
var url=$(this).prev().val();
window.open(url,'_blank');
return false;
});
</script>
</html>