Skip to content

Commit

Permalink
Closes #943
Browse files Browse the repository at this point in the history
  • Loading branch information
ParticleCore committed Feb 28, 2024
1 parent 50b406c commit 350afdd
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/chrome/js/background-inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,36 @@ function mainScript(extensionId, SettingData, defaultSettings) {

})();

const OverrideHandleResponse = (() => {

const listeners = [];
const handleResponseKey = crypto.randomUUID();

Object.defineProperty(Object.prototype, "handleResponse", {
set(data) {
this[handleResponseKey] = data;
},
get() {
const original = this[handleResponseKey];
return function (url, code, response, callback) {
if (response?.constructor === String) {
try {
const parsed = JSON.parse(response);
listeners?.forEach(listener => listener?.(parsed));
} catch (e) {
}
}
return original?.apply(this, arguments);
};
}
});

return {
onHandleResponseListener: listener => listeners.push(listener)
};

})();

const OverrideApplicationCreate = (() => {

const createListeners = [];
Expand Down Expand Up @@ -1309,6 +1339,7 @@ function mainScript(extensionId, SettingData, defaultSettings) {

};

OverrideHandleResponse.onHandleResponseListener(update);
OverrideApplicationCreate.onCreateListener(update);
OverrideApplicationCreate.onLoadListener(update);
OverrideApplicationCreate.onCueListener(update);
Expand Down Expand Up @@ -1645,6 +1676,8 @@ function mainScript(extensionId, SettingData, defaultSettings) {

OnYtPageDataFetched.addListener(listener);
OverrideResponseText.onResponseListener(listener);
OverrideHandleResponse.onHandleResponseListener(listener);
OverrideHandleResponse.onHandleResponseListener(playerConfig);
OverrideApplicationCreate.onCreateListener(playerConfig);
OverrideApplicationCreate.onLoadListener(playerConfig);
OverrideApplicationCreate.onCueListener(playerConfig);
Expand Down Expand Up @@ -1822,6 +1855,7 @@ function mainScript(extensionId, SettingData, defaultSettings) {
}
};

OverrideHandleResponse.onHandleResponseListener(listener);
OverrideApplicationCreate.onCreateListener(listener);
OverrideApplicationCreate.onLoadListener(listener);
OverrideApplicationCreate.onCueListener(listener);
Expand All @@ -1848,6 +1882,7 @@ function mainScript(extensionId, SettingData, defaultSettings) {
}
};

OverrideHandleResponse.onHandleResponseListener(listener);
OverrideApplicationCreate.onCreateListener(listener);
OverrideApplicationCreate.onLoadListener(listener);
OverrideApplicationCreate.onCueListener(listener);
Expand Down
35 changes: 35 additions & 0 deletions src/firefox/js/background-inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,36 @@ function mainScript(extensionId, SettingData, defaultSettings) {

})();

const OverrideHandleResponse = (() => {

const listeners = [];
const handleResponseKey = crypto.randomUUID();

Object.defineProperty(Object.prototype, "handleResponse", {
set(data) {
this[handleResponseKey] = data;
},
get() {
const original = this[handleResponseKey];
return function (url, code, response, callback) {
if (response?.constructor === String) {
try {
const parsed = JSON.parse(response);
listeners?.forEach(listener => listener?.(parsed));
} catch (e) {
}
}
return original?.apply(this, arguments);
};
}
});

return {
onHandleResponseListener: listener => listeners.push(listener)
};

})();

const OverrideApplicationCreate = (() => {

const createListeners = [];
Expand Down Expand Up @@ -1309,6 +1339,7 @@ function mainScript(extensionId, SettingData, defaultSettings) {

};

OverrideHandleResponse.onHandleResponseListener(update);
OverrideApplicationCreate.onCreateListener(update);
OverrideApplicationCreate.onLoadListener(update);
OverrideApplicationCreate.onCueListener(update);
Expand Down Expand Up @@ -1645,6 +1676,8 @@ function mainScript(extensionId, SettingData, defaultSettings) {

OnYtPageDataFetched.addListener(listener);
OverrideResponseText.onResponseListener(listener);
OverrideHandleResponse.onHandleResponseListener(listener);
OverrideHandleResponse.onHandleResponseListener(playerConfig);
OverrideApplicationCreate.onCreateListener(playerConfig);
OverrideApplicationCreate.onLoadListener(playerConfig);
OverrideApplicationCreate.onCueListener(playerConfig);
Expand Down Expand Up @@ -1822,6 +1855,7 @@ function mainScript(extensionId, SettingData, defaultSettings) {
}
};

OverrideHandleResponse.onHandleResponseListener(listener);
OverrideApplicationCreate.onCreateListener(listener);
OverrideApplicationCreate.onLoadListener(listener);
OverrideApplicationCreate.onCueListener(listener);
Expand All @@ -1848,6 +1882,7 @@ function mainScript(extensionId, SettingData, defaultSettings) {
}
};

OverrideHandleResponse.onHandleResponseListener(listener);
OverrideApplicationCreate.onCreateListener(listener);
OverrideApplicationCreate.onLoadListener(listener);
OverrideApplicationCreate.onCueListener(listener);
Expand Down

0 comments on commit 350afdd

Please sign in to comment.