-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
428 additions
and
345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,89 @@ | ||
(function () { | ||
'use strict'; | ||
// https://developers.google.com/analytics/devguides/collection/analyticsjs/ | ||
const noopfn = function () { | ||
}; | ||
'use strict'; | ||
|
||
// https://developers.google.com/analytics/devguides/collection/analyticsjs/ | ||
const noopfn = function () { | ||
}; | ||
// | ||
const Tracker = function () { | ||
}; | ||
const p = Tracker.prototype; | ||
p.get = noopfn; | ||
p.set = noopfn; | ||
p.send = noopfn; | ||
// | ||
const w = window; | ||
const gaName = w.GoogleAnalyticsObject || 'ga'; | ||
const gaQueue = w[gaName]; | ||
const ga = function () { | ||
const len = arguments.length; | ||
if (len === 0) { return; } | ||
const args = Array.from(arguments); | ||
let fn; | ||
let a = args[len - 1]; | ||
if (a instanceof Object && typeof a.hitCallback === 'function') { | ||
fn = a.hitCallback; | ||
} else if (a instanceof Function) { | ||
fn = () => { a(ga.create()); }; | ||
} else { | ||
const pos = args.indexOf('hitCallback'); | ||
if (pos !== -1 && typeof args[pos + 1] === 'function') { | ||
fn = args[pos + 1]; | ||
} | ||
} | ||
if (typeof fn !== 'function') { return; } | ||
try { | ||
fn(); | ||
} catch (ex) { | ||
} | ||
}; | ||
ga.create = function () { | ||
return new Tracker(); | ||
}; | ||
ga.getByName = function () { | ||
return new Tracker(); | ||
}; | ||
ga.getAll = function () { | ||
return [new Tracker()]; | ||
}; | ||
ga.remove = noopfn; | ||
// https://github.com/uBlockOrigin/uAssets/issues/2107 | ||
ga.loaded = true; | ||
w[gaName] = ga; | ||
// https://github.com/gorhill/uBlock/issues/3075 | ||
const dl = w.dataLayer; | ||
if (dl instanceof Object) { | ||
if (dl.hide instanceof Object && typeof dl.hide.end === 'function') { | ||
dl.hide.end(); | ||
dl.hide.end = () => { }; | ||
const Tracker = function () { | ||
}; | ||
const p = Tracker.prototype; | ||
p.get = noopfn; | ||
p.set = noopfn; | ||
p.send = noopfn; | ||
// | ||
const w = window; | ||
const gaName = w.GoogleAnalyticsObject || 'ga'; | ||
const gaQueue = w[gaName]; | ||
const ga = function (...args) { | ||
const len = args.length; | ||
if (len === 0) { return; } | ||
let fn; | ||
const a = args[len - 1]; | ||
if (typeof a === 'object' && typeof a.hitCallback === 'function') { | ||
fn = a.hitCallback; | ||
} else if (typeof a === 'function') { | ||
fn = () => { a(ga.create()); }; | ||
} else { | ||
const pos = args.indexOf('hitCallback'); | ||
if (pos !== -1 && typeof args[pos + 1] === 'function') { | ||
fn = args[pos + 1]; | ||
} | ||
} | ||
if (typeof fn !== 'function') { return; } | ||
try { | ||
fn(); | ||
} catch (ex) { | ||
} | ||
}; | ||
ga.create = function () { | ||
return new Tracker(); | ||
}; | ||
ga.getByName = function () { | ||
return new Tracker(); | ||
}; | ||
ga.getAll = function () { | ||
return [new Tracker()]; | ||
}; | ||
ga.remove = noopfn; | ||
// https://github.com/uBlockOrigin/uAssets/issues/2107 | ||
ga.loaded = true; | ||
w[gaName] = ga; | ||
// https://github.com/gorhill/uBlock/issues/3075 | ||
const dl = w.dataLayer; | ||
if (typeof dl === 'object') { | ||
if (typeof dl.hide === 'object' && typeof dl.hide.end === 'function') { | ||
dl.hide.end(); | ||
dl.hide.end = () => { }; | ||
} | ||
if (typeof dl.push === 'function') { | ||
const doCallback = function (item) { | ||
if (typeof item === 'object' === false) { return; } | ||
if (typeof item.eventCallback !== 'function') { return; } | ||
// eslint-disable-next-line sukka/prefer-timer-id -- deliberate use of setTimeout | ||
setTimeout(item.eventCallback, 1); | ||
item.eventCallback = () => { }; | ||
}; | ||
dl.push = new Proxy(dl.push, { | ||
apply(target, thisArg, args) { | ||
doCallback(args[0]); | ||
return Reflect.apply(target, thisArg, args); | ||
} | ||
if (typeof dl.push === 'function') { | ||
const doCallback = function (item) { | ||
if (item instanceof Object === false) { return; } | ||
if (typeof item.eventCallback !== 'function') { return; } | ||
setTimeout(item.eventCallback, 1); | ||
item.eventCallback = () => { }; | ||
}; | ||
dl.push = new Proxy(dl.push, { | ||
apply: function (target, thisArg, args) { | ||
doCallback(args[0]); | ||
return Reflect.apply(target, thisArg, args); | ||
} | ||
}); | ||
if (Array.isArray(dl)) { | ||
const q = dl.slice(); | ||
for (const item of q) { | ||
doCallback(item); | ||
} | ||
} | ||
}); | ||
if (Array.isArray(dl)) { | ||
const q = dl.slice(); | ||
for (const item of q) { | ||
doCallback(item); | ||
} | ||
} | ||
} | ||
// empty ga queue | ||
if (typeof gaQueue === 'function' && Array.isArray(gaQueue.q)) { | ||
const q = gaQueue.q.slice(); | ||
gaQueue.q.length = 0; | ||
for (const entry of q) { | ||
ga(...entry); | ||
} | ||
} | ||
// empty ga queue | ||
if (typeof gaQueue === 'function' && Array.isArray(gaQueue.q)) { | ||
const q = gaQueue.q.slice(); | ||
gaQueue.q.length = 0; | ||
for (const entry of q) { | ||
ga(...entry); | ||
} | ||
})(); | ||
} | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
window._gaq = window._gaq || { | ||
push: function () { | ||
push() { | ||
} | ||
}; | ||
})(); | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
const noopfn = function () { | ||
}; | ||
const w = window; | ||
w.ga = w.ga || noopfn; | ||
const dl = w.dataLayer; | ||
if (dl instanceof Object === false) { return; } | ||
if (dl.hide instanceof Object && typeof dl.hide.end === 'function') { | ||
if (typeof dl !== 'object') { return; } | ||
if (typeof dl.hide === 'object' && typeof dl.hide.end === 'function') { | ||
dl.hide.end(); | ||
} | ||
if (typeof dl.push === 'function') { | ||
dl.push = function (o) { | ||
if ( | ||
o instanceof Object && | ||
typeof o.eventCallback === 'function' | ||
typeof o === 'object' | ||
&& typeof o.eventCallback === 'function' | ||
) { | ||
// eslint-disable-next-line sukka/prefer-timer-id -- deliberately use setTimeout | ||
setTimeout(o.eventCallback, 1); | ||
} | ||
}; | ||
} | ||
})(); | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.