mirror of
https://github.com/galaxy-sea/AutoRedirector.git
synced 2026-10-24 08:54:32 +00:00
baike.baidu.com
This commit is contained in:
1 parent
e57343d177
commit
1a91ebce9c
4 files changed
+32
-9
No files matched your search
+26
-6
@@ -74,6 +74,16 @@ const redirectMap = {
|
||||
param: "body > div > div.warning_info > p.link",
|
||||
testHref: "https://jump.bdimg.com/safecheck/index?url=rN3wPs8te/r8jfr8YhogjfUWFoMgIRa8GuuBEpJ4eXO8AVsA2UkOV3OnAP38RLqgULlfrX2wNBE1ktsrhFGRdsUnCWH/dTBt0QiPKJTx1xte4mm563atJ0xgEMHDBR4XX1D3A8ieh9f3k7PccYSctkS252zuL3Y0uEoxzfbVtSg="
|
||||
},
|
||||
"baike.baidu.com": {
|
||||
path: "/reference",
|
||||
method: redirectByDocQuerySelector,
|
||||
param: "#root > div > div > div > a > strong",
|
||||
sleep: 1000,
|
||||
testHref: "https://baike.baidu.com/reference/124767/533aYdO6cr3_z3kATPHdnfn3ZnrHYoitt7bQUbdzzqIPmGapB4P1FJ836c828Ll2BUXIv5Utc5kRpM-kdy4cupBZLLxVE7REzxKiLWeV"
|
||||
},
|
||||
|
||||
// 需要从html中解析出来
|
||||
// manifest.json 文件添加一下白名单哦。
|
||||
|
||||
// 特殊的url
|
||||
"blog.51cto.com": {
|
||||
@@ -105,11 +115,8 @@ async function handleRedirect(tabId, url) {
|
||||
}
|
||||
|
||||
async function redirectByUrl(tabId, url, rule) {
|
||||
const url_ = new URL(url);
|
||||
const pathname = url_.pathname;
|
||||
if (rule.path && !pathname.startsWith(rule.path)) {
|
||||
return;
|
||||
}
|
||||
const url_ = await precheckAndSleep(url, rule);
|
||||
if (!url_) return;
|
||||
rule.param.forEach(param => {
|
||||
const target = url_.searchParams.get(param);
|
||||
if (target) {
|
||||
@@ -119,6 +126,8 @@ async function redirectByUrl(tabId, url, rule) {
|
||||
}
|
||||
|
||||
async function redirectByDocQuerySelector(tabId, url, rule) {
|
||||
const url_ = await precheckAndSleep(url, rule);
|
||||
if (!url_) return;
|
||||
if (browserAPI.scripting && browserAPI.scripting.executeScript) {
|
||||
// Chrome / Edge (MV3)
|
||||
browserAPI.scripting.executeScript({
|
||||
@@ -134,7 +143,6 @@ async function redirectByDocQuerySelector(tabId, url, rule) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function extractTargetFromHtml(param) {
|
||||
const targetElement = document.querySelector(param);
|
||||
if (targetElement) {
|
||||
@@ -142,6 +150,18 @@ async function extractTargetFromHtml(param) {
|
||||
}
|
||||
}
|
||||
|
||||
async function precheckAndSleep(url, rule) {
|
||||
const url_ = new URL(url);
|
||||
const pathname = url_.pathname;
|
||||
if (rule.path && !pathname.startsWith(rule.path)) {
|
||||
return null;
|
||||
}
|
||||
if (rule.sleep) {
|
||||
await new Promise(r => setTimeout(r, rule.sleep));
|
||||
}
|
||||
return url_;
|
||||
}
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/onUpdated
|
||||
// The status property will cycle through "loading" and "complete".
|
||||
const lastTabUrls = new Map();
|
||||
|
||||
@@ -29,7 +29,8 @@
|
||||
"*://weixin110.qq.com/*",
|
||||
"*://t.cn/*",
|
||||
"*://jump.bdimg.com/*",
|
||||
"*://jump2.bdimg.com/*"
|
||||
"*://jump2.bdimg.com/*",
|
||||
"*://baike.baidu.com/reference/*"
|
||||
],
|
||||
"options_page": "options.html",
|
||||
"background": {
|
||||
|
||||
+2
-1
@@ -29,7 +29,8 @@
|
||||
"*://weixin110.qq.com/*",
|
||||
"*://t.cn/*",
|
||||
"*://jump.bdimg.com/*",
|
||||
"*://jump2.bdimg.com/*"
|
||||
"*://jump2.bdimg.com/*",
|
||||
"*://baike.baidu.com/reference/*"
|
||||
],
|
||||
"options_page": "options.html",
|
||||
"background": {
|
||||
|
||||
@@ -29,7 +29,8 @@
|
||||
"*://weixin110.qq.com/*",
|
||||
"*://t.cn/*",
|
||||
"*://jump.bdimg.com/*",
|
||||
"*://jump2.bdimg.com/*"
|
||||
"*://jump2.bdimg.com/*",
|
||||
"*://baike.baidu.com/reference/*"
|
||||
],
|
||||
"options_page": "options.html",
|
||||
"background": {
|
||||
|
||||
Reference in new issue
Block a user