Skip to content

Commit

Permalink
Remove event listener on stop
Browse files Browse the repository at this point in the history
  • Loading branch information
hackermare committed Feb 28, 2022
1 parent eb07655 commit 1b87346
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions AutoScroll.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @name AutoScroll
* @author programmerpony
* @description Autoscroll with the mouse wheel button on GNU/Linux and macOS!
* @version 0.2.1
* @version 0.2.2
* @updateUrl https://raw.githubusercontent.com/programmer-pony/BD-AutoScroll/main/AutoScroll.plugin.js
* @authorLink https://fosstodon.org/@Luna
* @donate https://ko-fi.com/programmerpony
Expand Down Expand Up @@ -39,7 +39,6 @@ THE SOFTWARE.
*/

let enabled;
let htmlNode;
let bodyNode;
let state = {
Expand Down Expand Up @@ -92,12 +91,27 @@ class CheckBox extends BdApi.React.Component {
}
}

const mouseListener = (e) => {
if (state.scrolling) stopEvent(e, true);
else {
let path = e.composedPath();
let target = (path.length === 0 ? null : path[0]);
if (target != null && ((e.button === 1 && true) || (e.button === 0 && (e.ctrlKey || e.metaKey) && true)) && e.clientX < htmlNode.clientWidth && e.clientY < htmlNode.clientHeight && isValid(target)) {
let elem = findScroll(target);
if (elem) {
stopEvent(e, true);
show(elem, e.clientX, e.clientY);
}
}
}
}

module.exports = class AutoScroll {
getName() {
return 'AutoScroll';
}
getVersion() {
return '0.2.1';
return '0.2.2';
}
getAuthor() {
return 'programmerpony';
Expand All @@ -107,7 +121,6 @@ module.exports = class AutoScroll {
}
load() {}
start() {
enabled = true;
htmlNode = document.documentElement;
bodyNode = document.body ? document.body : htmlNode;
let outer = document.createElementNS('http://www.w3.org/1999/xhtml', 'auto-scroll');
Expand All @@ -124,24 +137,10 @@ module.exports = class AutoScroll {
inner.style.setProperty('background-repeat', 'no-repeat');
shadow.appendChild(inner);
htmlNode.appendChild(outer);
addEventListener('mousedown', (e) => {
if (!enabled) return;
if (state.scrolling) stopEvent(e, true);
else {
let path = e.composedPath();
let target = (path.length === 0 ? null : path[0]);
if (target != null && ((e.button === 1 && true) || (e.button === 0 && (e.ctrlKey || e.metaKey) && true)) && e.clientX < htmlNode.clientWidth && e.clientY < htmlNode.clientHeight && isValid(target)) {
let elem = findScroll(target);
if (elem) {
stopEvent(e, true);
show(elem, e.clientX, e.clientY);
}
}
}
}, true);
addEventListener('mousedown', mouseListener, true);
}
stop() {
enabled = false;
removeEventListener('mousedown', mouseListener, true);
}

getSettingsPanel() {
Expand Down

0 comments on commit 1b87346

Please sign in to comment.