Browse Source

Don't mark as read if middle click is outside of article link (#8553)

* Don't mark as read if middle click is outside of article link

Closes https://github.com/FreshRSS/FreshRSS/issues/6451

https://developer.mozilla.org/en-US/docs/Web/API/Element/auxclick_event

> The auxclick event is fired at an [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) when a non-primary pointing device button (any mouse button other than the primary—usually leftmost—button) has been pressed and released both within the same element.

> auxclick is fired after the [mousedown](https://developer.mozilla.org/en-US/docs/Web/API/Element/mousedown_event) and [mouseup](https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseup_event) events have been fired, in that order.

* Split up `onmouseup` and `onauxclick` logic

Co-authored-by: Frans de Jonge <fransdejonge@gmail.com>

---------

Co-authored-by: Frans de Jonge <fransdejonge@gmail.com>
Inverle 3 ngày trước cách đây
mục cha
commit
57471eda19
1 tập tin đã thay đổi với 22 bổ sung20 xóa
  1. 22 20
      p/scripts/main.js

+ 22 - 20
p/scripts/main.js

@@ -1504,38 +1504,40 @@ function init_stream(stream) {
 		}
 	};
 
-	stream.onmouseup = function (ev) {	// Mouseup enables us to catch middle click, and control+click in IE/Edge
-		if (ev.altKey || ev.metaKey || ev.shiftKey) {
+	stream.onmouseup = function (ev) {	// Mouseup enables us to catch control+click in IE/Edge
+		if (ev.altKey || ev.metaKey || ev.shiftKey || ev.which != 1) {
 			return;
 		}
 
-		let el = ev.target.closest('.item a.title');
+		const el = ev.target.closest('.item a.title');
 		if (el) {
-			if (ev.which == 1) {
-				if (ev.ctrlKey) {	// Control+click
-					if (context.auto_mark_site) {
-						mark_read(el.closest('.flux'), true, false);
-					}
-				} else {
-					el.parentElement.click();	// Normal click, just toggle article.
-				}
-			} else if (ev.which == 2 && !ev.ctrlKey) {	// Simple middle click: same behaviour as CTRL+click
-				if (context.auto_mark_article) {
-					const new_active = el.closest('.flux');
-					mark_read(new_active, true, false);
+			if (ev.ctrlKey) {	// Control+click
+				if (context.auto_mark_site) {
+					mark_read(el.closest('.flux'), true, false);
 				}
+			} else {
+				el.parentElement.click();	// Normal click, just toggle article.
+			}
+		}
+	};
+
+	stream.onauxclick = function (ev) {	// Auxclick enables us to catch middle click
+		if (ev.altKey || ev.metaKey || ev.shiftKey || ev.which != 2 || ev.ctrlKey) {
+			return;
+		}
+
+		let el = ev.target.closest('.item a.title');
+		if (el) {
+			if (context.auto_mark_article) {
+				const new_active = el.closest('.flux');
+				mark_read(new_active, true, false);
 			}
 			return;
 		}
 
 		if (context.auto_mark_site) {
-			// catch mouseup instead of click so we can have the correct behaviour
-			// with middle button click (scroll button).
 			el = ev.target.closest('.flux .link > a');
 			if (el) {
-				if (ev.which == 3) {
-					return;
-				}
 				mark_read(el.closest('.flux'), true, false);
 			}
 		}