From 777adf1baeb94ea1c29d5a143be93dccbbce64c1 Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 21 Nov 2017 13:42:51 +0300 Subject: [PATCH] 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. --- content/install.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/content/install.js b/content/install.js index f3e0a300..9dd0063e 100644 --- a/content/install.js +++ b/content/install.js @@ -24,17 +24,20 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { document.documentElement.appendChild(document.createElement('script')).text = '(' + function () { let settings; + const originalResponseJson = Response.prototype.json; document.addEventListener('stylusFixBuggyUSOsettings', function _({detail}) { document.removeEventListener('stylusFixBuggyUSOsettings', _); 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) { return originalResponseJson.call(this, ...args).then(json => { - Response.prototype.json = originalResponseJson; if (!settings || typeof ((json || {}).style_settings || {}).every !== 'function') { return json; } + Response.prototype.json = originalResponseJson; const images = new Map(); for (const jsonSetting of json.style_settings) { let value = settings.get('ik-' + jsonSetting.install_key);