-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-stats.js
More file actions
47 lines (42 loc) · 1.29 KB
/
node-stats.js
File metadata and controls
47 lines (42 loc) · 1.29 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
var nodeStats = {
appendChild: 0,
removeChild: 0,
replaceChild: 0,
insertBefore: 0,
attached: 0,
detached: 0
};
var isAttached = function(node)
{
if (node.parentNode === null) return false;
if (node.nodeName === "HTML") return true;
return isAttached(node.parentNode);
}
var _appendChild = Node.prototype.appendChild;
Node.prototype.appendChild = function(newChild)
{
nodeStats.appendChild++;
isAttached(this) ? nodeStats.attached++ : nodeStats.detached++;
return _appendChild.call(this, newChild);
};
var _removeChild = Node.prototype.removeChild;
Node.prototype.removeChild = function (oldChild)
{
nodeStats.removeChild++;
isAttached(oldChild) ? nodeStats.attached++ : nodeStats.detached++;
return _removeChild.call(this, oldChild);
}
var _replaceChild = Node.prototype.replaceChild;
Node.prototype.replaceChild = function (newChild, oldChild)
{
nodeStats.replaceChild++;
isAttached(oldChild) ? nodeStats.attached++ : nodeStats.detached++;
return _replaceChild.call(this, newChild, oldChild);
}
var _insertBefore = Node.prototype.insertBefore;
Node.prototype.insertBefore = function (newChild, refChild)
{
nodeStats.insertBefore++;
isAttached(this) ? nodeStats.attached++ : nodeStats.detached++;
return _insertBefore.call(this, newChild, refChild);
}