Skip to content

Commit

Permalink
Fix popup for CNN images (fixes #1199)
Browse files Browse the repository at this point in the history
  • Loading branch information
qsniyg committed Feb 6, 2024
1 parent dfea9a2 commit bb3e407
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 49 deletions.
113 changes: 85 additions & 28 deletions src/userscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115055,6 +115055,26 @@ var $$IMU_EXPORT$$;
}
}

if (host_domain_nosub === "cnn.com") {
return {
element_ok: function(el) {
if (el.tagName.toUpperCase() === "BUTTON" && (
el.classList.contains("gallery-inline__next-overlay") ||
el.classList.contains("gallery-inline__prev-overlay")
)) {
let parent = el.parentElement;
if (parent.classList.contains("gallery-inline__container")) {
let slides = parent.querySelector(".gallery-inline__slides");
return {
el: slides,
search: true
};
}
}
}
}
}

return null;
};

Expand Down Expand Up @@ -125954,7 +125974,8 @@ var $$IMU_EXPORT$$;
}

type FindSourceOptions = {
links?:boolean
links?:boolean,
point?:[number, number]
};
function find_source(els:Array<HTMLElement>, options?:FindSourceOptions) {
if (!options) options = {};
Expand Down Expand Up @@ -126222,7 +126243,7 @@ var $$IMU_EXPORT$$;
return true;
}

