Skip to content

Commit

Permalink
Fix #1264
Browse files Browse the repository at this point in the history
  • Loading branch information
qsniyg committed Jan 25, 2024
1 parent cd1b8a9 commit df412b1
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 26 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ Improvements:

* Various improvements/fixes to existing rules

Special thanks to Froktime, aslian for their contributions and reports for this release
Bugfixes:

* Fix a regression where alternate image URLs failed to load (thanks to posnipy for reporting)

Special thanks to Froktime, aslian, posnipy for their contributions and reports for this release

---

Expand Down
46 changes: 33 additions & 13 deletions src/userscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115346,7 +115346,8 @@ var $$IMU_EXPORT$$;
fine_urls: Array<BRLFineUrl>,
tried_urls: Array<BRLTriedUrl>,
oldobj: Array<any>,
tried_imus: Array<string>
tried_imus: Array<string>,
redirect_map: Record<string, string>
}
var bigimage_recursive_loop = function(url, options, query, state?:BRLState) {
var newoptions:any = {};
Expand All @@ -115356,7 +115357,8 @@ var $$IMU_EXPORT$$;
fine_urls: [],
tried_urls: [],
oldobj: [],
tried_imus: []
tried_imus: [],
redirect_map: {} // FIXME: is this needed?
};
}

Expand All @@ -115381,26 +115383,26 @@ var $$IMU_EXPORT$$;
}

obj = obj_merge(obj, oldobj);
var images = obj_to_simplelist(obj);
var image_urls = obj_to_simplelist(obj);

