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:
tophf 2017-11-21 13:42:51 +03:00
parent e8d0c7d039
commit 777adf1bae

View File

@ -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);