/
adblock-background.js
842 lines (750 loc) · 22.7 KB
/
adblock-background.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
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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
var getDecodedHostname = require('url').getDecodedHostname;
with (require('filterClasses'))
{
this.Filter = Filter;
this.WhitelistFilter = WhitelistFilter;
}
with (require('subscriptionClasses'))
{
this.Subscription = Subscription;
this.SpecialSubscription = SpecialSubscription;
this.DownloadableSubscription = DownloadableSubscription;
}
with (require('filterValidation'))
{
this.parseFilter = parseFilter;
this.parseFilters = parseFilters;
}
var FilterStorage = require('filterStorage').FilterStorage;
var FilterNotifier = require('filterNotifier').FilterNotifier;
var Prefs = require('prefs').Prefs;
var Synchronizer = require('synchronizer').Synchronizer;
var Utils = require('utils').Utils;
var NotificationStorage = require('notification').Notification;
var punycode = require("punycode");
// TODO
// Temporary...
var SAFARI = false;
// CUSTOM FILTERS
// Creates a custom filter entry that whitelists a given page
// Inputs: url:string url of the page
// Returns: null if successful, otherwise an exception
var createPageWhitelistFilter = function (url)
{
var url = url.replace(/#.*$/, ''); // Remove anchors
var parts = url.match(/^([^\?]+)(\??)/); // Detect querystring
var hasQuerystring = parts[2];
var filter = '@@|' + parts[1] + (hasQuerystring ? '?' : '|') + '$document';
return addCustomFilter(filter);
};
// UNWHITELISTING
// Look for a custom filter that would whitelist the 'url' parameter
// and if any exist, remove the first one.
// Inputs: url:string - a URL that may be whitelisted by a custom filter
// Returns: true if a filter was found and removed; false otherwise.
var tryToUnwhitelist = function (url)
{
url = url.replace(/#.*$/, ''); // Whitelist ignores anchors
var customFilters = getUserFilters();
if (!customFilters || !customFilters.length === 0)
{
return false;
}
for (var i = 0; i < customFilters.length; i++)
{
var text = customFilters[i];
var whitelist = text.search(/@@\*\$document,domain=\~/);
// Blacklist site, which is whitelisted by global @@*&document,domain=~
// filter
if (whitelist > -1)
{
// Remove protocols
url = url.replace(/((http|https):\/\/)?(www.)?/, '').split(/[/?#]/)[0];
var oldFilter = Filter.fromText(text);
FilterStorage.removeFilter(oldFilter);
var newFilter = Filter.fromText(text + '|~' + url);
FilterStorage.addFilter(newFilter);
return true;
} else
{
if (!isWhitelistFilter(text))
{
continue;
}
try
{
var filter = Filter.fromText(text);
}
catch (ex)
{
continue;
}
if (!filter.matches(url, RegExpFilter.typeMap.DOCUMENT, false))
{
continue;
}
FilterStorage.removeFilter(filter);
return true;
}
}
return false;
};
// Add a new custom filter entry.
// Inputs: filter:string line of text to add to custom filters.
// Returns: null if succesfull, otherwise an exception
var addCustomFilter = function (filterText)
{
try
{
var filter = Filter.fromText(filterText);
FilterStorage.addFilter(filter);
if (isSelectorFilter(filterText))
{
countCache.addCustomFilterCount(filterText);
}
return null;
}
catch (ex)
{
// convert to a string so that Safari can pass
// it back to content scripts
return ex.toString();
}
};
// Removes a custom filter entry.
// Inputs: host:domain of the custom filters to be reset.
var removeCustomFilter = function (host)
{
var customFilters = getUserFilters();
if (!customFilters || !customFilters.length === 0)
{
return false;
}
var identifier = host;
for (var i = 0; i < customFilters.length; i++)
{
var entry = customFilters[i];
// If the identifier is at the start of the entry
// then delete it.
if (entry.indexOf(identifier) === 0)
{
var filter = Filter.fromText(entry);
FilterStorage.removeFilter(filter);
}
}
};
// custom filter countCache singleton.
var countCache = (function ()
{
var cache;
// Update custom filter count stored in localStorage
var _updateCustomFilterCount = function ()
{
ext.storage.set('custom_filter_count', cache);
};
return {
// Update custom filter count cache and value stored in localStorage.
// Inputs: new_count_map:count map - count map to replace existing count
// cache
updateCustomFilterCountMap: function (newCountMap)
{
cache = newCountMap || cache;
_updateCustomFilterCount();
},
// Remove custom filter count for host
// Inputs: host:string - url of the host
removeCustomFilterCount: function (host)
{
if (host && cache[host])
{
delete cache[host];
_updateCustomFilterCount();
}
},
// Get current custom filter count for a particular domain
// Inputs: host:string - url of the host
getCustomFilterCount: function (host)
{
return cache[host] || 0;
},
// Add 1 to custom filter count for the filters domain.
// Inputs: filter:string - line of text to be added to custom filters.
addCustomFilterCount: function (filter)
{
var host = filter.split('##')[0];
cache[host] = this.getCustomFilterCount(host) + 1;
_updateCustomFilterCount();
},
init: function ()
{
ext.storage.get('custom_filter_count', function (response)
{
cache = response.custom_filter_count || {};
});
},
};
})();
countCache.init();
// Entry point for customize.js, used to update custom filter count cache.
var updateCustomFilterCountMap = function (newCountMap)
{
countCache.updateCustomFilterCountMap(newCountMap);
};
var removeCustomFilterForHost = function (host)
{
if (countCache.getCustomFilterCount(host))
{
removeCustomFilter(host);
countCache.removeCustomFilterCount(host);
}
};
var confirmRemovalOfCustomFiltersOnHost = function (host, activeTab)
{
var customFilterCount = countCache.getCustomFilterCount(host);
var confirmationText = translate('confirm_undo_custom_filters', [customFilterCount, host]);
if (!confirm(confirmationText))
{
return;
}
removeCustomFilterForHost(host);
if (!SAFARI)
{
chrome.tabs.reload(activeTab.id);
} else
{
activeTab.url = activeTab.url;
}
};
// Reload already opened tab
// Input:
// tabId: integer - id of the tab which should be reloaded
var reloadTab = function(tabId, callback) {
var localCallback = callback;
var listener = function (tabId, changeInfo, tab) {
if (changeInfo.status === 'complete' &&
tab.status === 'complete') {
setTimeout(function () {
chrome.tabs.sendMessage(tabId, { command: 'reloadcomplete' });
if (typeof localCallback === "function") {
localCallback(tab);
}
chrome.tabs.onUpdated.removeListener(listener);
}, 2000);
}
};
if (typeof tabId === 'string') {
tabId = parseInt(tabId);
}
chrome.tabs.onUpdated.addListener(listener);
chrome.tabs.reload(tabId, { bypassCache: true }, function () {
});
};
var isSelectorFilter = function (text)
{
// This returns true for both hiding rules as hiding whitelist rules
// This means that you'll first have to check if something is an excluded rule
// before checking this, if the difference matters.
return /\#\@?\#./.test(text);
};
var isWhitelistFilter = function (text)
{
return /^\@\@/.test(text);
};
var isSelectorExcludeFilter = function (text)
{
return /\#\@\#./.test(text);
};
// BGcall DISPATCH
(function ()
{
ext.onMessage.addListener(function (message, sender, sendResponse)
{
if (message.command != 'call')
return; // not for us
var fn = window[message.fn];
if (!fn)
{
console.log('FN not found, message', message, sender);
}
if (message.args && message.args.push)
{
message.args.push(sender);
}
var result = fn.apply(window, message.args);
sendResponse(result);
});
})();
var getAdblockUserId = function ()
{
return STATS.userId();
};
// passthrough functions
var addGABTabListeners = function (sender)
{
gabQuestion.addGABTabListeners(sender);
};
var removeGABTabListeners = function (saveState)
{
gabQuestion.removeGABTabListeners(saveState);
};
// INFO ABOUT CURRENT PAGE
// Get interesting information about the current tab.
// Inputs:
// callback: function(info).
// info object passed to callback: {
// tab: Tab object
// whitelisted: bool - whether the current tab's URL is whitelisted.
// disabled_site: bool - true if the url is e.g. about:blank or the
// Extension Gallery, where extensions don't run.
// total_blocked: int - # of ads blocked since install
// tab_blocked: int - # of ads blocked on this tab
// display_stats: bool - whether block counts are displayed on button
// display_menu_stats: bool - whether block counts are displayed on the popup
// menu
// }
// Returns: null (asynchronous)
var getCurrentTabInfo = function (callback, secondTime)
{
ext.pages.query(
{
active: true,
lastFocusedWindow: true,
}, function (pages)
{
if (pages.length === 0)
{
return; // For example: only the background devtools or a popup are opened
}
page = pages[0];
if (page && !page.url)
{
// Issue 6877: tab URL is not set directly after you opened a window
// using window.open()
if (!secondTime)
window.setTimeout(function ()
{
getCurrentTabInfo(callback, true);
}, 250);
return;
}
page.unicodeUrl = getUnicodeUrl(page.url.href);
var disabledSite = pageIsUnblockable(page.unicodeUrl);
var displayStats = Prefs.show_statsinicon;
var result =
{
page: page,
disabledSite: disabledSite,
settings: getSettings()
};
if (!disabledSite)
{
result.whitelisted = checkWhitelisted(page);
}
callback(result);
});
};
// Returns true if the url cannot be blocked
var pageIsUnblockable = function (url)
{
if (!url)
{ // Safari empty/bookmarks/top sites page
return true;
} else
{
var scheme = '';
if (!url.protocol)
{
scheme = parseUri(url).protocol;
} else
{
scheme = url.protocol;
}
return (scheme !== 'http:' && scheme !== 'https:' && scheme !== 'feed:');
}
};
// Returns true if the page is whitelisted.
// Called from a content script
var pageIsWhitelisted = function(sender)
{
return (checkWhitelisted(sender.page) != undefined);
}
// Get or set if AdBlock is paused
// Inputs: newValue (optional boolean): if true, AdBlock will be paused, if
// false, AdBlock will not be paused.
// Returns: undefined if newValue was specified, otherwise it returns true
// if paused, false otherwise.
var pausedKey = 'paused';
var pausedFilterText1 = '@@'; // white-list all blocking requests regardless of frame / document, but still allows element hiding
var pausedFilterText2 = '@@^$document'; // white-list all documents, which prevents element hiding
var adblockIsPaused = function (newValue)
{
if (newValue === undefined)
{
return (sessionstorage_get(pausedKey) === true);
}
// Add a filter to white list every page.
var result1 = parseFilter(pausedFilterText1);
var result2 = parseFilter(pausedFilterText2);
if (newValue === true)
{
FilterStorage.addFilter(result1.filter);
FilterStorage.addFilter(result2.filter);
ext.storage.set(pausedKey, true);
} else
{
FilterStorage.removeFilter(result1.filter);
FilterStorage.removeFilter(result2.filter);
ext.storage.remove(pausedKey);
}
sessionstorage_set(pausedKey, newValue);
};
// If AdBlock was paused on shutdown (adblock_is_paused is true), then
// unpause / remove the white-list all entry at startup.
ext.storage.get(pausedKey, function (response)
{
if (response[pausedKey])
{
var pauseHandler = function (action)
{
if (action == 'load')
{
FilterNotifier.removeListener(pauseHandler);
var result1 = parseFilter(pausedFilterText1);
var result2 = parseFilter(pausedFilterText2);
FilterStorage.removeFilter(result1.filter);
FilterStorage.removeFilter(result2.filter);
ext.storage.remove(pausedKey);
}
};
FilterNotifier.addListener(pauseHandler);
}
});
// Return the contents of a local file.
// Inputs: file:string - the file relative address, eg "js/foo.js".
// Returns: the content of the file.
var readfile = function (file)
{
// A bug in jquery prevents local files from being read, so use XHR.
var xhr = new XMLHttpRequest();
xhr.open('GET', chrome.extension.getURL(file), false);
xhr.send();
return xhr.responseText;
};
// BETA CODE
if (!SAFARI && chrome.runtime.id === 'pljaalgmajnlogcgiohkhdmgpomjcihk')
{
// Display beta page after each update for beta-users only
chrome.runtime.onInstalled.addListener(function (details)
{
if (details.reason === 'update' || details.reason === 'install')
{
ext.pages.open('https://getadblock.com/beta');
}
});
}
var updateStorageKey = 'last_known_version';
chrome.runtime.onInstalled.addListener(function (details)
{
if (details.reason === 'update' || details.reason === 'install')
{
localStorage.setItem(updateStorageKey, chrome.runtime.getManifest().version);
}
});
var openTab = function (url)
{
ext.pages.open(url);
};
// Creates a custom filter entry that whitelists a YouTube channel
// Inputs: url:string url of the page
// Returns: null if successful, otherwise an exception
var createWhitelistFilterForYoutubeChannel = function (url)
{
if (/ab_channel=/.test(url))
{
var ytChannel = url.match(/ab_channel=([^]*)/)[1];
} else
{
var ytChannel = url.split('/').pop();
}
if (ytChannel)
{
var filter = '@@|https://www.youtube.com/*' + ytChannel + '|$document';
return addCustomFilter(filter);
}
};
// YouTube Channel Whitelist and AdBlock Bandaids
// Script injection logic for Safari is done in safari_bg.js
if (!SAFARI)
{
var runChannelWhitelist = function (tabUrl, tabId)
{
if (parseUri(tabUrl).hostname === 'www.youtube.com' && getSettings().youtube_channel_whitelist && !parseUri.parseSearch(tabUrl).ab_channel)
{
chrome.tabs.executeScript(tabId,
{
file: 'adblock-ytchannel.js',
runAt: 'document_start',
});
}
};
chrome.tabs.onCreated.addListener(function (tab)
{
if (chrome.runtime.lastError)
{
return;
}
chrome.tabs.get(tab.id, function (tabs)
{
if (chrome.runtime.lastError)
{
return;
}
if (tabs && tabs.url && tabs.id)
{
runChannelWhitelist(tabs.url, tabs.id);
}
});
});
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab)
{
if (chrome.runtime.lastError)
{
return;
}
if (changeInfo.status === 'loading')
{
if (chrome.runtime.lastError)
{
return;
}
chrome.tabs.get(tabId, function (tabs)
{
if (tabs && tabs.url && tabs.id)
{
runChannelWhitelist(tabs.url, tabs.id);
}
});
}
});
// On single page sites, such as YouTube, that update the URL using the History API pushState(),
// they don't actually load a new page, we need to get notified when this happens
// and update the URLs in the Page and Frame objects
var youTubeHistoryStateUpdateHanlder = function(details) {
if (details &&
details.hasOwnProperty("frameId") &&
details.hasOwnProperty("tabId") &&
details.hasOwnProperty("url") &&
details.hasOwnProperty("transitionType") &&
details.transitionType === "link")
{
var myURL = new URL(details.url);
if (myURL.hostname === "www.youtube.com")
{
var myFrame = ext.getFrame(details.tabId, details.frameId);
var myPage = ext.getPage(details.tabId);
var previousWhitelistState = checkWhitelisted(myPage);
myPage.url = myURL;
myPage._url = myURL;
myFrame.url = myURL;
myFrame._url = myURL;
var currentWhitelistState = checkWhitelisted(myPage);
if (!currentWhitelistState && (currentWhitelistState !== previousWhitelistState)) {
myPage.sendMessage({type: "reloadStyleSheet"});
}
}
}
};
var addYouTubeHistoryStateUpdateHanlder = function() {
chrome.webNavigation.onHistoryStateUpdated.addListener(youTubeHistoryStateUpdateHanlder);
};
var removeYouTubeHistoryStateUpdateHanlder = function() {
chrome.webNavigation.onHistoryStateUpdated.removeListener(youTubeHistoryStateUpdateHanlder);
};
_settings.onload().then(function()
{
if (getSettings().youtube_channel_whitelist)
{
addYouTubeHistoryStateUpdateHanlder();
}
});
}
// used by the Options pages, since they don't have access to setContentBlocker
function isSafariContentBlockingAvailable()
{
return (SAFARI && safari && safari.extension && (typeof safari.extension.setContentBlocker === 'function'));
}
// These functions are usually only called by content scripts.
// DEBUG INFO
// Get debug info as a JSON object for bug reporting and ad reporting
var getDebugInfo = function (callback)
{
response = {};
response.other_info = {};
// Is this installed build of AdBlock the official one?
if (!SAFARI)
{
if (chrome.runtime.id === 'pljaalgmajnlogcgiohkhdmgpomjcihk')
{
response.other_info.buildtype = ' Beta';
} else if (chrome.runtime.id === 'gighmmpiobklfepjocnamgkkbiglidom' || chrome.runtime.id === 'aobdicepooefnbaeokijohmhjlleamfj')
{
response.other_info.buildtype = ' Stable';
} else
{
response.other_info.buildtype = ' Unofficial';
}
} else
{
if (safari.extension.baseURI.indexOf('com.betafish.adblockforsafari-UAMUU4S2D9') > -1)
{
response.other_info.buildtype = ' Stable';
} else
{
response.other_info.buildtype = ' Unofficial';
}
}
// Get AdBlock version
response.other_info.version = chrome.runtime.getManifest().version;
// Get subscribed filter lists
var subscriptionInfo = {};
var subscriptions = getSubscriptionsMinusText();
for (var id in subscriptions)
{
if (subscriptions[id].subscribed)
{
subscriptionInfo[id] = {};
subscriptionInfo[id].lastSuccess = new Date(subscriptions[id].lastSuccess * 1000);
subscriptionInfo[id].lastDownload = new Date(subscriptions[id].lastDownload * 1000);
subscriptionInfo[id].downloadCount = subscriptions[id].downloadCount;
subscriptionInfo[id].downloadStatus = subscriptions[id].downloadStatus;
}
}
response.subscriptions = subscriptionInfo;
var userFilters = getUserFilters();
if (userFilters && userFilters.length)
{
response.custom_filters = userFilters.join("\n");
}
// Get settings
var adblockSettings = {};
var settings = getSettings();
for (setting in settings)
{
adblockSettings[setting] = JSON.stringify(settings[setting]);
}
response.settings = adblockSettings;
response.prefs = JSON.stringify(Prefs);
response.other_info.browser = STATS.browser;
response.other_info.browserVersion = STATS.browserVersion;
response.other_info.osVersion = STATS.osVersion;
response.other_info.os = STATS.os;
if (window['blockCounts'])
{
response.other_info.blockCounts = blockCounts.get();
}
if (localStorage &&
localStorage.length) {
response.other_info.localStorageInfo = {};
response.other_info.localStorageInfo['length'] = localStorage.length;
var inx = 1;
for (var key in localStorage) {
response.other_info.localStorageInfo['key'+inx]= key;
inx++;
}
}
else
{
response.other_info.localStorageInfo = "no data";
}
response.other_info.is_adblock_paused = adblockIsPaused();
// Get total pings
ext.storage.get('total_pings', function (storageResponse)
{
response.other_info.total_pings = storageResponse.total_pings || 0;
// Now, add exclude filters (if there are any)
var excludeFiltersKey = 'exclude_filters';
chrome.storage.local.get(excludeFiltersKey, function (secondResponse)
{
if (secondResponse && secondResponse[excludeFiltersKey])
{
response.excluded_filters = secondResponse[excludeFiltersKey];
}
// Now, add the migration messages (if there are any)
var migrateLogMessageKey = 'migrateLogMessageKey';
chrome.storage.local.get(migrateLogMessageKey, function (thirdResponse)
{
if (thirdResponse && thirdResponse[migrateLogMessageKey])
{
messages = thirdResponse[migrateLogMessageKey].split('\n');
for (var i = 0; i < messages.length; i++)
{
var key = 'migration_message_' + i;
response.other_info[key] = messages[i];
}
}
if (callback)
{
callback(response);
}
});
});
});
};
// Called when user explicitly requests filter list updates
function updateFilterLists()
{
for (var i = 0; i < FilterStorage.subscriptions.length; i++)
{
var subscription = FilterStorage.subscriptions[i];
if (subscription instanceof DownloadableSubscription)
{
Synchronizer.execute(subscription, true, true);
}
}
}
function getUserFilters()
{
var filters = [];
var exceptions = [];
for (var i = 0; i < FilterStorage.subscriptions.length; i++)
{
var subscription = FilterStorage.subscriptions[i];
if (!(subscription instanceof SpecialSubscription))
{
continue;
}
for (var j = 0; j < subscription.filters.length; j++)
{
var filter = subscription.filters[j];
filters.push(filter.text);
}
}
return filters;
}
// Return |domain| encoded in Unicode
getUnicodeDomain = function(domain)
{
if (domain)
{
return punycode.toUnicode(domain);
}
else
{
return domain;
}
}
// Return |url| encoded in Unicode
getUnicodeUrl = function(url)
{
// URLs encoded in Punycode contain xn-- prefix
if (url && url.indexOf("xn--") > 0)
{
var parsed = parseUri(url);
parsed.href = parsed.href.replace(parsed.hostname, punycode.toUnicode(parsed.hostname));
return parsed.href;
}
return url;
};
// Remove comment when migration code is removed
// STATS = STATS();
// STATS.startPinging();