for (let i = 0; i < obj.length; i++) {
// TODO: also remove bad_if
if (obj[i].bad) {
let bad_url = obj[i].url;

obj.splice(i, 1);
images.splice(i, 1);
image_urls.splice(i, 1);
i--;

for (let j = 0; j < tried_urls.length; j++) {
if (tried_urls[j].newurl === bad_url) {
let orig_url = tried_urls[j].newobj.url;
let index = array_indexof(images, orig_url);
let index = array_indexof(image_urls, orig_url);
tried_urls[j].redirects_to_bad = true;

if (index >= 0) {
obj.splice(index, 1);
images.splice(index, 1);
image_urls.splice(index, 1);

if (index < i)
i -= 2;
Expand All @@ -115412,17 +115414,32 @@ var $$IMU_EXPORT$$;
}
}
}

// FIXME: is this needed?
if (false && obj[i].url in state.redirect_map) {
let to = state.redirect_map[obj[i].url];
let j;
for (j = i + 1; j < obj.length; j++) {
if (obj[j].url === to) {
obj.splice(i, j - i);
image_urls.splice(i, j - i);
break;
}
}

i -= 1;
}
}

if (_nir_debug_) {
console_log("bigimage_recursive_loop's cb: obj after:", deepcopy(obj));
console_log("bigimage_recursive_loop's cb: images after:", deepcopy(images));
console_log("bigimage_recursive_loop's cb: image_urls after:", deepcopy(image_urls));
console_log("bigimage_recursive_loop's cb: fine_urls:", deepcopy(fine_urls));
console_log("bigimage_recursive_loop's cb: tried_urls:", deepcopy(tried_urls));
}

for (let i = 0; i < fine_urls.length; i++) {
let index = array_indexof(images, fine_urls[i].url);
let index = array_indexof(image_urls, fine_urls[i].url);
if (index >= 0) {
obj = [obj[index]];
if (_nir_debug_) {
Expand All @@ -115440,7 +115457,7 @@ var $$IMU_EXPORT$$;
continue;
}

let index = array_indexof(images, tried_urls[i].newurl);
let index = array_indexof(image_urls, tried_urls[i].newurl);
if (index >= 0) {
obj = [obj[index]];
if (_nir_debug_) {
Expand Down Expand Up @@ -115485,8 +115502,10 @@ var $$IMU_EXPORT$$;
redirects_to_bad: false
});

//if (array_indexof(images, newurl) < 0 && newurl !== url || true) {
var newurl_index = array_indexof(images, newurl);
state.redirect_map[url] = newurl;

//if (array_indexof(image_urls, newurl) < 0 && newurl !== url || true) {
var newurl_index = array_indexof(image_urls, newurl);
if (newurl_index < 0 && already_tried_url) {
if (_nir_debug_) {
console_log("bigimage_recursive_loop (query): already tried url", deepcopy(state));
Expand All @@ -115495,9 +115514,10 @@ var $$IMU_EXPORT$$;
}

if (newurl_index < 0 || !obj[newurl_index].norecurse) {
state.oldobj = obj;
bigimage_recursive_loop(newurl, options, query, state);
} else {
//obj = obj.slice(array_indexof(images, newurl));
//obj = obj.slice(array_indexof(image_urls, newurl));
obj = [obj[newurl_index]];

if (_nir_debug_) {
Expand All @@ -115513,7 +115533,7 @@ var $$IMU_EXPORT$$;
}

if (_nir_debug_) {
console_log("bigimage_recursive_loop", url, deepcopy(options), query, deepcopy(fine_urls), deepcopy(tried_urls), deepcopy(oldobj));
console_log("bigimage_recursive_loop", url, deepcopy(options), query, deepcopy(state));
}

return bigimage_recursive(url, newoptions);
Expand Down
40 changes: 28 additions & 12 deletions userscript.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -103266,7 +103266,8 @@ var $$IMU_EXPORT$$;
fine_urls: [],
tried_urls: [],
oldobj: [],
tried_imus: []
tried_imus: [],
redirect_map: {} // FIXME: is this needed?
};
}
var fine_urls = state.fine_urls;
Expand All @@ -103288,22 +103289,22 @@ var $$IMU_EXPORT$$;
console_log("bigimage_recursive_loop's cb: oldobj:", deepcopy(oldobj));
}
obj = obj_merge(obj, oldobj);
var images = obj_to_simplelist(obj);
var image_urls = obj_to_simplelist(obj);
for (var i = 0; i < obj.length; i++) {
// TODO: also remove bad_if
if (obj[i].bad) {
var bad_url = obj[i].url;
obj.splice(i, 1);
images.splice(i, 1);
image_urls.splice(i, 1);
i--;
for (var j = 0; j < tried_urls.length; j++) {
if (tried_urls[j].newurl === bad_url) {
var orig_url = tried_urls[j].newobj.url;
var index = array_indexof(images, orig_url);
var index = array_indexof(image_urls, orig_url);
tried_urls[j].redirects_to_bad = true;
if (index >= 0) {
obj.splice(index, 1);
images.splice(index, 1);
image_urls.splice(index, 1);
if (index < i)
i -= 2;
else if (index === i)
Expand All @@ -103313,15 +103314,28 @@ var $$IMU_EXPORT$$;
}
}
}
// FIXME: is this needed?
if (false && obj[i].url in state.redirect_map) {
var to = state.redirect_map[obj[i].url];
var j = void 0;
for (j = i + 1; j < obj.length; j++) {
if (obj[j].url === to) {
obj.splice(i, j - i);
image_urls.splice(i, j - i);
break;
}
}
i -= 1;
}
}
if (_nir_debug_) {
console_log("bigimage_recursive_loop's cb: obj after:", deepcopy(obj));
console_log("bigimage_recursive_loop's cb: images after:", deepcopy(images));
console_log("bigimage_recursive_loop's cb: image_urls after:", deepcopy(image_urls));
console_log("bigimage_recursive_loop's cb: fine_urls:", deepcopy(fine_urls));
console_log("bigimage_recursive_loop's cb: tried_urls:", deepcopy(tried_urls));
}
for (var i = 0; i < fine_urls.length; i++) {
var index = array_indexof(images, fine_urls[i].url);
var index = array_indexof(image_urls, fine_urls[i].url);
if (index >= 0) {
obj = [obj[index]];
if (_nir_debug_) {
Expand All @@ -103337,7 +103351,7 @@ var $$IMU_EXPORT$$;
try_any = true;
continue;
}
var index = array_indexof(images, tried_urls[i].newurl);
var index = array_indexof(image_urls, tried_urls[i].newurl);
if (index >= 0) {
obj = [obj[index]];
if (_nir_debug_) {
Expand Down Expand Up @@ -103376,18 +103390,20 @@ var $$IMU_EXPORT$$;
newobj: deepcopy(newobj),
redirects_to_bad: false
});
//if (array_indexof(images, newurl) < 0 && newurl !== url || true) {
var newurl_index = array_indexof(images, newurl);
state.redirect_map[url] = newurl;
//if (array_indexof(image_urls, newurl) < 0 && newurl !== url || true) {
var newurl_index = array_indexof(image_urls, newurl);
if (newurl_index < 0 && already_tried_url) {
if (_nir_debug_) {
console_log("bigimage_recursive_loop (query): already tried url", deepcopy(state));
}
return options.cb(null, data);
}
if (newurl_index < 0 || !obj[newurl_index].norecurse) {
state.oldobj = obj;
bigimage_recursive_loop(newurl, options, query, state);
} else {
//obj = obj.slice(array_indexof(images, newurl));
//obj = obj.slice(array_indexof(image_urls, newurl));
obj = [obj[newurl_index]];
if (_nir_debug_) {
console_log("bigimage_recursive_loop (query): returning", deepcopy(obj), data);
Expand All @@ -103401,7 +103417,7 @@ var $$IMU_EXPORT$$;
}
}
if (_nir_debug_) {
console_log("bigimage_recursive_loop", url, deepcopy(options), query, deepcopy(fine_urls), deepcopy(tried_urls), deepcopy(oldobj));
console_log("bigimage_recursive_loop", url, deepcopy(options), query, deepcopy(state));
}
return bigimage_recursive(url, newoptions);
};
Expand Down

0 comments on commit df412b1

Please sign in to comment.