Skip to content

Commit

Permalink
feat(remove-redirect): 适配搜狗搜索
Browse files Browse the repository at this point in the history
  • Loading branch information
maomao1996 committed Jul 20, 2024
1 parent e0bcc0d commit 2efc17b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-lions-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'remove-redirect': minor
---

适配搜狗搜索
2 changes: 1 addition & 1 deletion packages/remove-redirect/metablock.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name:en": "Remove Redirect",
"namespace": "maomao1996.remove-redirect",
"version": "1.12.0",
"description": "修复跳转链接为站外直链(移除重定向),免去拦截页面点击步骤可直达站外;拦截页面自动跳转;已适配爱发电、百度搜索、百度贴吧、Bing 搜索、酷安、CSDN、豆瓣、Facebook、码云、Google 搜索、Google 重定向页、花瓣网、InfoQ、Instagram、简书、掘金、金山文档、链滴、力扣(Leetcode)、51CTO 博客、NGA 玩家社区、牛客网、开源中国、pixiv、微信、微信开放社区、QQ 邮箱、PC 版 QQ、腾讯文档、腾讯兔小巢、360 搜索、少数派、腾讯云开发者社区、推特(Twitter)、微博、YouTube、语雀、知乎、知乎专栏",
"description": "修复跳转链接为站外直链(移除重定向),免去拦截页面点击步骤可直达站外;拦截页面自动跳转;已适配爱发电、百度搜索、百度贴吧、Bing 搜索、酷安、CSDN、豆瓣、Facebook、码云、Google 搜索、Google 重定向页、花瓣网、InfoQ、Instagram、简书、掘金、金山文档、链滴、力扣(Leetcode)、51CTO 博客、NGA 玩家社区、牛客网、开源中国、pixiv、微信、微信开放社区、QQ 邮箱、PC 版 QQ、腾讯文档、腾讯兔小巢、360 搜索、搜狗搜索、少数派、腾讯云开发者社区、推特(Twitter)、微博、YouTube、语雀、知乎、知乎专栏",
"author": "",
"homepage": "",
"supportURL": "",
Expand Down
4 changes: 3 additions & 1 deletion packages/remove-redirect/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ if (isArray(currentSite)) {
},
} = transform
const observer = new MutationObserver(() => {
document.querySelectorAll<HTMLAnchorElement>(selector).forEach(customTransform)
document
.querySelectorAll<HTMLAnchorElement>(selector)
.forEach(customTransform as CustomTransform<HTMLAnchorElement>)
})
observer.observe(document.body, { childList: true, subtree: true })
}
Expand Down
1 change: 1 addition & 0 deletions packages/remove-redirect/src/sites/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export { default as oschinaNet } from './oschina.net'
export { default as pixivNet } from './pixiv.net'
export { default as qqCom } from './qq.com'
export { default as soCom } from './so.com'
export { default as sogouCom } from './sogou.com'
export { default as sspaiCom } from './sspai.com'
export { default as tencentCom } from './tencent.com'
export { default as twitterCom } from './twitter.com'
Expand Down
44 changes: 44 additions & 0 deletions packages/remove-redirect/src/sites/sogou.com.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { validateUrl } from '@femm/shared-utils'
import { defineSite } from 'src/utils'

/******************************************************************************
** 搜狗搜索
** - https://sogou.com/web?query=mmPlayer
** - https://sogou.com/web?query=武林外传
**
** - https://m.sogou.com/web/searchList.jsp?keyword=mmPlayer
******************************************************************************/
const sites = [
defineSite<HTMLDivElement>([
'搜狗搜索',
'sogou.com',
{
transform: {
selector: '.results .vrwrap',
customTransform(node) {
const dataNode = node.querySelector<HTMLDivElement>('[data-url]')
if (dataNode) {
const originUrl = dataNode.dataset.url!
if (validateUrl(originUrl)) {
node
.querySelectorAll<HTMLAnchorElement>('a[href*="/link?url="]')
.forEach((a) => a.setAttribute('href', originUrl))
}
}
},
},
},
]),
defineSite([
,
'm.sogou.com',
{
transform: {
selector: 'a[href^="./id="]',
queryName: 'url',
},
},
]),
]

export default sites

0 comments on commit 2efc17b

Please sign in to comment.