function D(e) {
if (o) {
console.log(e)
}
}(function() {
var e = document.createElement("script");
e.type = "text/javascript";
e.async = true;
e.src = "https://ssl.google-analytics.com/ga.js";
var t = document.getElementsByTagName("script")[0];
t.parentNode.insertBefore(e, t)
})();
var M = null;
var B = null;
var G = null;
var Q = null;
var L = null;
var V = [];
var z = [20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240, 20480];
var H = [.7071, .7071, .7071, .7071, .7071, .7071, .7071, .7071, .7071, .7071, .7071];
var K = 11;
var X = function() {};
var Y = {};
var Z = false;
var $;
function l(e) {
return a + e
}
function ee(n) {
if (!localStorage[i]) {
localStorage[i] = JSON.stringify({})
}
var r = JSON.parse(localStorage[i]);
if (r == null || typeof r != "object") {
r = {}
}
s.get(null, function(e) {
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError)
}
for (var t in e) {
if (t.startsWith(a)) {
r[t.slice(a.length)] = e[t]
}
}
n(r)
})
}
function te(e, t, n) {
var r = JSON.parse(localStorage[i]);
if (r == null || typeof r != "object") {
r = {}
}
var a = Object.keys(r).length;
r[e] = t;
var o = Object.keys(r).length;
if (W && Object.keys(r) > W && o >= a) {
n();
return
}
localStorage[i] = JSON.stringify(r);
syncPresets = {};
syncPresets[l(e)] = t;
s.set(syncPresets, function() {
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError)
}
n()
})
}
function ne(e, t) {
_gaq.push(["_trackEvent", "deletePreset", e.preset]);
var n = JSON.parse(localStorage[i]);
if (n == null || typeof n != "object") {
n = {}
}
delete n[e.preset];
localStorage[i] = JSON.stringify(n);
s.remove(l(e.preset), t)
}
chrome.storage.onChanged.addListener(function(e, t) {});
function c() {
if (Z) {
M.close();
M = null;
Z = false;
chrome.runtime.onMessage.removeListener($);
var e = Object.keys(Y);
for (var t = 0; t < e.length; t++) {
var n = e[t];
Y[n].stream.getTracks()[0].stop();
delete Y[n]
}
}
}
function re() {
return new AudioContext({
latencyHint: "playback"
})
}
function ae() {
if (Z) {
M.close();
M = null;
Z = false;
Q = null;
L = null;
var e = Object.values(Y);
Y = {};
for (var t = 0; t < e.length; t++) {
var n = e[t].audioSource;
n.disconnect(B)
}
u(e)
}
}
function u(e) {
var t = null;
if (Z) {
return
}
Z = true;
M = re();
M.suspend();
console.log("starting sampleRate: " + M.sampleRate);
var n = false;
X = function() {
if (n) {
return
}
var e = re();
var t = M.sampleRate && e.sampleRate && M.sampleRate != e.sampleRate;
if (t) {
console.log(e);
console.log(M);
n = true
}
e.close();
if (t) {
console.log("sampleRate changed... reloading AudioContext");
ae()
}
};
B = M.createGain();
B.gain.value = 1;
G = M.createGain();
G.gain.value = m();
if (t) {
var r = M.createScriptProcessor(t);
r.onaudioprocess = function(e) {
var t = e.inputBuffer;
var n = e.outputBuffer;
for (var r = 0; r < n.numberOfChannels; r++) {
n.copyToChannel(t.getChannelData(r), r)
}
};
G.connect(r);
r.connect(M.destination)
} else {
G.connect(M.destination)
}
if (!localStorage[U]) {
localStorage[U] = "0.0.0"
}
if (localStorage[" "] == " ") {
if (localStorage["sync"] != " ") {
ee(function(e) {
var t = Object.keys(e);
for (var n = 0; n < t.length; n++) {
var r = t[n];
te(r, e[r], function() {})
}
});
localStorage["sync"] = " "
}
}
localStorage[U] = J;
V = [];
var a = {};
function o() {
var e = G;
var t = false;
for (var n = V.length - 1; n >= 0; n--) {
if (V[n].gain.value != 0) {
if (!a[n]) {
t = true
}
if (t) {
D(n + " -> " + e.idx);
V[n].disconnect();
V[n].connect(e)
}
if (a[n]) {
t = false
}
a[n] = true;
e = V[n];
e.idx = n
} else {
if (a[n]) {
a[n] = false;
t = true
}
}
}
if (t) {
D("preGain -> " + e.idx);
B.disconnect();
B.connect(e)
}
}
for (var i = 0; i < K; i++) {
var s = M.createBiquadFilter();
if (i == 0) {
s.type = "lowshelf"
} else if (i == K - 1) {
s.type = "highshelf"
} else {
s.type = "peaking"
}
var l = "filter" + i;
var c = localStorage[l];
if (c) {
c = JSON.parse(c);
s.frequency.value = c.f;
s.gain.value = c.g;
s.Q.value = c.q
} else {
s.frequency.value = z[i];
s.gain.value = 0;
s.Q.value = H[i]
}
V.push(s);
localStorage[l] = JSON.stringify({
f: s.frequency.value,
g: s.gain.value,
q: s.Q.value
})
}
B.connect(G);
function u(e) {
f = V[e.index];
f.gain.value = v(e.gain);
f.frequency.value = p(e.frequency);
f.Q.value = d(e.q);
var t = "filter" + e.index;
localStorage[t] = JSON.stringify({
f: f.frequency.value,
g: f.gain.value,
q: f.Q.value
});
o()
}
function g(e) {
if (e > 10) {
return 10
}
if (e < .00316) {
return .00316
}
return e
}
function v(e) {
if (e < -30) {
return -30
}
if (e > 30) {
return 30
}
return e
}
function p(e) {
if (e < 5) {
return 5
}
if (e > 2e4) {
return 2e4
}
return e
}
function d(e) {
if (e < .2) {
e = .2
}
if (e > 11) {
e = 11
}
return e
}
function y(e) {
var t = g(e.gain);
G.gain.value = g(t);
h(t)
}
function m() {
if (!localStorage["GAIN"]) {
localStorage["GAIN"] = JSON.stringify(1)
}
return JSON.parse(localStorage["GAIN"])
}
function h(e) {
localStorage["GAIN"] = JSON.stringify(e)
}
function S(e) {
_gaq.push(["_trackEvent", "preset", "save"]);
var t = [];
var n = [];
var r = [];
for (var a = 0; a < V.length; a++) {
var o = V[a];
t.push(o.frequency.value);
n.push(o.gain.value);
r.push(o.Q.value)
}
var i = {
frequencies: t,
gains: n,
qs: r
};
te(e.preset, i, E)
}
It seems you've provided a snippet of JavaScript code that appears to interact with the Google Analytics API and a Chrome extension's storage system. To explain what is going on, I'll break down the different components of the code provided and their purposes.
-
Google Analytics Setup (_gaq Array):
_gaq is an array used to queue up Google Analytics commands before the analytics.js library is loaded. The code initializes the analytics account and tracks a pageview and a custom event (indicating the extension was opened and the current version).
-
Chrome Extension's Version:
chrome.runtime.getManifest().version retrieves the current version of the extension from its manifest file. This is tracked in the Google Analytics event.
-
Local Storage Usage:
The snippet interacts with localStorage to perform various tasks related to saving extension settings and presets. The methods get, set, and remove are being used to interact with Chrome's storage system. The original storage methods are replaced with chrome.storage.sync, which allows for syncing data across devices where the user is signed into Chrome.
-
Date Variable:
The e variable holds a string representing a date, but it is not used within the scope of the provided code.
-
Dynamic Script Loading:
A script (presumably Google Analytics’ ga.js) is loaded dynamically by appending a <script> element to the DOM, which allows for analytics tracking.
-
Management of Audio Processing:
The code looks like it's part of an audio-related Chrome extension, possibly an equalizer (AudioContext, BiquadFilter, etc.). It works with audio streams, manipulating their gains and frequencies using an array of filters, and it has an ae() function that closes and resets the AudioContext, which is the environment allowing for audio processing.
-
Presets Handling:
There are functions such as ee(), te(), and ne() to manage user-defined presets stored in localStorage. These are likely to represent equalizer settings (frequencies, gains, qs).
-
Logging and Debugging Support:
There are provisions in place, with a method D() and a boolean variable o, for logging and debugging information to console.
-
Miscellaneous:
There are placeholders for code that is intended to react to changes in Chrome storage and to handle messages (chrome.storage.onChanged.addListener, chrome.runtime.onMessage.removeListener) but these segments are not fully implemented in the given snippet.
-
Closure-Scoped Functions:
Functions like u(), y(), and m() to control various aspects of the audio processing are closure-scoped, meaning they are probably meant to be private to the implementation and used internally by the script.
-
Audio Processing:
Functions are defined to update filter values (u()), set the main gain (y()), and helper functions for sanitizing input values for gain (v()), frequency (p()), and Q-factor (d()).
-
Preset Save Function (S())
The S() function saves the current state of the filters into a preset name received as a parameter.
This code snippet lacks context and isn't complete, so it isn't fully functional or understandable without the rest of the extension’s codebase. Additionally, some of the identified functions (E()) are called but not defined within this snippet, suggesting that there is more to the extension than what is shown.