-
Notifications
You must be signed in to change notification settings - Fork 0
/
songtaste.js
103 lines (80 loc) · 2.55 KB
/
songtaste.js
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
var http = require('http'),
connect = require('connect'),
httpProxy = require('http-proxy'),
iconv = require('iconv-lite'),
harmon = require('harmon'),
fs = require('fs');
var selects = [];
var bodyselect = {};
bodyselect.query = 'body';
bodyselect.func = function(node) {
var stm = node.createStream({outer : false});
var all = '';
stm.on('data', function(data) {
data = iconv.decode(data, 'gbk').toString('utf8');
all += data;
});
stm.on('end', function() {
all = all.replace(/<!--([\s\S]*?)-->/g, "$1");
all = all.replace(/^\/\/(.*$)/mg, "$1");
// all = all.replace("<!-- <div id=\"playicon", "<div id=\"playicon");
// all = all.replace("<link rel=\"stylesheet\" href=\"http://www.songtaste.com/plugin/fancybox/jquery.fancybox-1.3.4.css\" type=\"text/css\" /> -->", "<link rel=\"stylesheet\" href=\"http://www.songtaste.com/plugin/fancybox/jquery.fancybox-1.3.4.css\" type=\"text/css\" />");
process.stdout.write('deal body\n');
var resStr = iconv.encode(all, 'gbk');
stm.end(resStr);
});
}
selects.push(bodyselect);
// var tjselect = {};
// tjselect.query = '.tj_scleft';
// tjselect.func = function(node) {
// var stm = node.createStream({outer : false});
// var all2 = '';
// stm.on('data', function(data) {
// data = iconv.decode(data, 'gbk').toString('utf8');
// all2 += data;
// });
// stm.on('end', function() {
// all2 = all2.replace(/<!--([\s\S]*?)-->/g, "$1");
// all2 = all2.replace(/^\/\/(.*$)/mg, "$1");
// process.stdout.write('deal .tj_scleft\n');
// var resStr = iconv.encode(all, 'gbk');
// stm.end(resStr);
// });
// }
//
// selects.push(tjselect);
var imgSelector = {};
imgSelector.query = '.song_left > img';
imgSelector.func = function(node) {
var stm = node.createStream({ outer : true });
stm.on('data', function(data) {
});
stm.on('end', function() {
process.stdout.write('remove .song_left > img\n');
stm.end('');
});
}
selects.push(imgSelector);
//
// Basic Connect App
//
var app = connect();
var proxy = httpProxy.createProxyServer({
target: 'http://songtaste.com'
})
app.use(harmon([], selects));
app.use(
function (req, res) {
proxy.web(req, res);
}
);
http.createServer(app).listen(8093);
var pid = process.pid;
console.log(pid);
var pidFile = 'pid.txt';
var existsSync = fs.existsSync || path.existsSync;
existsSync(pidFile) && fs.unlinkSync(pidFile);
fs.writeFile(pidFile, '' + pid, function(err) {
if(err) console.log(err);
});