chrome extensions

This commit is contained in:
changjin wei(魏昌进) 2025-02-01 13:37:54 +08:00
parent b96aa95983
commit 732f94a869
20 changed files with 344 additions and 0 deletions

1
.gitignore vendored
View File

@ -128,3 +128,4 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.DS_Store

View File

@ -1,2 +1,6 @@
# AutoRedirector
AutoRedirector 是一款智能跳转插件,可自动绕过各大网站的中转链接,直接跳转到目标页面,提升浏览体验,减少不必要的等待和手动点击。支持 QQ、微信、CSDN、知乎、掘金、微博、豆瓣、LeetCode 等常见网站,智能解析 URL 或 HTML 页面中的真实目标链接,确保用户快速访问所需内容。
<a href="https://www.flaticon.com/free-icon/shuffle_1000607?term=redirect&related_id=1000607" title="random icons">Random icons created by Freepik - Flaticon</a>

11
_locales/en/messages.json Normal file
View File

@ -0,0 +1,11 @@
{
"extName": {
"message": "AutoRedirector",
"description": "The name of the extension"
},
"extDescription": {
"message": "Automatically bypass redirect pages and go directly to the target URL.",
"description": "Description of the extension"
}
}

View File

@ -0,0 +1,11 @@
{
"extName": {
"message": "自动跳转器",
"description": "插件名称"
},
"extDescription": {
"message": "AutoRedirector 是一款智能跳转插件,可自动绕过各大网站的中转链接,直接跳转到目标页面,提升浏览体验,减少不必要的等待和手动点击。支持 QQ、微信、CSDN、知乎、掘金、微博、豆瓣、LeetCode 等常见网站,智能解析 URL 或 HTML 页面中的真实目标链接,确保用户快速访问所需内容。",
"description": "插件简介"
}
}

133
background.js Normal file
View File

