From d2f34672943edd8bec92e85cb716e4fc77ea28d5 Mon Sep 17 00:00:00 2001 From: simonkimi Date: Thu, 21 Dec 2023 15:02:51 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=BD=E9=99=85?= =?UTF-8?q?=E7=89=88bing=E5=BD=93=E9=93=BE=E6=8E=A5=E5=A4=AA=E9=95=BF?= =?UTF-8?q?=E6=97=B6=E9=87=8D=E5=AE=9A=E5=90=91=E9=93=BE=E6=8E=A5=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98,=20=E5=90=8C?= =?UTF-8?q?=E6=97=B6=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=85=B6=E4=BB=96=E9=83=A8?= =?UTF-8?q?=E4=BD=8D=E7=9A=84=E9=87=8D=E5=AE=9A=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AC-Baidu-SoGou-Google-NoRedirect.user.js | 160 ++++++++++++++++++----- 1 file changed, 127 insertions(+), 33 deletions(-) diff --git a/AC-Baidu-SoGou-Google-NoRedirect.user.js b/AC-Baidu-SoGou-Google-NoRedirect.user.js index c7772e0..6c46e8a 100644 --- a/AC-Baidu-SoGou-Google-NoRedirect.user.js +++ b/AC-Baidu-SoGou-Google-NoRedirect.user.js @@ -2504,6 +2504,7 @@ body[google] { } if (curSite.SiteTypeID === SiteType.GOOGLE) removeOnMouseDownFunc(); // 移除onMouseDown事件,谷歌去重定向 if (curSite.SiteTypeID === SiteType.MBAIDU) removeMobileBaiduDirectLink(); // 处理百度手机版本的重定向地址 + if (curSite.SiteTypeID === SiteType.BING) resetBingOthers(); // bing的其他重定向 removeRedirectLinkTarget(); // 只移除知乎的重定向问题 & 百度学术重定向问题 safeRemove(".res_top_banner"); // 移除百度可能显示的劫持 } @@ -3154,6 +3155,122 @@ body[google] { } } + function getBingRealLinkByUrl(linkHref) { + return new Promise((resolve, reject) => { + if (linkHref.indexOf("www.bing.com/ck/a") === -1) { + reject("Unsupported link") + return; + } + GM_xmlhttpRequest({ + // from: "acxhr", + url: linkHref, + headers: { "Accept": "*/*", "Referer": linkHref }, + method: "GET", + timeout: 8000, + onload: function(response) { + if (response.responseText || response.status === 200) { + const realLink = Reg_Get(response.responseText, "u\\s?=\\s\"(.+?)\";"); + if (realLink !== "") { + resolve(realLink); + } + reject(''); + return; + } + reject('') + }, + onerror: function (err) { + reject(err) + } + }) + }); + } + + function resetBingOthers() { + if (document.querySelector("#est_cn") != null) { + return; + } + + // 右侧百科卡片重定向 + const cardNode = document.querySelector("#b_context .b_sideBleed"); + if (cardNode != null) { + // 描述和图片, 这俩链接不一样但是指向一样 + const desA = cardNode.querySelector(".l_ecrd_imcolheader_desc a"); + const icon = cardNode.querySelector(".l_ecrd_webicon_txtside"); + let url = []; + if (desA != null && desA.getAttribute("ac_redirectStatus") !== "2") { + url.push(desA.href); + } + if (icon != null && icon.getAttribute("ac_redirectStatus") !== "2") { + url.push(icon.href); + } + if (url.length > 0) { + getBingRealLinkByUrl(url[0]).then(realLink => { + url.forEach(link => DealRedirect(null, link, realLink, null)); + }); + } + + // 浏览更多 + let moreSearchList = cardNode.querySelectorAll(".l_ecrd_simgset_item") + for (const searchItem of moreSearchList) { + const link = searchItem.querySelector(".as_pasf_data") + if (link != null) { + const linkHref = link.href; + getBingRealLinkByUrl(linkHref).then(realLink => DealRedirect(null, linkHref, realLink, null, 'subtitle')) + } + } + } + } + + function resetBingNormal(curNode, linkHref) { + const realLinkNode = curNode.querySelector(".b_attribution cite"); + if (!realLinkNode || !realLinkNode.textContent) return false; + let realLink = realLinkNode.textContent; + if (!(realLink.startsWith("http://") || realLink.startsWith("https://"))) { + realLink = "https://" + realLink; + } + + function replaceBingLink(linkHref, realLink) { + DealRedirect(null, linkHref, realLink, null); + // 文章结构分析界面 + if (curNode.classList.contains("b_algoBorder")) { + // 对于章节, 后置拼接 + const chapterTitles = curNode.querySelectorAll(".b_rc_gb_sub_title>a"); + for (const chapterTitle of chapterTitles) { + const link = chapterTitle.getAttribute("href"); + const title = chapterTitle.textContent; + if (!link || !title) continue; + const chapterLink = realLink + "#" + title; + DealRedirect(null, link, chapterLink, null, 'subtitle'); + } + // 对于图片, 使用原始链接 + const chapterImages = curNode.querySelectorAll(".b_rc_gb_img_wrapper>a"); + for (const img of chapterImages) { + const link = img.getAttribute("href"); + if (!link) continue; + DealRedirect(null, link, realLink, null, 'subtitle'); + } + } + return true; + } + + if (realLink.endsWith("...") || realLink.endsWith("bing.com/videos")) { + // 链接没有显示全, 需要调用接口获取真是链接 + let url = linkHref.replace(/^http:/, "https:"); + getBingRealLinkByUrl(url).then(link => { + replaceBingLink(linkHref, link) + }) + } else { + replaceBingLink(linkHref, realLink); + } + + // 对于相关链接, 必须走接口请求真实链接 + let linkNodes = document.querySelectorAll(".b_algospacing_block>.b_algospacing_link") + for (const linkNode of linkNodes) { + const linkHref = linkNode.href; + getBingRealLinkByUrl(linkNode.href).then(realLink => DealRedirect(null, linkHref, realLink, null)); + } + } + function resetURLNormal() { const mainList = document.querySelectorAll(curSite.MainType) @@ -3190,39 +3307,16 @@ body[google] { DealRedirect(null, linkHref, trueLink); return true } - // MARK bing国际版 & 国内版 数据解析 这里目前有严重bug,暂时无法复现重定向流程,先停止重定向 - // if(curSite.SiteTypeID === SiteType.BING) { - // // 链接数据 - // const realLinkNode = curNode.querySelector(".b_attribution cite"); - // if (!realLinkNode || !realLinkNode.textContent) return false; - // let realLink = realLinkNode.textContent; - // console.log(realLink) - // return - // if (!(realLink.startsWith("http://") || realLink.startsWith("https://"))) { - // realLink = "https://" + realLink; - // } - // DealRedirect(null, linkHref, realLink, null); - // // 文章结构分析界面 - // if (curNode.classList.contains("b_algoBorder")) { - // // 对于章节, 后置拼接 - // const chapterTitles = curNode.querySelectorAll(".b_rc_gb_sub_title>a"); - // for (const chapterTitle of chapterTitles) { - // const link = chapterTitle.getAttribute("href"); - // const title = chapterTitle.textContent; - // if (!link || !title) continue; - // const chapterLink = realLink + "#" + title; - // DealRedirect(null, link, chapterLink, null, 'subtitle'); - // } - // // 对于图片, 使用原始链接 - // const chapterImages = curNode.querySelectorAll(".b_rc_gb_img_wrapper>a"); - // for (const img of chapterImages) { - // const link = img.getAttribute("href"); - // if (!link) continue; - // DealRedirect(null, link, realLink, null, 'subtitle'); - // } - // } - // return true; - // } + // bing国际版重定向 + if(curSite.SiteTypeID === SiteType.BING) { + // 国内版bing链接为原始链接, 不需要重定向 + if (document.querySelector("#est_cn") != null) { + return true; + } + + resetBingNormal(curNode, linkHref); + return true; + } } const getBaiduEncodingHandle = (linkUrl) => { let resLink = linkUrl From 21cb7d34c01034cf21a4c95c3e789b985ed3eb00 Mon Sep 17 00:00:00 2001 From: simonkimi Date: Thu, 21 Dec 2023 15:20:28 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AC-Baidu-SoGou-Google-NoRedirect.user.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AC-Baidu-SoGou-Google-NoRedirect.user.js b/AC-Baidu-SoGou-Google-NoRedirect.user.js index 6c46e8a..45711ea 100644 --- a/AC-Baidu-SoGou-Google-NoRedirect.user.js +++ b/AC-Baidu-SoGou-Google-NoRedirect.user.js @@ -3222,6 +3222,10 @@ body[google] { } function resetBingNormal(curNode, linkHref) { + // 不清楚还有没有其他类型的重定向链接, 先只处理这一种 + if (linkHref.indexOf("www.bing.com/ck/a") === -1) { + return ; + } const realLinkNode = curNode.querySelector(".b_attribution cite"); if (!realLinkNode || !realLinkNode.textContent) return false; let realLink = realLinkNode.textContent; From c62a8ca4597de3290b8d334ae20ee039a0094618 Mon Sep 17 00:00:00 2001 From: simonkimi Date: Thu, 21 Dec 2023 16:05:07 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=B8=BAcell=E4=B8=AD=E7=9A=84"=E5=B1=95?= =?UTF-8?q?=E5=BC=80"=E6=8C=89=E9=92=AE=E4=B9=9F=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=87=8D=E5=AE=9A=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AC-Baidu-SoGou-Google-NoRedirect.user.js | 27 ++++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/AC-Baidu-SoGou-Google-NoRedirect.user.js b/AC-Baidu-SoGou-Google-NoRedirect.user.js index 45711ea..3904400 100644 --- a/AC-Baidu-SoGou-Google-NoRedirect.user.js +++ b/AC-Baidu-SoGou-Google-NoRedirect.user.js @@ -3233,19 +3233,32 @@ body[google] { realLink = "https://" + realLink; } - function replaceBingLink(linkHref, realLink) { + function replaceBingLink(curNode, linkHref, realLink) { DealRedirect(null, linkHref, realLink, null); + // 文章内的展开按钮 + const expandBtn = curNode.querySelector(".b_rc_gb_sub_hero .b_paractl > a") + if (expandBtn) { + DealRedirect(null, expandBtn.href, realLink, null, 'link'); + } + // 文章结构分析界面 if (curNode.classList.contains("b_algoBorder")) { // 对于章节, 后置拼接 - const chapterTitles = curNode.querySelectorAll(".b_rc_gb_sub_title>a"); - for (const chapterTitle of chapterTitles) { - const link = chapterTitle.getAttribute("href"); - const title = chapterTitle.textContent; + const cells = curNode.querySelectorAll("#b_rc_gb_origin .b_rc_gb_sub_cell"); + for (const cell of cells) { + const titleNode = cell.querySelector(".b_rc_gb_sub_title>a"); + if (!titleNode) continue; + const link = titleNode.getAttribute("href"); + const title = titleNode.textContent; if (!link || !title) continue; const chapterLink = realLink + "#" + title; DealRedirect(null, link, chapterLink, null, 'subtitle'); + const expandBtn = cell.querySelector(".b_paractl>a"); + if (expandBtn) { + DealRedirect(null, expandBtn.href, chapterLink, null, 'link'); + } } + // 对于图片, 使用原始链接 const chapterImages = curNode.querySelectorAll(".b_rc_gb_img_wrapper>a"); for (const img of chapterImages) { @@ -3261,10 +3274,10 @@ body[google] { // 链接没有显示全, 需要调用接口获取真是链接 let url = linkHref.replace(/^http:/, "https:"); getBingRealLinkByUrl(url).then(link => { - replaceBingLink(linkHref, link) + replaceBingLink(curNode, linkHref, link) }) } else { - replaceBingLink(linkHref, realLink); + replaceBingLink(curNode, linkHref, realLink); } // 对于相关链接, 必须走接口请求真实链接 From 992c4797753ea02378d6c2cf7a83a74acb661d14 Mon Sep 17 00:00:00 2001 From: simonkimi Date: Mon, 25 Dec 2023 16:24:19 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=AD=E9=97=B4?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E7=9C=81=E7=95=A5=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AC-Baidu-SoGou-Google-NoRedirect.user.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/AC-Baidu-SoGou-Google-NoRedirect.user.js b/AC-Baidu-SoGou-Google-NoRedirect.user.js index 3904400..f983076 100644 --- a/AC-Baidu-SoGou-Google-NoRedirect.user.js +++ b/AC-Baidu-SoGou-Google-NoRedirect.user.js @@ -3270,7 +3270,10 @@ body[google] { return true; } - if (realLink.endsWith("...") || realLink.endsWith("bing.com/videos")) { + if (realLink.endsWith("...") || + realLink.endsWith("bing.com/videos") || + realLink.indexOf("/.../") !== -1 + ) { // 链接没有显示全, 需要调用接口获取真是链接 let url = linkHref.replace(/^http:/, "https:"); getBingRealLinkByUrl(url).then(link => {