V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  adsjcxeicxzs  ›  全部回复第 1 页 / 共 1 页
回复总数  20
谢谢 op, 使用中发现一个问题, 一些 pop 不需要跳转, 比如 v2 的感谢按钮, 所以更新了一版

// ==UserScript==
// @name Force All Links to Open in New Tab
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Make all links open in a new tab, while keeping the original page unchanged
// @match *://*/*
// @grant none
// @license MIT
// ==/UserScript==

(function () {
'use strict';

function isPopupOrInteractiveLink(link) {
const url = link.href;

// Check if link has any event handlers (interactive functionality)
if (link.onclick || link.getAttribute('onclick') ||
link.getAttribute('onmousedown') || link.getAttribute('onmouseup')) {
return true;
}

// Check for data attributes that indicate JavaScript functionality
if (link.hasAttribute('data-toggle') || link.hasAttribute('data-target') ||
link.hasAttribute('data-dismiss') || link.hasAttribute('data-action') ||
link.hasAttribute('data-modal') || link.hasAttribute('data-popup')) {
return true;
}

// Check for CSS classes that typically indicate interactive elements
const interactiveClasses = ['modal-trigger', 'popup-trigger', 'lightbox-trigger',
'dialog-trigger', 'overlay-trigger', 'accordion-trigger',
'tab-trigger', 'dropdown-trigger', 'tooltip-trigger'];
if (interactiveClasses.some(cls => link.classList.contains(cls))) {
return true;
}

// Check for hash-only links that are used for JavaScript interactions
if (url.endsWith('#') || url.endsWith('#;') || url.includes('#!') ||
url === window.location.href + '#' || url === '#') {
return true;
}

// Check for javascript: URLs
if (url.startsWith('javascript:')) {
return true;
}

// Check for void(0) patterns
if (/void\(0\)/i.test(url)) {
return true;
}

// Check for same-page anchors (internal page navigation)
if (url.includes('#') && url.split('#')[0] === window.location.href.split('#')[0]) {
return true;
}

// Common popup URL patterns
const popupPatterns = [
/popup/i, /modal/i, /overlay/i, /lightbox/i, /dialog/i, /window\.open/i,
/fancybox/i, /colorbox/i, /thickbox/i, /magnific/i, /photoswipe/i,
/gallery/i, /slideshow/i, /carousel/i, /accordion/i, /tabs?/i,
/dropdown/i, /tooltip/i, /share/i, /social/i
];

return popupPatterns.some(pattern => pattern.test(url));
}

function openInNewTab(event) {
const link = event.target.closest('a'); // Find the clicked link
if (link && link.href && !link.hasAttribute('target')) {
// Check if this is a popup or interactive link
if (isPopupOrInteractiveLink(link)) {
// Let popup/interactive links behave normally (don't interfere)
return;
}

event.preventDefault(); // Block the default behavior
event.stopPropagation(); // Prevent bubbling so internal JS won't trigger navigation
setTimeout(() => {
window.open(link.href, '_blank'); // Open link in a new tab
}, 50); // Small delay for compatibility
}
}

// Attach the click listener to the whole document
document.addEventListener('click', openInNewTab, true);
})();
4 天前
回复了 sdrpsps 创建的主题 生活 1781 天后,我们还是分手了
@adsjcxeicxzs 原文更加准确

Life is like a river, and your life is a single-person raft drifting down that river. When you form a relationship you are tying a rope around someone else’s raft, and pulling them close to you so that as you carry on through the river of life, you won’t drift apart.

But sometimes the rapids will get more intense, and sometimes there will be boulders, or even other rafts that come between you and force your rafts apart. Sometimes one of you will end up in a fast-moving current while the other one ends up in the shallows, and slows down. When that happens, some of those ropes you’ve tied will weaken and some of them will break away.

When these problems arise, the ultimate question is not whether your relationship can survive— it’s whether you both want it to. It’s going to take some effort to pull your rafts back together. If you’re moving at different speeds then one of you may have to speed up or slow down their plans, or, more likely, you’ll meet somewhere in the middle.

But if you’re no longer moving through life at the same rate, in the same direction, or with the same destination in mind, then it’s okay to let go. We’re all going over a waterfall in the end, so don’t waste your time on the river struggling to stay with someone who doesn’t respect your own path.
4 天前
回复了 sdrpsps 创建的主题 生活 1781 天后,我们还是分手了
reddit 看到的, 感觉很透彻, 翻译后分享出来:
生活如同一条缓缓流淌的河,而你的人生就是独自漂行的小筏。当你与某人建立关系,你便用绳索把对方的筏系在自己身边,让彼此在河流中同行,不至于漂散。

