-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhide_element.js
65 lines (57 loc) · 1.63 KB
/
hide_element.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
/**************************************************
* Hide Element
*
* Remove annoying elements on a page that are
* blocking your content, like prestitials and
* newsletter pop ups.
*
* Config settings:
*
* query: CSS query to find your element.
*
* interval: Timer interval in milleseconds.
*
* max: Total number of times the script will check
* for the element.
*
* hideAll: Hide all elements that the query returns.
*
* hideIndex: Hide a specific element that the query
* returns.
*
* @author Joel Regus
**************************************************/
(function () {
"use strict";
var config = {
query: "#elementId",
interval: 100,
max: 100,
hideAll: false,
hideIndex: 0
},
hideElement = function(element) {
element.style.display = "none";
},
stopTimer = function() {
clearInterval(findElement);
},
findElement = setInterval(function(){
this.i = this.i || 0;
this.elements = document.querySelectorAll(config.query);
this.i++;
this.len = this.elements.length;
if (this.i === config.max) {
stopTimer();
} else if (this.len > 0) {
if (config.hideAll) {
for (var j = 0; j < this.len; j++) {
hideElement(this.elements[j]);
}
} else {
hideElement(this.elements[config.hideIndex]);
}
stopTimer();
}
}, config.interval);
}());