forked from divakarvenu/BlurImage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
67 lines (56 loc) · 2.13 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
//find all the image in answer feed,thumbnail and ad feeds and add blurclasses
var blurImage = function(){
$('.answer_body_preview').find("img").addClass('blurimage');
$('.ui_layout_thumbnail').addClass('blurthumb');
$('.HyperLinkFeedStory ').find("img").addClass('blurimage');
$('.hyperlink_image').addClass('blurthumb');
}
//find all the image in answer feed,thumbnail and ad feeds and remove blurclasses
var unblurImage=function(){
$('.answer_body_preview').find("img").removeClass('blurimage');
$('.ui_layout_thumbnail').removeClass('blurthumb');
$('.HyperLinkFeedStory ').find("img").removeClass('blurimage');
$('.hyperlink_image').removeClass('blurthumb');
}
var addListeners=function(){
$( "<style> .blurimage { -webkit-filter: blur(50px); filter: blur(50px) } .blurthumb { -webkit-filter: blur(5px); -moz-filter: blur(5px); -o-filter: blur(5px); -ms-filter: blur(5px); filter: blur(5px); width: 100px; height: 100px; background-color: #ccc;}</style>" ).appendTo( "head" );
blurImage();
$(window).scroll(function(){
blurImage();
});
$('.ui_qtext_more_link').click(function(){
blurImage();
});
$('.blurimage').click(function(){
$(this).removeClass('.blurimage'); //if user wanted to see image let them click and see
});
$('.blurthumb').click(function(){
$(this).removeClass('.blurthumb'); //if user wanted to see image let them click and see
});
}
var removeListeners=function(){
$(window).unbind('scroll');
$('.ui_qtext_more_link').unbind('click');
$('.blurimage').unbind('click');
$('.blurthumb').unbind('click');
unblurImage();
}
//message listener for background
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if(request.command === 'init'){
addListeners();
}else{
removeListeners();
}
sendResponse({result: "success"});
});
//on init perform based on chrome stroage value
window.onload=function(){
chrome.storage.sync.get('hide', function(data) {
if(data.hide){
addListeners();
}else{
removeListeners();
}
});
}