Bing Direct Link

This script is for removing Bing Redirect link, but this doesn't support privacy, as it fetch the redirect result of the URL

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Bing Direct Link
// @namespace    http://github.com/benyaminl
// @version      0.14
// @description  This script is for removing Bing Redirect link, but this doesn't support privacy, as it fetch the redirect result of the URL
// @author       Benyamin Limanto
// @match        https://www.bing.com/search*
// @icon         https://icons.duckduckgo.com/ip2/bing.com.ico
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function replaceTheRestOfURL() {
        var urls = document.querySelectorAll("a[href*='https://www.bing.com/ck']:not(.b_logoArea)");
        for(i=0;i < urls.length; i++)
        {
            let url = urls[i];
            fetch(url.href)
                .then(r => r.text())
                .then(d => {
                try {
                    let realUrl = d.match(/https:\/\/.+/i)[0].replace("\";","");

                    url.href = realUrl;
                }
                catch(e)
                {
                    console.log(e);
                }
            });
        }
    }

    var urlBody = document.querySelectorAll(".tilk");
    var i = -1;
    for(i=0; i < urlBody.length; i++)
    {
        let url = urlBody[i];
        let stringUrl = url.querySelector("cite");

        fetch(url.href)
            .then(r => r.text())
            .then(d => {
            let realUrl = d.match(/https:\/\/.+/i)[0].replace("\";","");
            let h2Url = url.parentNode.parentNode.querySelector("h2 a");
            h2Url.href = realUrl;
        });
    }

    var urlCard = document.querySelectorAll(".rd_sg_ttl");
    for(i=0; i < urlCard.length; i++)
    {
        let url = urlCard[i];
        let cite = urlCard[i].parentNode.querySelector("cite");

        fetch(url.querySelector("a").href)
            .then(r => r.text())
            .then(d => {
            let realUrl = d.match(/https:\/\/.+/i)[0].replace("\";","");
            url.querySelector("a").href = realUrl;
        });

    }

    replaceTheRestOfURL();

    // Hook for rest dynamic part of page, using timeout
    document.querySelector("#b_results").addEventListener("click", function(e) {
        let target = e.target;

        console.log("clicked");
        let counter = 0;
        let check = setInterval(function() {
            replaceTheRestOfURL();
            counter++;
            if (counter > 5)
            {
                console.log("stopped");
                clearInterval(check);
            }

        }, 1000);
    });

})();