-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
67 lines (63 loc) · 2.3 KB
/
content.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
if (window.location.href.indexOf("sahibinden.com") > -1) {
let parents = [];
function getParent(element){
return element.closest('ul');
}
function getParentIndex(parents,parent){
return parents.indexOf(parent);
}
function isParentExistInParents(parents, parent){
return getParentIndex(parents, parent) === -1;
}
function pushToParents(parents, parent){
if(isParentExistInParents(parents, parent)){
parents.push(parent);
}
return parents;
}
function insertClassesToCheckBoxes(){
$(".facetedCheckbox").each(function(index,element){
let parent = getParent(element);
pushToParents(parents, parent);
$(element).addClass('facetedCheckboxSelectAll facetedCheckboxSelectAll'+getParentIndex(parents, parent));
});
}
function insertSelectAlls(){
parents.forEach(function(element,index){
$(element).prepend("<li><div class='text-content'><a class='facetedCheckboxSelectAllA js-attribute facetedCheckbox' onclick='(function(){ $(\".facetedCheckboxSelectAll\"+"+index+").click(); })();'><i tabindex='0'></i>Hepsini Seç / Kaldır</a></div></li>");
});
}
function removeSelectAlls(){
$(".facetedCheckboxSelectAllA").remove();
}
function getSelectAllText(element){
return $(element).isChecked()
}
//message listener for background
chrome.runtime.onMessage.addListener(function(request) {
if(request.command === 'init'){
insertSelectAlls();
}else{
removeSelectAlls();
}
});
//on init perform based on chrome stroage value
window.onload=function(){
chrome.storage.sync.get('active', function(data) {
if(data.active){
document.querySelectorAll('.faceted-select').forEach(function(element, index){
if(index == 1){
element.click();
setTimeout(function(){
insertClassesToCheckBoxes();
insertSelectAlls();
element.click();
}, 1000)
}
});
}else{
removeSelectAlls();
}
});
}
}