@ -0,0 +1,133 @@
// 配置对象:每个 hostname 对应一个跳转规则
const redirectMap = {
// 常规操作
"link.juejin.cn": { testHref: "https://link.juejin.cn/?target=https://github.com/galaxy-sea" },
"link.csdn.net": { testHref: "https://link.csdn.net/?target=https://github.com/galaxy-sea" },
"link.zhihu.com": { testHref: "https://link.zhihu.com/?target=https://github.com/galaxy-sea" },
"c.pc.qq.com": { testHref: "https://c.pc.qq.com/pc.html?url=https://github.com/galaxy-sea" },
"hd.nowcoder.com": { testHref: "https://hd.nowcoder.com/link.html?target=https://github.com/galaxy-sea" },
"link.uisdc.com": { testHref: "https://link.uisdc.com/?redirect=https://github.com/galaxy-sea" },
// 需要判断域名和路径
"www.jianshu.com": { path: "/go-wild", testHref: "https://www.jianshu.com/go-wild?ac=2&url=https://github.com/galaxy-sea" },
"www.douban.com": { path: "/link2", testHref: "https://www.douban.com/link2/?url=https://github.com/galaxy-sea" },
"steamcommunity.com": { path: "/linkfilter", testHref: "https://steamcommunity.com/linkfilter/?url=https://github.com/galaxy-sea" },
"www.tianyancha.com": { path: "/security", testHref: "https://www.tianyancha.com/security?target=http://github.com/galaxy-sea" },
"game.bilibili.com": { path: "/linkfilter", testHref: "https://game.bilibili.com/linkfilter/?url=https://github.com/galaxy-sea" },
"www.chinaz.com": { path: "/go.shtml", testHref: "https://www.chinaz.com/go.shtml?url=https://github.com/galaxy-sea" },
"www.youtube.com": { path: "/redirect", testHref: "https://www.youtube.com/redirect?q=https://github.com/galaxy-sea" },
"mail.qq.com": { path: "/cgi-bin/readtemplate", testHref: "https://mail.qq.com/cgi-bin/readtemplate?t=safety&check=false&gourl=https://github.com/galaxy-sea&subtemplate=gray&evil=0" },
"weibo.cn": { path: "/sinaurl", testHref: "https://weibo.cn/sinaurl?u=https://github.com/galaxy-sea" },
"afdian.com": { path: "/link", testHref: "https://afdian.com/link?target=https://github.com/galaxy-sea" },
"ask.latexstudio.net": { path: "/go/index", testHref: "https://ask.latexstudio.net/go/index?url=https://github.com/galaxy-sea" },
"blzxteam.com": { path: "/gowild", testHref: "https://blzxteam.com/gowild.htm?url=https://github.com/galaxy-sea" },
"cloud.tencent.com": { path: "/developer/tools/blog-entry", testHref: "https://cloud.tencent.com/developer/tools/blog-entry?target=http%3A%2F%2Fgithub.com%2Foctokit&objectId=1434763&objectType=1&isNewArticle=undefined" },
"docs.qq.com": { path: "/scenario/link.html", testHref: "https://docs.qq.com/scenario/link.html?url=https://github.com/galaxy-sea" },
"gitee.com": { path: "/link", testHref: "https://gitee.com/link?target=https://github.com/galaxy-sea" },
"leetcode.cn": { path: "/link", testHref: "https://leetcode.cn/link/?target=https://github.com/galaxy-sea" },
"sspai.com": { path: "/link", testHref: "https://sspai.com/link?target=https://github.com/galaxy-sea" },
"t.me": { path: "/iv", testHref: "https://t.me/iv?url=https://github.com/galaxy-sea" },
"tieba.baidu.com": { path: "/mo/q/checkurl", testHref: "https://tieba.baidu.com/mo/q/checkurl?url=https://github.com/galaxy-sea" },
"www.gcores.com": { path: "/link", testHref: "https://www.gcores.com/link?target=https://github.com/galaxy-sea" },
"www.kookapp.cn": { path: "/go-wild", testHref: "https://www.kookapp.cn/go-wild.html?url=https://github.com/galaxy-sea" },
"www.oschina.net": { path: "/action/GoToLink", testHref: "https://www.oschina.net/action/GoToLink?url=https://github.com/galaxy-sea" },
"www.qcc.com": { path: "/web/transfer-link", testHref: "https://www.qcc.com/web/transfer-link?link=https://github.com/galaxy-sea" },
"www.yuque.com": { path: "/r/goto", testHref: "https://www.yuque.com/r/goto?url=https://github.com/galaxy-sea" },
"xie.infoq.cn": { path: "/link", testHref: "https://xie.infoq.cn/link?target=https://github.com/galaxy-sea" },
"www.baike.com": { path: "/redirect_link", testHref: "https://www.baike.com/redirect_link?url=https://github.com/galaxy-sea" },
"developers.weixin.qq.com": { path: "/community/middlepage/href", testHref: "https://developers.weixin.qq.com/community/middlepage/href?href=https://github.com/galaxy-sea" },
"developer.aliyun.com": { path: "/redirect", testHref: "https://developer.aliyun.com/redirect?target=https://github.com/galaxy-sea" },
// "1111111": { path: "/111111", testHref: "" },
// 需要从html中解析出来
// manifest.json 文件添加一下白名单哦。
"weixin110.qq.com": {
method: redirectByDocQuerySelector,
param: "body > div > div.weui-msg__text-area > p",
testHref: "https://weixin110.qq.com/cgi-bin/mmspamsupport-bin/newredirectconfirmcgi?click=94e70da48e938d0145086c1c99a2ad71&bankey=1b60392a82c1f670f6c089ddc17234ba&midpagecode=e2faa0ee03e19e6efecf869b7f9ca0522c68d4854df6fbfa04376e4e5a76fb68051eaf8948fea39790a1cd7df4a64a26&bancode=2399cb39b79374a740f5d35881d294a89c5943a7ad8c941bad626d61c0fcf52d"
},
"t.cn": {
method: redirectByDocQuerySelector,
param: "#textline",
testHref: "https://t.cn/A6uN06Qy"
},
"jump.bdimg.com": {
method: redirectByDocQuerySelector,
param: "body > div > div.warning_info > p.link",
testHref: "https://jump.bdimg.com/safecheck/index?url=rN3wPs8te/r8jfr8YhogjfUWFoMgIRa8GuuBEpJ4eXO8AVsA2UkOV3OnAP38RLqgULlfrX2wNBE1ktsrhFGRdsUnCWH/dTBt0QiPKJTx1xte4mm563atJ0xgEMHDBR4XX1D3A8ieh9f3k7PccYSctkS252zuL3Y0uEoxzfbVtSg="
},
// 特殊的url
"blog.51cto.com": {
method: function (tabId, url, rule) {
debugger
if (rule.path && !new URL(url).pathname.startsWith(rule.path)) {
return;
}
chrome.tabs.update(tabId, { url: decodeURIComponent(url.replace("https://blog.51cto.com/transfer?", "")) });
},
path: "/transfer",
testHref: "https://blog.51cto.com/transfer?https://github.com/galaxy-sea"
},
};
const defaultConfig = {
method: redirectByUrl,
param: ["target", "url", "q", "gourl", "u", "redirect", "toasturl", "link", "href"]
};
function handleRedirect(tabId, url) {
// debugger;
const url_ = new URL(url);
const hostname = url_.hostname;
if (!redirectMap[hostname]) return;
const rule = { ...defaultConfig, ...redirectMap[hostname] };
if (typeof rule.method === "function") {
rule.method(tabId, url, rule);
}
}
function redirectByUrl(tabId, url, rule) {
const url_ = new URL(url);
const pathname = url_.pathname;
if (rule.path && !pathname.startsWith(rule.path)) {
return;
}
rule.param.forEach(param => {
const target = url_.searchParams.get(param);
if (target) {
chrome.tabs.update(tabId, { url: decodeURIComponent(target) });
}
});
}
function redirectByDocQuerySelector(tabId, url, rule) {
chrome.scripting.executeScript({
target: { tabId },
func: extractTargetFromHtml,
args: [rule.param]
});
}
function extractTargetFromHtml(param) {
// debugger;
const targetElement = document.querySelector(param);
if (targetElement) {
window.location.href = targetElement.textContent.trim();
}
}
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete' && tab.url) {
handleRedirect(tabId, tab.url);
}
// chrome.runtime.reload();
});
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === "install") {
chrome.tabs.create({ url: "./options.html" }); // 这里的 "welcome.html" 需要在插件的 `public` 目录下
}
});

