forked from gleuch/STOP-SOPA-Blackout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblackout.js
195 lines (161 loc) · 9.73 KB
/
blackout.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
STOP SOPA/PIPA #000000-out
Embeddable widget for pro-Internet solidarity
More info:
https://fatlab.github.com/stop-sopa-blackout
This source made freely available under an MIT License:
http://opensource.org/licenses/mit-license.php
*/
function sopa_blackout_start($_) {
$_.fn.reverse = function(){return this.pushStack(this.get().reverse(), arguments);};
(function($_) {
$_.sopa_blackout = function(data, c) {
if (!$_.sopa_blackout.settings.finish) $_.sopa_blackout.init();
$_(data).sopa_blackout(c);
if (!$_.sopa_blackout.settings.finish) $_.sopa_blackout.finish(c);
};
$_.fn.sopa_blackout = function(c) {
return this.filter(function() {
return $_.sopa_blackout.filter(this);
}).each(function() {
$_.sopa_blackout.blackout(this, c);
});
};
$_.extend($_.sopa_blackout, {
settings : {hide_bg : true, href : false, page_height : 0, replace: '<ins class="sopa_blackout" style="color: %C; background-color: %C;">$1</ins>', init : false, finish : false},
pluck : function(str) {
return $_.map(str.split(' '), function(s) {return s.replace(/.{1}/img, '*');}).join(' ');
},
filter : function(self) {
if (self.nodeType == 1) {
var tag = self.tagName.toLowerCase();
return !($_(self).hasClass('sopa_blackout') || $_(self).hasClass('skip_stop_sopa') || tag == 'head' || tag == 'img' || tag == 'textarea' || tag == 'option' || tag == 'style' || tag == 'script' || tag == 'code' || tag == 'samp');
} else {
return true;
}
},
blackout : function(self, c) {
$_(self).css({'text-shadow' : 'none'});
if (self.nodeType == 3) {
if (self.nodeValue.replace(/\s/ig, '')) {
var text = $_.map(self.nodeValue.split(' '), function(s) {return $_.sopa_blackout.settings.replace.replace(/\%C/mg, c).replace(/\$1/mg, s);}).join(' '),
sp1 = document.createElement("span");
sp1.className = 'sopa_blackout';
sp1.innerHTML = text;
self.parentNode.replaceChild(sp1, self)
}
} else if (self.nodeType == 1) {
if ($_(self).children().length > 0) {
$_.sopa_blackout($_(self).contents(), c);
} else {
if ($_(self).html() != '') {
text = $_.map($_(self).html().split(' '), function(s) {return $_.sopa_blackout.settings.replace.replace(/\%C/mg, c).replace(/\$1/mg, s);}).join(' '),
$_(self).html(text);
}
}
}
},
init : function() {
$_.sopa_blackout.settings.init = true;
},
finish : function(c) {
$_(document).each(function() {this.title = $_.sopa_blackout.pluck(this.title);});
$_('img, input[type=image], iframe, embed, object').each(function() {
try {
if ($_(this).attr('alt').match($_.sopa_blackout.settings.search) || $_(this).attr('title').match($_.sopa_blackout.settings.search) || $_(this).attr('src').match($_.sopa_blackout.settings.search)) {
var r = $_(this), w = r.width(), h = r.height(), el_c = c;
r.addClass('sopa_blackout').css({background: el_c, width: r.width(), height: r.height()}).attr('src', ("https:" == document.location.protocol ? 'http:' : 'http:')+'//assets.gleuch.com/blank.png').width(w).height(h);
}
} catch(e) {}
});
// $_('input[type=text]').each(function() {if ($_(this).val().match($_.sopa_blackout.settings.search) ) $_(this).val( $_.sopa_blackout.pluck($_(this).val()) );});
// $_('textarea, option').each(function() {if ($_(this).html().match($_.sopa_blackout.settings.search) ) $_(this).html( $_.sopa_blackout.pluck($_(this).html()) );});
var s = document.createElement("style");
s.innerHTML = ".sopa_blackout, .sopa_blackout:hover {display:inline-block; font-size: inherit !important; box-shadow: 0 1px 2px rgba(0,0,0,.12); text-decoration: none !important;"+ ($_.sopa_blackout.settings.hide_bg ? "background-image: none !important;" : "") +"} .bg_sopa_blackout {box-shadow: 0 1px 2px rgba(0,0,0,.12); "+ ($_.sopa_blackout.settings.hide_bg ? "background-image: none !important;" : "") +"}";
$_('head').append(s);
$_.sopa_blackout.settings.href = location.href;
$_.sopa_blackout.settings.page_height = $_('body').height();
$_.sopa_blackout.settings.finish = true;
}
});
})($_);
if (localStorage) {
if (localStorage.disable_sopa_blackout != '1' || !Stop_SOPA.promote) {
$_.sopa_blackout('body', Stop_SOPA.color);
}
if (!!Stop_SOPA.promote) {
var html = '';
if (localStorage.disable_sopa_blackout == '1') {
html = ' \
<div id="sopa_blackout_promote" class="skip_stop_sopa" style="position: fixed; z-index: 3000; top: 0; right: 0;"> \
<a onmouseover="this.style.opacity=.64;" onmouseout="this.style.opacity=1.0;" style="display: inline-block; margin: 5px; padding: 8px 8px 7px 8px; font: 18px/18px normal Helvetica,Arial,sans-serif; font-weight: bold; color: #fff; background: #f0f; text-shadow: 0 1px 2px rgba(0,0,0,.18); box-shadow: 0 1px 2px rgba(0,0,0,.18); font-weight: bold; border: 1px solid #f0f; border-radius: 7px;" href="http://bit.ly/FATSOPA" title="http://fightforthefuture.org/" target="_blank" id="sopa_blackout_action">STOP SOPA!</a> \
</div> \
';
setInterval(function() {
var el = $_('#sopa_blackout_promote a');
if (el.size() > 0) {
if (el.hasClass('sopa_ff0')) {
el.removeClass('sopa_ff0').addClass('sopa_f0f').css({'background-color':'#f0f', 'color':'#fff', 'border-color':'#f0f'});
} else {
el.removeClass('sopa_f0f').addClass('sopa_ff0').css({'background-color':'#ff0', 'color':'#000', 'border-color':'#ff0'});
}
}
}, 1000);
} else {
html = ' \
<div id="sopa_blackout_promote" class="skip_stop_sopa" style="position: fixed; z-index: 3000; top: 30%; left: 0; right: 0;"> \
<div style="width: 550px; margin: 0 auto; padding: 14px; background: #ff0; border-radius: 10px; border: 9px solid #ff0; box-shadow: 0px 3px 5px rgba(0,0,0,.24);"> \
<h1 style="text-align: center; font: 24px/29px bold Helvetica,Arial,sans-serif; color: #000; margin: 0; padding: 0 0 4px 0; font-weight: bold; ">Prevent Online Censorship!</h1> \
<p style="text-align: center; font: 17px/21px normal Helvetica,Arial,sans-serif; color: #222; margin: 0; padding: 0 0 4px 0; font-weight: bold;">This and many other web sites could disappear under SOPA!</p> \
<p style="text-align: left;font: 13px/19px normal Helvetica,Arial,sans-serif; color: #222; margin: 0; padding: 0 0 4px 0;">Speak up and voice your concerns against SOPA ("Stop Online Piracy Act"), a terrible piece of Congressional legislation that gives broad powers for the courts to take down sites by claims from "infringed" users.</p> \
<div style="text-align: center; padding: 14px 0 0 0; margin: 0;"> \
<a onmouseover="this.style.opacity=.64;" onmouseout="this.style.opacity=1.0;" style="display: inline-block; margin: 0 5px; padding: 8px 8px; font: 18px/18px normal Helvetica,Arial,sans-serif; font-weight: bold; color: #fff; background: #f0f; text-shadow: 0 1px 2px rgba(0,0,0,.18); box-shadow: 0 1px 2px rgba(0,0,0,.18); font-weight: bold; border: 1px solid #f0f; border-radius: 7px;" href="http://americancensorship.org/" title="http://americancensorship.org/" target="_blank" id="sopa_blackout_action">Make Some Noise</a> \
<a onmouseover="this.style.opacity=.64;" onmouseout="this.style.opacity=1.0;" style="display: inline-block; margin: 0 5px; padding: 8px 8px; font: 18px/18px normal Helvetica,Arial,sans-serif; font-weight: bold; color: #444; background: #ddd; text-shadow: 0 1px 2px rgba(0,0,0,.18); box-shadow: 0 1px 2px rgba(0,0,0,.18); font-weight: bold; border: 1px solid #ddd; border-radius: 7px;" href="javascript:;" id="sopa_blackout_skip">No Thanks</a> \
</div> \
</div> \
</div> \
';
}
if ($_('#sopa_blackout_promote').size() <= 0) $_('body').append(html);
$_('#sopa_blackout_action, #sopa_blackout_skip').click(function() {
if (localStorage.disable_sopa_blackout != '1') {
$_('#sopa_blackout_promote').remove();
localStorage.disable_sopa_blackout = '1';
window.location.reload();
}
return true;
});
}
}
if (!localStorage.disable_sopa_blackout) {
/* Allow AJAX detection */
setInterval(function() {
var h = $_('body').height(), ch = $_.sopa_blackout.settings.page_height;
if (location.href != $_.sopa_blackout.settings.href || Math.abs(ch-h) > 20 ) {
$_.sopa_blackout.settings.href = location.href;
$_.sopa_blackout.settings.page_height = h;
$_.sopa_blackout.settings.init = false;
$_.sopa_blackout.settings.finish = false;
$_.sopa_blackout('body', Stop_SOPA.color);
}
}, 1000);
}
};
/* STOP SOPA!! */
try {
if (typeof(jQuery) == 'undefined') {
document.write('<scr'+'ipt src="'+ ("https:" == document.location.protocol ? 'https:' : 'http:') +'//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></scr'+'ipt>');
}
if (typeof(Stop_SOPA) != 'object') var Stop_SOPA = {promote:true};
if (typeof(Stop_SOPA.promote) == 'undefined') Stop_SOPA.promote = true;
if (typeof(Stop_SOPA.color) == 'undefined') Stop_SOPA.color = '#000000';
setTimeout(function() {
try {
jQuery.noConflict();
if (!jQuery('body').hasClass('stop_sopa_blackout')) {
jQuery('body').addClass('stop_sopa_blackout');
sopa_blackout_start(jQuery);
}
} catch(err) {}
}, (typeof(jQuery) == 'undefined' ? 1000 : 100));
} catch(err) {}