-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathboysenDom.js
139 lines (122 loc) · 3.37 KB
/
boysenDom.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
Test of altering dom via a function
boysenDom.js
-Changes all elements of a dom
Add borders to all elements
TODO
Fix alignment issues in certain websites, arises when adding border of 1 px
Remove borders
*/
var popupElements = ["popupWrap","popupWrap ui-draggable","popupTitle","popupTitleInner","popupClassDisplay","popupClassDisplayOuter","popupTitleDisplayModeToggle","popupClassDisplayBody","popupWrap ui-draggable ui-draggable-handle"];
var isOpen = false;
//parseDom used to parse the entire DOM and add the appropriate borders
function addBorderToElement(currentElement){
var currentWidth = currentElement.clientWidth;
var currentHeight = currentElement.clientHeight;
var numChildren = currentElement.childNodes.length;
var elementFromID = document.getElementById(currentElement.id);
if(elementFromID === null){
return;
}
var found = $.inArray(elementFromID.className, popupElements) > -1;
if(found){
return;
}
if(numChildren > 3){
elementFromID.className += " boysenRed";
}
else if(numChildren > 2){
elementFromID.className += " boysenBlue";
}
else if(numChildren > 0){
elementFromID.className += " boysenPurple";
}
}
function removeGif(){
$(".gifBox").remove();
}
/*
Function to add border clases appropriately
*/
function parseDom(){
//console.log.log("parseDom");
var all = document.getElementsByTagName("*");
var max=all.length;
var elementID;
var displayCounter = 0;
for (var i=0; i < max; i++) {
// Do something with the element here
var element = all[i];
elementID = element.id;
if(!element.id){
element.id = "boysen"+i;
}
if(document.getElementById(element.id) !== null){
addBorderToElement(all[i]);
}
}
chrome.runtime.sendMessage({status: 'finishedParsing'});
}
/*
Function to remove added classes
Catch a typeerror
*/
function removeClasses(selected){
try{
selected.className = selected.className.replace("boysenBlue" , '' );
selected.className = selected.className.replace("boysenPurple" , '' );
selected.className = selected.className.replace("boysenRed" , '' );
selected.className = selected.className.replace("hoverEffect" , '' );
}
catch(e){
// //console.log.log(e);
}
}
/*
Function to reset the borders and remove the box
*/
function clearDom(){
//console.log.log("clearDom");
var all = document.getElementsByTagName("*");
var max=all.length;
var elementID;
for (var i=0; i < max; i++) {
// Do something with the element here
var element = all[i];
elementID = element.id;
var selected = document.getElementById(elementID);
if(selected !== null){
removeClasses(selected);
}
}
unbindMouse();
$('.popupWrap').addClass("bounceOutDown animated");
setTimeout(function(){
$(".popupWrap").removeClass("bounceOutDown animated");
$(".popupWrap").detach();
}, 1000);
}
//Unbind mouse
function unbindMouse(){
$("body").unbind("mousemove");
}
//add a loading display
function showLoader(){
$("body").prepend('<div class="gifBox"></div>');
}
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.action == "beginParse"){
if(!isOpen){
$("body").prepend('<div class="gifBox">boysening.</div>');
setTimeout(function(){
parseDom();
},300);
isOpen = true;
}
else{
clearDom();
isOpen = false;
}
}
});