Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

115助手的新标签打开功能最好添加一个阻止事件冒泡 #22

Open
lvzhenbo opened this issue Apr 25, 2024 · 6 comments
Open
Labels
bug Something isn't working PR welcome

Comments

@lvzhenbo
Copy link

脚本

115-helper 115 小助手

问题重现步骤

打开新标签打开功能

实际的结果是什么?

事件冒泡机制会导致点击新标签打开的a标签后触发115本身的选择文件夹事件

期望的结果是什么?

不会触发115本身的选择文件夹事件

操作系统

Windows

浏览器

Chrome

使用的浏览器

No response

浏览器版本(设置 — 关于)

124

扩展

油猴 Tampermonkey

扩展版本

510

@lvzhenbo lvzhenbo added the bug Something isn't working label Apr 25, 2024
@maomao1996
Copy link
Owner

为了性能目前是通过事件委托处理的事件(单纯加一个阻止冒泡处理不了这个),后续看看怎么优化

@dnknn
Copy link

dnknn commented Apr 29, 2024

为了性能目前是通过事件委托处理的事件

肯定也必须是事件委托, 总不可能为页码的每1个列表都注册一个事件吧, 那得几十几百几千(根据用户设置的页码数量), 就额外占用内存导致更卡顿

@maomao1996
Copy link
Owner

为了性能目前是通过事件委托处理的事件

肯定也必须是事件委托, 总不可能为页码的每1个列表都注册一个事件吧, 那得几十几百几千(根据用户设置的页码数量), 就额外占用内存导致更卡顿

是的,不过要解决这个触发选中还是需要点处理的

@dnknn
Copy link

dnknn commented Apr 30, 2024

不过要解决这个触发选中还是需要点处理的

其实也无伤大雅,无需过渡复杂处理的.
像楼主都懂事件冒泡就应该也懂自己架设事件去实现吧, 要实现新标签页打开,也可有N种其它实现不触发勾选的,
例如用快捷键keydown => 打开li:hover
例如用mouseup=>定义鼠标第4键触发文件夹图标时...

@lvzhenbo
Copy link
Author

我在做自己的115侧边栏脚本的时候发现了意外收获,我想可以解决问题了

$('[no-file-select]').on('mousedown',function(e){
  e.stopPropagation();
  return true;
});

这是我通过事件监听器找到的,我通过添加dom节点发现在115的非侧边栏的区域无论怎么点都会触发文件选择,想到了一个事情,就是你说的事件委托,原本以为是点击事件,没想到是在鼠标事件里

@lvzhenbo
Copy link
Author

哦,这边提一个小bug,是115页面改了以后引起的,算是115的前端懒了,可以把脚本加的按钮放在官方按钮后面
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR welcome
Projects
None yet
Development

No branches or pull requests

3 participants