-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaddCounter.js
45 lines (44 loc) · 1.88 KB
/
addCounter.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
var fs = require('fs');
var strip = require('strip-comments');
//var path = __dirname + '/test/ssp15-recursion/src/'
var path = __dirname + '/server/client/ClassContainer/'+process.argv[2]+'/'+process.argv[3]+'/recursion/src/'
console.log(path+"getElementsByClassName.js")
fs.exists(path+"getElementsByClassName.js",function(exists){
console.log(exists)
if(exists){
fs.readFile(path+"getElementsByClassName.js","utf-8", (err, data) => {
if (err) throw err;
var string = strip(data);
var match = string.match(/var getElementsByClassName = function.*\(.*\) {/)
if(!match){
match = string.match(/var getElementsByClassName = function\(.*\n\) {/)
}
string = string.replace(match[0],"\nvar counter = 0; \n" + match[0] + " \ncounter++ \nif(counter > 2000){\n\treturn\n}","")
fs.writeFile(path + "getElementsByClassName.js",string,(err, data) => {
if(err) throw err;
})
});
fs.readFile(path+"parseJSON.js","utf-8", (err, data) => {
if (err) throw err;
var string = data;
var match = string.match(/var parseJSON = function\(.*\) {/)
string = string.replace(match[0],"\nvar counter = 0; \n" + match[0] + " \ncounter++ \nif(counter > 2000){\n\treturn\n}")
fs.writeFile(path + "parseJSON.js",string,(err, data) => {
if(err) throw err;
})
});
fs.readFile(path+"stringifyJSON.js","utf-8", (err, data) => {
if (err) throw err;
var string = data;
var match = string.match(/var stringifyJSON = function\(.*\) {/)
if(!match){
match = string.match(/function stringifyJSON\(.*\) {/)
}
string = string.replace(match[0],"\nvar counter = 0; \n" + match[0] + " \ncounter++ \nif(counter > 2000){\n\treturn\n}")
fs.writeFile(path+"stringifyJSON.js",string,(err, data) => {
if(err) throw err;
})
});
}
})
console.log(process.argv[2], process.argv[3])