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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
|
/*
*
* This file is part of Privacy Badger <https://www.eff.org/privacybadger>
* Copyright (C) 2016 Electronic Frontier Foundation
*
* Privacy Badger is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* Privacy Badger is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Privacy Badger. If not, see <http://www.gnu.org/licenses/>.
*/
require.scopes.surrogatedb = (function() {
/**
* A hostname can have one or more surrogate scripts.
*
* "hostnames" maps hostnames to surrogate pattern tokens.
*
* Surrogate pattern tokens are used to look up the actual
* surrogate script code (stored in "surrogates" object below).
*
* There are currently two types of surrogate pattern tokens:
*
* - {Array} one or more suffix tokens:
* Does the script URL (querystring excluded) end with the token?
*
* - {String} wildcard token:
* Matches any script URL for the hostname.
*/
const hostnames = {
'b.scorecardresearch.com': [
'/beacon.js',
'/c2/plugins/streamsense_plugin_html5.js',
],
'sb.scorecardresearch.com': [
'/beacon.js',
'/c2/plugins/streamsense_plugin_html5.js',
],
'ssl.google-analytics.com': [
'/ga.js',
'/analytics.js',
],
'www.google-analytics.com': [
'/analytics.js',
'/ga.js',
],
'www.googletagservices.com': [
'/gpt.js',
],
'api.youneeq.ca': [
'/app/yqmin',
],
'cdn.krxd.net': 'noopjs',
'widgets.outbrain.com': '/outbrain.js',
};
/**
* "surrogates" maps surrogate pattern tokens to surrogate script code.
*/
const surrogates = {
/* eslint-disable no-extra-semi, space-in-parens */
// Google Analytics (legacy ga.js)
//
// sourced from https://github.com/uBlockOrigin/uAssets/ under GPLv3
// https://github.com/uBlockOrigin/uAssets/blob/2dfeece7cfe671e93573db6d176901cf2df37623/filters/resources.txt#L162-L260
//
// test cases:
// http://checkin.avianca.com/
// https://www.vmware.com/support/pubs/ws_pubs.html (release notes links)
//
// API reference:
// https://developers.google.com/analytics/devguides/collection/gajs/methods/
'/ga.js': '(' +
function() {
var noopfn = function() {
;
};
//
var Gaq = function() {
;
};
Gaq.prototype.Na = noopfn;
Gaq.prototype.O = noopfn;
Gaq.prototype.Sa = noopfn;
Gaq.prototype.Ta = noopfn;
Gaq.prototype.Va = noopfn;
Gaq.prototype._createAsyncTracker = noopfn;
Gaq.prototype._getAsyncTracker = noopfn;
Gaq.prototype._getPlugin = noopfn;
Gaq.prototype.push = function(a) {
if ( typeof a === 'function' ) {
a(); return;
}
if ( Array.isArray(a) === false ) {
return;
}
// https://twitter.com/catovitch/status/776442930345218048
// https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiDomainDirectory#_gat.GA_Tracker_._link
if ( a[0] === '_link' && typeof a[1] === 'string' ) {
window.location.assign(a[1]);
}
// https://github.com/gorhill/uBlock/issues/2162
if ( a[0] === '_set' && a[1] === 'hitCallback' && typeof a[2] === 'function' ) {
a[2]();
}
};
//
var tracker = (function() {
var out = {};
var api = [
'_addIgnoredOrganic _addIgnoredRef _addItem _addOrganic',
'_addTrans _clearIgnoredOrganic _clearIgnoredRef _clearOrganic',
'_cookiePathCopy _deleteCustomVar _getName _setAccount',
'_getAccount _getClientInfo _getDetectFlash _getDetectTitle',
'_getLinkerUrl _getLocalGifPath _getServiceMode _getVersion',
'_getVisitorCustomVar _initData _link _linkByPost',
'_setAllowAnchor _setAllowHash _setAllowLinker _setCampContentKey',
'_setCampMediumKey _setCampNameKey _setCampNOKey _setCampSourceKey',
'_setCampTermKey _setCampaignCookieTimeout _setCampaignTrack _setClientInfo',
'_setCookiePath _setCookiePersistence _setCookieTimeout _setCustomVar',
'_setDetectFlash _setDetectTitle _setDomainName _setLocalGifPath',
'_setLocalRemoteServerMode _setLocalServerMode _setReferrerOverride _setRemoteServerMode',
'_setSampleRate _setSessionTimeout _setSiteSpeedSampleRate _setSessionCookieTimeout',
'_setVar _setVisitorCookieTimeout _trackEvent _trackPageLoadTime',
'_trackPageview _trackSocial _trackTiming _trackTrans',
'_visitCode'
].join(' ').split(/\s+/);
var i = api.length;
while ( i-- ) {
out[api[i]] = noopfn;
}
out._getLinkerUrl = function(a) {
return a;
};
return out;
})();
//
var Gat = function() {
;
};
Gat.prototype._anonymizeIP = noopfn;
Gat.prototype._createTracker = noopfn;
Gat.prototype._forceSSL = noopfn;
Gat.prototype._getPlugin = noopfn;
Gat.prototype._getTracker = function() {
return tracker;
};
Gat.prototype._getTrackerByName = function() {
return tracker;
};
Gat.prototype._getTrackers = noopfn;
Gat.prototype.aa = noopfn;
Gat.prototype.ab = noopfn;
Gat.prototype.hb = noopfn;
Gat.prototype.la = noopfn;
Gat.prototype.oa = noopfn;
Gat.prototype.pa = noopfn;
Gat.prototype.u = noopfn;
var gat = new Gat();
window._gat = gat;
//
var gaq = new Gaq();
(function() {
var aa = window._gaq || [];
if ( Array.isArray(aa) ) {
while ( aa[0] ) {
gaq.push(aa.shift());
}
}
})();
window._gaq = gaq.qf = gaq;
} + ')();',
// https://github.com/gorhill/uBlock/issues/1265
// https://github.com/uBlockOrigin/uAssets/blob/581f2c93eeca0e55991aa331721b6942f3162615/filters/resources.txt#L736-L746
/* eslint-disable no-undef */
'/beacon.js': '(' +
function() {
window.COMSCORE = {
purge: function() {
_comscore = [];
},
beacon: function() {
;
}
};
} + ')();',
/* eslint-enable no-undef */
// http://www.dplay.se/ett-jobb-for-berg/ (videos)
'/c2/plugins/streamsense_plugin_html5.js': '(' +
function() {
} + ')();',
// https://github.com/EFForg/privacybadger/issues/993
// https://github.com/uBlockOrigin/uAssets/blob/2bc97541b3b9a9380b3ce8bd2242375925df293c/filters/resources.txt#L436-L567
/* eslint-disable no-empty */
'/gpt.js': '(' +
function() {
var p;
// https://developers.google.com/doubleclick-gpt/reference
var noopfn = function() {
;
}.bind();
var noopthisfn = function() {
return this;
};
var noopnullfn = function() {
return null;
};
var nooparrayfn = function() {
return [];
};
var noopstrfn = function() {
return '';
};
//
var companionAdsService = {
addEventListener: noopthisfn,
enableSyncLoading: noopfn,
setRefreshUnfilledSlots: noopfn
};
var contentService = {
addEventListener: noopthisfn,
setContent: noopfn
};
var PassbackSlot = function() {
;
};
p = PassbackSlot.prototype;
p.display = noopfn;
p.get = noopnullfn;
p.set = noopthisfn;
p.setClickUrl = noopthisfn;
p.setTagForChildDirectedTreatment = noopthisfn;
p.setTargeting = noopthisfn;
p.updateTargetingFromMap = noopthisfn;
var pubAdsService = {
addEventListener: noopthisfn,
clear: noopfn,
clearCategoryExclusions: noopthisfn,
clearTagForChildDirectedTreatment: noopthisfn,
clearTargeting: noopthisfn,
collapseEmptyDivs: noopfn,
defineOutOfPagePassback: function() { return new PassbackSlot(); },
definePassback: function() { return new PassbackSlot(); },
disableInitialLoad: noopfn,
display: noopfn,
enableAsyncRendering: noopfn,
enableSingleRequest: noopfn,
enableSyncRendering: noopfn,
enableVideoAds: noopfn,
get: noopnullfn,
getAttributeKeys: nooparrayfn,
getTargeting: noopfn,
getTargetingKeys: nooparrayfn,
getSlots: nooparrayfn,
refresh: noopfn,
set: noopthisfn,
setCategoryExclusion: noopthisfn,
setCentering: noopfn,
setCookieOptions: noopthisfn,
setForceSafeFrame: noopthisfn,
setLocation: noopthisfn,
setPublisherProvidedId: noopthisfn,
setRequestNonPersonalizedAds: noopthisfn,
setSafeFrameConfig: noopthisfn,
setTagForChildDirectedTreatment: noopthisfn,
setTargeting: noopthisfn,
setVideoContent: noopthisfn,
updateCorrelator: noopfn
};
var SizeMappingBuilder = function() {
;
};
p = SizeMappingBuilder.prototype;
p.addSize = noopthisfn;
p.build = noopnullfn;
var Slot = function() {
;
};
p = Slot.prototype;
p.addService = noopthisfn;
p.clearCategoryExclusions = noopthisfn;
p.clearTargeting = noopthisfn;
p.defineSizeMapping = noopthisfn;
p.get = noopnullfn;
p.getAdUnitPath = nooparrayfn;
p.getAttributeKeys = nooparrayfn;
p.getCategoryExclusions = nooparrayfn;
p.getDomId = noopstrfn;
p.getSlotElementId = noopstrfn;
p.getSlotId = noopthisfn;
p.getTargeting = nooparrayfn;
p.getTargetingKeys = nooparrayfn;
p.set = noopthisfn;
p.setCategoryExclusion = noopthisfn;
p.setClickUrl = noopthisfn;
p.setCollapseEmptyDiv = noopthisfn;
p.setTargeting = noopthisfn;
//
var gpt = window.googletag || {};
var cmd = gpt.cmd || [];
gpt.apiReady = true;
gpt.cmd = [];
gpt.cmd.push = function(a) {
try {
a();
} catch (ex) {
}
return 1;
};
gpt.companionAds = function() { return companionAdsService; };
gpt.content = function() { return contentService; };
gpt.defineOutOfPageSlot = function() { return new Slot(); };
gpt.defineSlot = function() { return new Slot(); };
gpt.destroySlots = noopfn;
gpt.disablePublisherConsole = noopfn;
gpt.display = noopfn;
gpt.enableServices = noopfn;
gpt.getVersion = noopstrfn;
gpt.pubads = function() { return pubAdsService; };
gpt.pubadsReady = true;
gpt.setAdIframeTitle = noopfn;
gpt.sizeMapping = function() { return new SizeMappingBuilder(); };
window.googletag = gpt;
while ( cmd.length !== 0 ) {
gpt.cmd.push(cmd.shift());
}
} + ')();',
/* eslint-enable no-empty */
// https://github.com/EFForg/privacybadger/issues/1014
/* eslint-disable no-unused-expressions */
'/app/yqmin': '(' +
function() {
var noopfn = function() {
;
};
function YqClass() {
this.observe = noopfn;
this.observeMin = noopfn;
this.scroll_event = noopfn;
this.onready = noopfn;
this.yq_panel_click = noopfn;
this.titleTrim = noopfn;
}
window.Yq || (window.Yq = new YqClass);
} + ')();',
/* eslint-enable no-unused-expressions */
// https://github.com/uBlockOrigin/uAssets/blob/0e225402b40db0983faf8b4ce13c73d57fb257d7/filters/resources.txt#L354-L403
/* eslint-disable no-empty */
'/analytics.js': '(' +
function() {
// https://developers.google.com/analytics/devguides/collection/analyticsjs/
var noopfn = function() {
;
};
var noopnullfn = function() {
return null;
};
//
var Tracker = function() {
;
};
var p = Tracker.prototype;
p.get = noopfn;
p.set = noopfn;
p.send = noopfn;
//
var w = window,
gaName = w.GoogleAnalyticsObject || 'ga';
var ga = function() {
var len = arguments.length;
if ( len === 0 ) {
return;
}
var f = arguments[len-1];
if ( typeof f !== 'object' || f === null || typeof f.hitCallback !== 'function' ) {
return;
}
try {
f.hitCallback();
} catch (ex) {
}
};
ga.create = function() {
return new Tracker();
};
ga.getByName = noopnullfn;
ga.getAll = function() {
return [];
};
ga.remove = noopfn;
// https://github.com/uBlockOrigin/uAssets/issues/2107
ga.loaded = true;
w[gaName] = ga;
// https://github.com/gorhill/uBlock/issues/3075
var dl = w.dataLayer;
if ( dl instanceof Object && dl.hide instanceof Object && typeof dl.hide.end === 'function' ) {
dl.hide.end();
}
} + ')();',
/* eslint-enable no-empty */
// https://github.com/uBlockOrigin/uAssets/blob/d7d4836638dcf227938b4cead66ad9d01b6166ba/filters/resources.txt#L843-L868
'/outbrain.js': '(' +
function() {
var noopfn = function() {
;
};
var obr = {};
var methods = [
'callClick', 'callLoadMore', 'callRecs', 'callUserZapping',
'callWhatIs', 'cancelRecommendation', 'cancelRecs', 'closeCard',
'closeModal', 'closeTbx', 'errorInjectionHandler', 'getCountOfRecs',
'getStat', 'imageError', 'manualVideoClicked', 'onOdbReturn',
'onVideoClick', 'pagerLoad', 'recClicked', 'refreshSpecificWidget',
'refreshWidget', 'reloadWidget', 'researchWidget', 'returnedError',
'returnedHtmlData', 'returnedIrdData', 'returnedJsonData', 'scrollLoad',
'showDescription', 'showRecInIframe', 'userZappingMessage', 'zappingFormAction'
];
obr.extern = {
video: {
getVideoRecs: noopfn,
videoClicked: noopfn
}
};
methods.forEach(function(a) {
obr.extern[a] = noopfn;
});
window.OBR = window.OBR || obr;
} + ')();',
// https://github.com/uBlockOrigin/uAssets/blob/0efcadb2ecc2a9f0daa5a1df79841d794b83860f/filters/resources.txt#L38-L41
'noopjs': '(' +
function() {
;
} + ')();',
/* eslint-enable no-extra-semi, space-in-parens */
};
// aliases
// for example:
// surrogates['/JS/socialize.js'] = surrogates['/JS/gigya.js'] = surrogates['/js/gigya.js'];
// reformat surrogate strings to exactly match formatting in uAssets
Object.keys(surrogates).forEach(key => {
surrogates[key] = surrogates[key]
// remove space from anon function if present
.replace(/^\(function \(/, '(function(')
// fix indentation
.split(/[\r\n]/).map(str => str.replace(/^ {4}/, '')).join('\n')
// replace spaces by tabs
.replace(/ {2}/g, '\t');
});
const exports = {
hostnames: hostnames,
surrogates: surrogates,
};
return exports;
})();
|