然而,有时急流汹涌,有时礁石横亘,甚至其他筏子会挡在你们之间,将你们分开。偶尔,你顺流而下,他却滞于浅滩,渐渐拉开距离。此时,那些绳索,有的会松弛,有的会断裂。

面对这些波折,最终的问题不是关系能否继续,而是你们是否真心想要继续。要让筏子重聚,需要付出努力。有时,你得加速前行,有时,你得放慢脚步;更常见的,是在河流的某处相遇,在中间的某点找到平衡。

但若你们不再同向而行,不再步调一致,也不再怀抱相同的目标,那么放手也是一种解脱。毕竟,我们终将迎来瀑布之落,不必在河上,为了不尊重你生命之道的人,耗尽时光与力气。
9 天前
回复了 GaryLee 创建的主题 浏览器 chrome 还是 edge?
edge 其实挺好用的, 有一些比较新奇的功能. 但是害怕泄露隐私... 有了解的知道 edge 会泄露隐私吗?
297 天前
回复了 eggt 创建的主题 小米 为啥那么多人推荐小米油烟机啊?
用的 p1 半年多, 即使烟比较大的时候也会吸得很干净. 吸力不看参数看效果, 挺满意的. 开吸烟机的时候如果不开窗户, 1 米 5 开外的热水器, 都点不起火. 暂时没发现什么缺点
303 天前
回复了 wing929 创建的主题 生活 母亲突发脑溢血
@moonve 我是男生, 我也没打过拳. 按你说的情况角色互换, 当然会很痛苦, 但是我痛苦并不代表对方就是错的. 我觉得这种道德要求, 放自己身上提升自己就好. 用来指责别人, 不合适.
结合实际来说, 也有不少[ 疑问 ]的地方
1. 分手
什么叫分开没分手? 这是不是单方面定义的? 如果之前同居, 对方现在搬走了, 那么当做分手也很合理.
2. 感情
如果觉得自己感情很深, 对方很渣. 那么请问为什么要冷战, 冷战很伤害感情. 冷战[ 半个月 ]这么久, 为什么不沟通, 不解决? 做了哪些事情挽回感情? 平时是不是沟通方式就有问题?
3. 手术
既然联系了, 并且还愿意问你具体情况, 问了有没有可能要一直照顾, 那对方可能也不是决绝不想关心, 不然还搭理你干嘛呢? 但是你非要试探别人愿不愿意出钱, 愿不愿意赌一把以后一起照顾老人? 有话直说不行吗?
4. 看望
你想让对方看望, 是不是忘记了大家还在吵架冷战呢? 吵架的时候一个屁不放, 现在有事儿了想起来了. 我跟你正生气呢, 我还要装笑去你家吗? 你不先把咱俩问题解决? 我去看了之后那算咱俩好了还是没好还是怎么回事儿?

上面都是疑问的地方, 不能听楼主一面之词, 大家就谴责这个女生.
304 天前
回复了 wing929 创建的主题 生活 母亲突发脑溢血
@forgottencoast 这种关系啥关系.. 不就是男女朋友么... 还是半分手状态...
304 天前
回复了 wing929 创建的主题 生活 母亲突发脑溢血
@Chelseawin 感情也是俩人的感情, 不是跟他父母的感情...
304 天前
回复了 wing929 创建的主题 生活 母亲突发脑溢血
好奇怪.. 还没结婚呢, 为什么有些人怎么就道德绑架别人... 试问假如是你的女儿, 你愿意她还没结婚就承受这些? 这不是开玩笑么... 谁不想选择一个相对轻松的家庭... 感情又不能当饭吃, 婚姻本来就很物质, 又不是谈恋爱搞着玩..
我用的小米的, 好清理, 风力非常非常大.
351 天前
回复了 HeyCaptainJack 创建的主题 职场话题 坐标郑州,老前端 er 已失业
同郑州, 技术栈主要是前端渲染 & 游戏开发, 即 cocos unity threejs vtk
360 天前
回复了 xiaotongxin 创建的主题 生活 如何给在家干活的媳妇提供情绪价值?
帮忙分担家务更加务实. 家里的环境本身就是要一起维护的, 再加上家务活多是一些繁杂的体力活, 男生也理应更多的承担一些.
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2735 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 27ms · UTC 07:31 · PVG 15:31 · LAX 00:31 · JFK 03:31
Developed with CodeLauncher
♥ Do have faith in what you're doing.