BIN
icons/icon128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
icons/icon16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

BIN
icons/icon24.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
icons/icon256.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

BIN
icons/icon32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
icons/icon512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
icons/icon64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
images/AliPay.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 KiB

BIN
images/WeChatPay.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

40
manifest.json Normal file
View File

@ -0,0 +1,40 @@
{
"manifest_version": 3,
"name": " __MSG_extName__",
"version": "1.0",
"description": "__MSG_extDescription__",
"default_locale": "zh_CN",
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "icons/icon16.png",
"24": "icons/icon24.png",
"32": "icons/icon32.png",
"64": "icons/icon64.png",
"128": "icons/icon128.png"
}
},
"icons": {
"16": "icons/icon16.png",
"24": "icons/icon24.png",
"32": "icons/icon32.png",
"64": "icons/icon64.png",
"128": "icons/icon128.png"
},
"permissions": [
"activeTab",
"tabs",
"scripting",
"notifications"
],
"host_permissions": [
"*://weixin110.qq.com/*",
"*://t.cn/*",
"*://jump.bdimg.com/*"
],
"options_page": "options.html",
"background": {
"service_worker": "background.js"
}
}

36
options.html Normal file
View File

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>插件设置</title>
<link rel="stylesheet" href="./simple.css">
</head>
<body>
<h2>AutoRedirector 是一款智能跳转插件,可自动绕过各大网站的中转链接,直接跳转到目标页面,提升浏览体验,减少不必要的等待和手动点击。支持 QQ、微信、CSDN、知乎、掘金、微博、豆瓣、LeetCode
等常见网站,智能解析 URL 或 HTML 页面中的真实目标链接,确保用户快速访问所需内容。</h2>
<div style="display: flex;">
<div style="display: inline-block">
<button id="openAllButton">点击打开全部跳转链接</button>
<ul id="domainList">
</ul>
<script src="background.js"></script>
<script src="options.js"></script>
</div>
<div style="display: inline-block;">
<button id="openOptions">打开测试网页</button>
<button>新的中转链接反馈 或 bug反馈</button>
<p></p>
<h3 class="rainbow">善良的好人们行行好施舍点银子给我买包烟吧一块两块不嫌少三块四块会更好赠人香烟手有余香。——by爱抽烟的人</h3>
<p></p>
<image width="200" height="300" style="display: inline-block" src="images/WeChatPay.png"></image>
<image width="200" height="300" style="display: inline-block" src="images/AliPay.png"></image>
<script src="popup.js"></script>
</div>
</div>
</body>
</html>

31
options.js Normal file
View File

@ -0,0 +1,31 @@
document.addEventListener("DOMContentLoaded", function () {
const tableBody = document.getElementById("domainList");
if (Object.keys(redirectMap).length === 0) {
return;
}
var innerHTML = ""
Object.entries(redirectMap).forEach(([hostname, value]) => {
innerHTML = innerHTML + `
<li><a target="_blank" href="${value.testHref}">${hostname}</a></li>
`
});
tableBody.innerHTML = innerHTML
const openAllButton = document.getElementById("openAllButton");
openAllButton.addEventListener("click", function () {
const links = document.querySelectorAll("#domainList a"); // Get all <a> elements
let index = 0;
function openNextLink() {
if (index < links.length) {
window.open(links[index].href, "_blank");
index++;
setTimeout(openNextLink, 500); // Delay next link by 500ms
}
}
openNextLink(); // Start the process
});
});

43
popup.html Normal file
View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My First Extension</title>
<style>
body {
width: 404px;
/* height: 400px; */
font-family: Arial, sans-serif;
}
button {
width: 100%;
height: 40px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
</style>
<link rel="stylesheet" href="./simple.css">
</head>
<body>
<button id="openOptions">打开测试网页</button>
<button >新的中转链接反馈 或 bug反馈</button>
<p></p>
<h3 class="rainbow">善良的好人们行行好施舍点银子给我买包烟吧一块两块不嫌少三块四块会更好赠人香烟手有余香。——by爱抽烟的人</h3>
<p></p>
<image width="200" height="300" style="display: inline-block" src="images/WeChatPay.png"></image>
<image width="200" height="300" style="display: inline-block" src="images/AliPay.png"></image>
<script src="popup.js"></script>
</body>
</html>

4
popup.js Normal file
View File

@ -0,0 +1,4 @@
document.getElementById("openOptions").addEventListener("click", function () {
chrome.tabs.create({ url: "options.html" });
});

30
simple.css Normal file
View File

@ -0,0 +1,30 @@
@keyframes rainbowText {
0% {
color: red;
}
20% {
color: orange;
}
40% {
color: yellow;
}
60% {
color: green;
}
80% {
color: blue;
}
100% {
color: red;
}
}
.rainbow {
font-weight: bold;
animation: rainbowText 3s linear infinite;
}