Skip to content

Commit a34e3a4

Browse files
committed
feat: ✨ 选择文本打开链接由只开第一个改为打开全部
1 parent 29b1b40 commit a34e3a4

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

apps/common/right-click-tab/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# right-click-tab
22

3+
## 1.4.0
4+
5+
### Minor Changes
6+
7+
- 选择文本打开链接由只开第一个改为打开全部
8+
39
## 1.3.1
410

511
### Patch Changes

apps/common/right-click-tab/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "common-right-click-tab",
33
"type": "module",
4-
"version": "1.3.1",
4+
"version": "1.4.0",
55
"private": true,
66
"description": "右键超链接快速打开新标签页(Common Right Click Tab)-- 用户可以通过右键点击【普通链接、鼠标选中带链接的文字】等方式快速打开新标签页。效果类似于【Ctrl+左键】点击链接效果相同。",
77
"author": {

apps/common/right-click-tab/src/index.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,25 @@ const view = new View(store)
1313

1414
console.log(`${ID}(v${VERSION})`)
1515

16-
function tryGetUrl(element: Element): string | null {
16+
function tryGetUrls(element: Element): string[] | undefined {
1717
const selection = window.getSelection()?.toString()
1818
if (selection) {
1919
const urls = Array.from(getUrls(selection))
20-
return urls.length > 0
21-
? urls[0]
22-
// : selection
23-
: null
20+
if (urls.length > 0) {
21+
return urls
22+
}
2423
}
2524

2625
const link = element.closest('a')
27-
return link?.href || null
26+
if (link && link.href) {
27+
return [link.href]
28+
}
2829
}
2930

3031
document.addEventListener('contextmenu', (e: MouseEvent) => {
31-
const href = tryGetUrl(e.target as Element)?.trim()
32+
const urls = tryGetUrls(e.target as Element)
3233

33-
if (!href) {
34+
if (!urls) {
3435
return
3536
}
3637

@@ -40,13 +41,13 @@ document.addEventListener('contextmenu', (e: MouseEvent) => {
4041
timer = CLEANED
4142
if (store.trigger === 'double') {
4243
e.preventDefault()
43-
GM_openInTab(href, { active: store.active })
44+
urls.forEach(url => GM_openInTab(url, { active: store.active }))
4445
}
4546
return
4647
}
4748

4849
if (import.meta.env.DEV) {
49-
console.log(`open ${href} in ${store.active ? 'foreground' : 'background'} mode`)
50+
console.log(`open ${urls} in ${store.active ? 'foreground' : 'background'} mode`)
5051
}
5152

5253
if (store.trigger === 'single') {
@@ -57,7 +58,7 @@ document.addEventListener('contextmenu', (e: MouseEvent) => {
5758
// single click
5859
timer = CLEANED
5960
if (store.trigger === 'single') {
60-
GM_openInTab(href, { active: store.active })
61+
urls.forEach(url => GM_openInTab(url, { active: store.active }))
6162
}
6263
}, THRESHOLD)
6364
})

0 commit comments

Comments
 (0)