correctly fix the USO bug with populating settings on their site
previously we disconnected the interceptor on first XHR response, which is not necessarily for the style, so now we wait until an actual one.
This commit is contained in:
parent
e8d0c7d039
commit
777adf1bae
|
@ -24,17 +24,20 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
||||||
document.documentElement.appendChild(document.createElement('script')).text = '(' +
|
document.documentElement.appendChild(document.createElement('script')).text = '(' +
|
||||||
function () {
|
function () {
|
||||||
let settings;
|
let settings;
|
||||||
|
const originalResponseJson = Response.prototype.json;
|
||||||
document.addEventListener('stylusFixBuggyUSOsettings', function _({detail}) {
|
document.addEventListener('stylusFixBuggyUSOsettings', function _({detail}) {
|
||||||
document.removeEventListener('stylusFixBuggyUSOsettings', _);
|
document.removeEventListener('stylusFixBuggyUSOsettings', _);
|
||||||
settings = /\?/.test(detail) && new URLSearchParams(new URL(detail).search);
|
settings = /\?/.test(detail) && new URLSearchParams(new URL(detail).search);
|
||||||
|
if (!settings) {
|
||||||
|
Response.prototype.json = originalResponseJson;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
const originalResponseJson = Response.prototype.json;
|
|
||||||
Response.prototype.json = function (...args) {
|
Response.prototype.json = function (...args) {
|
||||||
return originalResponseJson.call(this, ...args).then(json => {
|
return originalResponseJson.call(this, ...args).then(json => {
|
||||||
Response.prototype.json = originalResponseJson;
|
|
||||||
if (!settings || typeof ((json || {}).style_settings || {}).every !== 'function') {
|
if (!settings || typeof ((json || {}).style_settings || {}).every !== 'function') {
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
Response.prototype.json = originalResponseJson;
|
||||||
const images = new Map();
|
const images = new Map();
|
||||||
for (const jsonSetting of json.style_settings) {
|
for (const jsonSetting of json.style_settings) {
|
||||||
let value = settings.get('ik-' + jsonSetting.install_key);
|
let value = settings.get('ik-' + jsonSetting.install_key);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user