function addTagElement(el, layer) {
function addTagElement(el, layer:number) {
//nir_debug("find_source", "addTagElement", el);

if (helpers && helpers.element_replace) {
Expand All @@ -126245,13 +126266,37 @@ var $$IMU_EXPORT$$;
if (element_ok_result === true) {
ok_els.push(ok_el_obj);
set_add(ok_els_set, el);
} else {
if (is_element(element_ok_result)) {
ok_el_obj.el = element_ok_result;
ok_els.push(ok_el_obj);
set_add(ok_els_set, el);
} else if (typeof element_ok_result === "object") {
if (is_element(element_ok_result))
element_ok_result = {el: element_ok_result};

ok_el_obj.el = element_ok_result.el;
ok_els.push(ok_el_obj);
set_add(ok_els_set, el);

el = element_ok_result;
el = element_ok_result.el;

if (element_ok_result.search) {
let point = options.point;
if (!point) {
let rect = get_bounding_client_rect(el);
point = [
rect.left + (rect.width / 2),
rect.top + (rect.height / 2)
];
}

let found_els = find_els_at_point(point, {
els_mode: "full",
els: [el]
});

for (let fel of found_els) {
if (fel === el)
continue;

addElement(fel);
}
}
}
}
Expand Down Expand Up @@ -127325,11 +127370,24 @@ var $$IMU_EXPORT$$;
}

var exclude_find_els = new_set();
function find_els_at_point(xy, els?:Array<Element>, prev?:IMUSet, zoom_cache?:Map<Element, {zIndex: number}>):Array<HTMLElement> {
type FindElsAtPointOptions = {
els_mode?: "full"|"hybrid"|"simple",
els?: Array<Element>
}
function find_els_at_point(xy, options?:FindElsAtPointOptions, els?:Array<Element>, prev?:IMUSet, zoom_cache?:Map<Element, {zIndex: number}>):Array<HTMLElement> {
// test for pointer-events: none: https://www.shacknews.com/article/114834/should-you-choose-vulkan-or-directx-12-in-red-dead-redemption-2

if (false && _nir_debug_)
console_log("find_els_at_point", deepcopy(xy), deepcopy(els), deepcopy(prev));
console_log("find_els_at_point", deepcopy(options), deepcopy(xy), deepcopy(els), deepcopy(prev));

if (!options) {
options = {};
}

if (!options.els_mode)
options.els_mode = get_single_setting("mouseover_find_els_mode");
if (options.els && !els)
els = options.els;

var first_run = false;
if (!prev) {
Expand All @@ -127348,8 +127406,6 @@ var $$IMU_EXPORT$$;
var ret = [];
var afterret = [];

var els_mode = get_single_setting("mouseover_find_els_mode");

if (!els) {
let orig_els = document.elementsFromPoint(xy[0], xy[1]);

Expand All @@ -127365,26 +127421,26 @@ var $$IMU_EXPORT$$;
console_log("find_els_at_point (elsfrompoint)", deepcopy(els));
}

if (els_mode === "simple")
if (options.els_mode === "simple")
return els as Array<HTMLElement>;
}

for (var i = 0; i < els.length; i++) {
if (i > 0 && first_run && els_mode === "hybrid") {
for (let i = 0; i < els.length; i++) {
if (i > 0 && first_run && options.els_mode === "hybrid") {
ret.push(els[i]);
continue;
}

var el = els[i];
let el = els[i];

if (set_has(prev, el))
continue;

set_add(prev, el);

var el_has_children = false;
var el_children = null;
var el_shadow_children = null;
let el_has_children = false;
let el_children = null;
let el_shadow_children = null;

if (el.childElementCount > 0) {
el_children = el.children;
Expand Down Expand Up @@ -127416,9 +127472,9 @@ var $$IMU_EXPORT$$;
}
}

var newels = find_els_at_point(xy, newchildren, prev, zoom_cache);
for (var j = 0; j < newels.length; j++) {
var newel = newels[j];
let newels = find_els_at_point(xy, options, newchildren, prev, zoom_cache);
for (let j = 0; j < newels.length; j++) {
let newel = newels[j];
//console_log("about to add", newel, deepcopy(ret))
if (array_indexof(ret, newel) < 0) {
//console_log("adding", newel);
Expand All @@ -127429,7 +127485,7 @@ var $$IMU_EXPORT$$;

// youtube links on: https://old.reddit.com/r/anime/comments/btlmky/wt_mushishi_a_beautifully_melancholic_take_on_the/
// they pop up outside of the cursor
var rect = get_bounding_client_rect(el, zoom_cache);
let rect = get_bounding_client_rect(el, zoom_cache);
if (rect && rect.width > 0 && rect.height > 0 &&
rect.left <= xy[0] && rect.right >= xy[0] &&
rect.top <= xy[1] && rect.bottom >= xy[1] &&
Expand All @@ -127438,7 +127494,7 @@ var $$IMU_EXPORT$$;
}
}

for (var i = 0; i < afterret.length; i++) {
for (let i = 0; i < afterret.length; i++) {
if (array_indexof(ret, afterret[i]) < 0)
ret.push(afterret[i]);
}
Expand All @@ -127447,7 +127503,7 @@ var $$IMU_EXPORT$$;
console_log("find_els_at_point (unsorted ret)", shallowcopy(ret));
}

if (first_run && els_mode === "hybrid") {
if (first_run && options.els_mode === "hybrid") {
return ret;
}

Expand Down Expand Up @@ -127570,7 +127626,7 @@ var $$IMU_EXPORT$$;
mouseContextY = null;
}

var source = find_source(els);
var source = find_source(els, {point: point});

if (!source && settings.mouseover_allow_self_pagelink && popup_trigger_reason === "keyboard") {
source = {
Expand Down Expand Up @@ -129027,8 +129083,9 @@ var $$IMU_EXPORT$$;
e.stopImmediatePropagation();
e.stopPropagation();

var els = find_els_at_point([mouseX, mouseY]);
var source = find_source(els);
let point = [mouseX, mouseY];
var els = find_els_at_point(point);
var source = find_source(els, {point: point});
if (!source || !source.el)
return;

Expand Down
86 changes: 65 additions & 21 deletions userscript.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -103087,6 +103087,23 @@ var $$IMU_EXPORT$$;
}
};
}
if (host_domain_nosub === "cnn.com") {
return {
element_ok: function(el) {
if (el.tagName.toUpperCase() === "BUTTON" && (el.classList.contains("gallery-inline__next-overlay") ||
el.classList.contains("gallery-inline__prev-overlay"))) {
var parent_6 = el.parentElement;
if (parent_6.classList.contains("gallery-inline__container")) {
var slides = parent_6.querySelector(".gallery-inline__slides");
return {
el: slides,
search: true
};
}
}
}
};
}
return null;
};
var _get_album_info_gallery = function(album_info, el, nextprev) {
Expand Down Expand Up @@ -112182,12 +112199,32 @@ var $$IMU_EXPORT$$;
if (element_ok_result === true) {
ok_els.push(ok_el_obj);
set_add(ok_els_set, el);
} else {
if (is_element(element_ok_result)) {
ok_el_obj.el = element_ok_result;
ok_els.push(ok_el_obj);
set_add(ok_els_set, el);
el = element_ok_result;
} else if (typeof element_ok_result === "object") {
if (is_element(element_ok_result))
element_ok_result = { el: element_ok_result };
ok_el_obj.el = element_ok_result.el;
ok_els.push(ok_el_obj);
set_add(ok_els_set, el);
el = element_ok_result.el;
if (element_ok_result.search) {
var point = options.point;
if (!point) {
var rect = get_bounding_client_rect(el);
point = [
rect.left + (rect.width / 2),
rect.top + (rect.height / 2)
];
}
var found_els = find_els_at_point(point, {
els_mode: "full",
els: [el]
});
for (var _i = 0, found_els_1 = found_els; _i < found_els_1.length; _i++) {
var fel = found_els_1[_i];
if (fel === el)
continue;
addElement(fel);
}
}
}
}
Expand Down Expand Up @@ -113046,10 +113083,17 @@ var $$IMU_EXPORT$$;
currenttab_is_image() && !imagetab_ok_override;
}
var exclude_find_els = new_set();
function find_els_at_point(xy, els, prev, zoom_cache) {
function find_els_at_point(xy, options, els, prev, zoom_cache) {
// test for pointer-events: none: https://www.shacknews.com/article/114834/should-you-choose-vulkan-or-directx-12-in-red-dead-redemption-2
if (false && _nir_debug_)
console_log("find_els_at_point", deepcopy(xy), deepcopy(els), deepcopy(prev));
console_log("find_els_at_point", deepcopy(options), deepcopy(xy), deepcopy(els), deepcopy(prev));
if (!options) {
options = {};
}
if (!options.els_mode)
options.els_mode = get_single_setting("mouseover_find_els_mode");
if (options.els && !els)
els = options.els;
var first_run = false;
if (!prev) {
prev = new_set();
Expand All @@ -113064,24 +113108,23 @@ var $$IMU_EXPORT$$;
}
var ret = [];
var afterret = [];
var els_mode = get_single_setting("mouseover_find_els_mode");
if (!els) {
var orig_els = document.elementsFromPoint(xy[0], xy[1]);
els = [];
for (var _i = 0, orig_els_1 = orig_els; _i < orig_els_1.length; _i++) {
var el_2 = orig_els_1[_i];
if (!set_has(exclude_find_els, el_2))
els.push(el_2);
var el = orig_els_1[_i];
if (!set_has(exclude_find_els, el))
els.push(el);
}
afterret = els;
if (_nir_debug_) {
console_log("find_els_at_point (elsfrompoint)", deepcopy(els));
}
if (els_mode === "simple")
if (options.els_mode === "simple")
return els;
}
for (var i = 0; i < els.length; i++) {
if (i > 0 && first_run && els_mode === "hybrid") {
if (i > 0 && first_run && options.els_mode === "hybrid") {
ret.push(els[i]);
continue;
}
Expand Down Expand Up @@ -113117,9 +113160,9 @@ var $$IMU_EXPORT$$;
newchildren.push(el_shadow_children[j]);
}
}
var newels = find_els_at_point(xy, newchildren, prev, zoom_cache);
for (var j = 0; j < newels.length; j++) {
var newel = newels[j];
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];
//console_log("about to add", newel, deepcopy(ret))
if (array_indexof(ret, newel) < 0) {
//console_log("adding", newel);
Expand All @@ -113144,7 +113187,7 @@ var $$IMU_EXPORT$$;
if (_nir_debug_ && ret.length > 0) {
console_log("find_els_at_point (unsorted ret)", shallowcopy(ret));
}
if (first_run && els_mode === "hybrid") {
if (first_run && options.els_mode === "hybrid") {
return ret;
}
var get_zindex_raw = function(el) {
Expand Down Expand Up @@ -113241,7 +113284,7 @@ var $$IMU_EXPORT$$;
mouseContextX = null;
mouseContextY = null;
}
var source = find_source(els);
var source = find_source(els, { point: point });
if (!source && settings.mouseover_allow_self_pagelink && popup_trigger_reason === "keyboard") {
source = {
el: document.body,
Expand Down Expand Up @@ -114424,8 +114467,9 @@ var $$IMU_EXPORT$$;
e.preventDefault();
e.stopImmediatePropagation();
e.stopPropagation();
var els = find_els_at_point([mouseX, mouseY]);
var source = find_source(els);
var point = [mouseX, mouseY];
var els = find_els_at_point(point);
var source = find_source(els, { point: point });
if (!source || !source.el)
return;
source = add_source(source);
Expand Down

0 comments on commit bb3e407

Please sign in to comment.