Skip to content

Commit

Permalink
Improve parsing for <picture> elements that aren't at the top layer
Browse files Browse the repository at this point in the history
  • Loading branch information
qsniyg committed Jul 21, 2024
1 parent 2b998ea commit 877b7d2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ New features:
Improvements:

* Various improvements/fixes to existing rules (including Flickr, iTunes, Patreon, Soundcloud, Threads, TikTok, Tumblr)
* Improve parsing for <picture> elements

Bugfixes:

Expand Down
38 changes: 30 additions & 8 deletions src/userscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ var $$IMU_EXPORT$$;
// channels
map: false,
cache: false,
bigimage_recursive: true,
bigimage_recursive: false,
input: false,
check_image_get: false,
find_source: false
find_source: true
};

console.log("Loaded");
Expand Down Expand Up @@ -21286,13 +21286,13 @@ var $$IMU_EXPORT$$;
};

common_functions["_wix_bigimage_inner"] = function(src) {
var newsrc = src.replace(/(:\/\/[^/]*\/)(f\/+[-0-9a-f]{36}\/+[0-9a-z]+-[-0-9a-f]{20,}(?:\.[^/.]*)?\/+v1\/+fill\/+w_[0-9]+,h_[0-9]+)(?:,[^/]+)?(\/+.*[?&]token=.*)$/, "$1$2,q_100$3");
var newsrc = src.replace(/(:\/\/[^/]*\/)(f\/+[-0-9a-f]{36}\/+[0-9a-z]+-[-0-9a-f]{20,}(?:\.[^/.]*)?\/+v1\/+(?:fill|fit)\/+w_[0-9]+,h_[0-9]+)(?:,[^/]+)?(\/+.*[?&]token=.*)$/, "$1$2,q_100$3");
if (newsrc !== src) {
return newsrc;
}

// thanks to MrSeyker on greasyfork: https://greasyfork.org/en/scripts/36662-image-max-url/discussions/34976#comment-160842
newsrc = src.replace(/(:\/\/[^/]*\/f\/+[-0-9a-f]{36}\/+[0-9a-z]+-[-0-9a-f]{20,}\.(?:png|PNG)\/+v1\/+fill\/+[^/]+\/+[^/?#]+)\.[^/.?#]+(\?.*)?$/, "$1.png$2");
newsrc = src.replace(/(:\/\/[^/]*\/f\/+[-0-9a-f]{36}\/+[0-9a-z]+-[-0-9a-f]{20,}\.(?:png|PNG)\/+v1\/+(?:fill|fit)\/+[^/]+\/+[^/?#]+)\.[^/.?#]+(\?.*)?$/, "$1.png$2");
if (newsrc !== src) {
return newsrc;
}
Expand Down Expand Up @@ -129891,18 +129891,39 @@ var $$IMU_EXPORT$$;
add_bgimage(layer, el, window.getComputedStyle(el, ":after"), "after");
}

let is_sub_element = function(el, parent) {
if (el === parent) // el is not a subelement of parent
return false;

while (el) {
if (el === parent)
return true;
el = el.parentElement;
}

return false;
};

for (var i = 0; i < els.length; i++) {
// sidebar articles on https://www.rt.com/russia/447357-miss-moscow-2018-photos/
// the <picture> element has a size of 0, and hence isn't added to find_els_at_point
if (els[i].tagName === "IMG" && els[i].parentElement && els[i].parentElement.tagName === "PICTURE" && array_indexof(els, els[i].parentElement) < 0) {
els.splice(i + 1, 0, els[i].parentElement);
}

// remove every element before PICTURE as they will be added automatically anyways
// remove every sub element of PICTURE as they will be added automatically anyways
// this messes up the layering
if (els[i].tagName === "PICTURE" && i == 1) {
els.splice(0, i);
i = 0;
if (els[i].tagName === "PICTURE") {
for (let j = 0; j < i; j++) {
let subel = els[j];

if (is_sub_element(subel, els[i])) {
els.splice(j, 1);
j--;
i--;
}
}

break;
}
}
Expand All @@ -129914,6 +129935,7 @@ var $$IMU_EXPORT$$;

if (_nir_debug_) {
//console_log(els);
nir_debug("find_source", "_find_source (els)", deepcopy(els));
nir_debug("find_source", "_find_source (sources)", deepcopy(sources));
nir_debug("find_source", "_find_source (layers)", deepcopy(layers));
nir_debug("find_source", "_find_source (ok_els)", deepcopy(ok_els));
Expand Down
37 changes: 27 additions & 10 deletions userscript.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ var $$IMU_EXPORT$$;
// channels
map: false,
cache: false,
bigimage_recursive: true,
bigimage_recursive: false,
input: false,
check_image_get: false,
find_source: false
find_source: true
};
console.log("Loaded");
}
Expand Down Expand Up @@ -19831,12 +19831,12 @@ var $$IMU_EXPORT$$;
return null;
};
common_functions["_wix_bigimage_inner"] = function(src) {
var newsrc = src.replace(/(:\/\/[^/]*\/)(f\/+[-0-9a-f]{36}\/+[0-9a-z]+-[-0-9a-f]{20,}(?:\.[^/.]*)?\/+v1\/+fill\/+w_[0-9]+,h_[0-9]+)(?:,[^/]+)?(\/+.*[?&]token=.*)$/, "$1$2,q_100$3");
var newsrc = src.replace(/(:\/\/[^/]*\/)(f\/+[-0-9a-f]{36}\/+[0-9a-z]+-[-0-9a-f]{20,}(?:\.[^/.]*)?\/+v1\/+(?:fill|fit)\/+w_[0-9]+,h_[0-9]+)(?:,[^/]+)?(\/+.*[?&]token=.*)$/, "$1$2,q_100$3");
if (newsrc !== src) {
return newsrc;
}
// thanks to MrSeyker on greasyfork: https://greasyfork.org/en/scripts/36662-image-max-url/discussions/34976#comment-160842
newsrc = src.replace(/(:\/\/[^/]*\/f\/+[-0-9a-f]{36}\/+[0-9a-z]+-[-0-9a-f]{20,}\.(?:png|PNG)\/+v1\/+fill\/+[^/]+\/+[^/?#]+)\.[^/.?#]+(\?.*)?$/, "$1.png$2");
newsrc = src.replace(/(:\/\/[^/]*\/f\/+[-0-9a-f]{36}\/+[0-9a-z]+-[-0-9a-f]{20,}\.(?:png|PNG)\/+v1\/+(?:fill|fit)\/+[^/]+\/+[^/?#]+)\.[^/.?#]+(\?.*)?$/, "$1.png$2");
if (newsrc !== src) {
return newsrc;
}
Expand Down Expand Up @@ -115452,17 +115452,33 @@ var $$IMU_EXPORT$$;
add_bgimage(layer, el, window.getComputedStyle(el, ":before"), "before");
add_bgimage(layer, el, window.getComputedStyle(el, ":after"), "after");
}
var is_sub_element = function(el, parent) {
if (el === parent) // el is not a subelement of parent
return false;
while (el) {
if (el === parent)
return true;
el = el.parentElement;
}
return false;
};
for (var i = 0; i < els.length; i++) {
// sidebar articles on https://www.rt.com/russia/447357-miss-moscow-2018-photos/
// the <picture> element has a size of 0, and hence isn't added to find_els_at_point
if (els[i].tagName === "IMG" && els[i].parentElement && els[i].parentElement.tagName === "PICTURE" && array_indexof(els, els[i].parentElement) < 0) {
els.splice(i + 1, 0, els[i].parentElement);
}
// remove every element before PICTURE as they will be added automatically anyways
// remove every sub element of PICTURE as they will be added automatically anyways
// this messes up the layering
if (els[i].tagName === "PICTURE" && i == 1) {
els.splice(0, i);
i = 0;
if (els[i].tagName === "PICTURE") {
for (var j_1 = 0; j_1 < i; j_1++) {
var subel = els[j_1];
if (is_sub_element(subel, els[i])) {
els.splice(j_1, 1);
j_1--;
i--;
}
}
break;
}
}
Expand All @@ -115472,6 +115488,7 @@ var $$IMU_EXPORT$$;
}
if (_nir_debug_) {
//console_log(els);
nir_debug("find_source", "_find_source (els)", deepcopy(els));
nir_debug("find_source", "_find_source (sources)", deepcopy(sources));
nir_debug("find_source", "_find_source (layers)", deepcopy(layers));
nir_debug("find_source", "_find_source (ok_els)", deepcopy(ok_els));
Expand Down Expand Up @@ -116018,8 +116035,8 @@ var $$IMU_EXPORT$$;
}
}
var newels = find_els_at_point(xy, options, newchildren, prev, zoom_cache);
for (var j_1 = 0; j_1 < newels.length; j_1++) {
var newel = newels[j_1];
for (var j_2 = 0; j_2 < newels.length; j_2++) {
var newel = newels[j_2];
//console_log("about to add", newel, deepcopy(ret))
if (array_indexof(ret, newel) < 0) {
//console_log("adding", newel);
Expand Down

0 comments on commit 877b7d2

Please sign in to comment.