File tree 1 file changed +23
-2
lines changed
readthedocs/core/static-src/core/js/doc-embed
1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -163,6 +163,27 @@ Promo.prototype.post_promo_display = function () {
163
163
}
164
164
} ;
165
165
166
+ function detect_adblock ( ) {
167
+ // Status codes are not correctly reported on JSONP requests
168
+ // So we resort to different ways to detect adblockers
169
+ var detected = false ;
170
+
171
+ // Check if our ad element is blocked
172
+ $ ( '<div />' )
173
+ . attr ( 'id' , 'rtd-detection' )
174
+ . attr ( 'class' , 'ethical-rtd' )
175
+ . html ( ' ' )
176
+ . appendTo ( 'body' ) ;
177
+ if ( $ ( '#rtd-detection' ) . height ( ) === 0 ) {
178
+ detected = true ;
179
+ }
180
+
181
+ // Remove the test element regardless
182
+ $ ( '#rtd-detection' ) . remove ( ) ;
183
+
184
+ return detected ;
185
+ }
186
+
166
187
function adblock_admonition ( ) {
167
188
console . log ( '---------------------------------------------------------------------------------------' ) ;
168
189
console . log ( 'Read the Docs hosts documentation for tens of thousands of open source projects.' ) ;
@@ -256,10 +277,10 @@ function init() {
256
277
promo . display ( ) ;
257
278
}
258
279
} ,
259
- error : function ( xhr , textStatus , errorThrown ) {
280
+ error : function ( ) {
260
281
console . error ( 'Error loading Read the Docs promo' ) ;
261
282
262
- if ( ! rtddata . ad_free && xhr && xhr . status === 404 && rtd . api_host === 'https://readthedocs.org' ) {
283
+ if ( ! rtddata . ad_free && rtd . api_host === 'https://readthedocs.org' && detect_adblock ( ) ) {
263
284
adblock_admonition ( ) ;
264
285
adblock_nag ( ) ;
265
286
}
You can’t perform that action at this time.
0 commit comments