Skip to content
This repository has been archived by the owner on Sep 10, 2023. It is now read-only.

Commit

Permalink
fix: 提升百度的稳定性
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Apr 10, 2022
1 parent 291f5df commit 0efa80f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 41 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -37,6 +37,7 @@
"gm-http": "^0.2.1",
"lodash.debounce": "^4.0.8",
"lodash.throttle": "^4.1.1",
"p-retry": "^5.1.0",
"reflect-metadata": "^0.1.13"
}
}
18 changes: 12 additions & 6 deletions src/sites/www.baidu.com.ts
Expand Up @@ -4,37 +4,43 @@ import {
getRedirect,
increaseRedirect,
decreaseRedirect,
antiRedirect
antiRedirect,
} from "@/utils";
import pRetry from "p-retry";

export class BaiduProvider implements IProvider {
public test = /www\.baidu\.com\/link\?url=/;
public resolve(aElement: HTMLAnchorElement) {
console.log(aElement);
if (getRedirect(aElement) <= 2 && this.test.test(aElement.href)) {
increaseRedirect(aElement);
this.handlerOneElement(aElement)
.then(res => {

pRetry(() => this.handlerOneElement(aElement), { retries: 3 })
.then((res) => {
decreaseRedirect(aElement);
})
.catch(err => {
.catch((err) => {
decreaseRedirect(aElement);
});
}
}

private async handlerOneElement(aElement: HTMLAnchorElement): Promise<any> {
try {
const res: Response$ = await http.request({
const res = await http.request({
url: aElement.href,
method: "GET",
anonymous: true
anonymous: true,
});

if (res.finalUrl) {
antiRedirect(aElement, res.finalUrl);
}

return res;
} catch (err) {
console.error(err);
return Promise.reject(new Error(`[http]: ${aElement.href} fail`));
}
}
}
71 changes: 36 additions & 35 deletions webpack.config.ts
Expand Up @@ -46,52 +46,53 @@ const webpackConfig: webpack.Configuration = {
banner: `// ==UserScript==
// @name ${pkg.name}
// @author ${pkg.author}
// @collaborator ${pkg.author}
// @description ${pkg.description}
// @version ${pkg.version}
// @update ${format(new Date(), "yyyy-MM-dd HH:mm:ss")}
// @grant GM_xmlhttpRequest
// @include *www.baidu.com*
// @include *tieba.baidu.com*
// @include *v.baidu.com*
// @include *xueshu.baidu.com*
// @include *www.google.*
// @include *docs.google.*
// @include *mail.google.*
// @include *play.google.*
// @include *youtube.com/watch?v=*
// @include *youtube.com/channel/*
// @include *encrypted.google.com*
// @include *www.so.com*
// @include *www.zhihu.com*
// @include *daily.zhihu.com*
// @include *zhuanlan.zhihu.com*
// @include *weibo.com*
// @include *twitter.com*
// @include *www.sogou.com*
// @include *juejin.im*
// @include *juejin.cn*
// @include *mail.qq.com*
// @include *addons.mozilla.org*
// @include *www.jianshu.com*
// @include *www.douban.com*
// @include *getpocket.com*
// @include *www.dogedoge.com*
// @include *51.ruyo.net*
// @include *steamcommunity.com*
// @include *mijisou.com*
// @include *blog.csdn.net*
// @include *.oschina.net*
// @include *app.yinxiang.com*
// @include *www.logonews.cn*
// @match *://www.baidu.com/*
// @match *://tieba.baidu.com/*
// @match *://v.baidu.com/*
// @match *://xueshu.baidu.com/*
// @match *://www.google.*
// @match *://docs.google.*
// @match *://mail.google.*
// @match *://play.google.*
// @match *://youtube.com/watch?v=*
// @match *://youtube.com/channel/*
// @match *://encrypted.google.com/*
// @match *://www.so.com/*
// @match *://www.zhihu.com/*
// @match *://daily.zhihu.com/*
// @match *://zhuanlan.zhihu.com/*
// @match *://weibo.com/*
// @match *://twitter.com/*
// @match *://www.sogou.com/*
// @match *://juejin.im/*
// @match *://juejin.cn/*
// @match *://mail.qq.com/*
// @match *://addons.mozilla.org/*
// @match *://www.jianshu.com/*
// @match *://www.douban.com/*
// @match *://getpocket.com/*
// @match *://www.dogedoge.com/*
// @match *://51.ruyo.net/*
// @match *://steamcommunity.com/*
// @match *://mijisou.com/*
// @match *://blog.csdn.net/*
// @match *://*.oschina.net/*
// @match *://app.yinxiang.com/*
// @match *://www.logonews.cn/*
// @connect www.baidu.com
// @connect *
// @compatible chrome 完美运行
// @compatible firefox 完美运行
// @supportURL https://axetroy.github.io/
// @supportURL https://github.com/axetroy/anti-redirect/issues/new/choose
// @homepage https://github.com/axetroy/anti-redirect
// @run-at document-start
// @contributionURL troy450409405@gmail.com|alipay.com
// @downloadURL https://github.com/axetroy/anti-redirect/raw/gh-pages/anti-redirect.user.js
// @updateURL https://github.com/axetroy/anti-redirect/raw/gh-pages/anti-redirect.user.js
// @namespace https://greasyfork.org/zh-CN/users/3400-axetroy
// @license Anti 996 License; https://github.com/axetroy/anti-redirect/blob/master/LICENSE
// ==/UserScript==
Expand Down

0 comments on commit 0efa80f

Please sign in to comment.