Bing URL Decoder

Decode the Bing URLs to get the direct result page URL

目前為 2023-04-15 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Bing URL Decoder
// @namespace    https://github.com/Auncaughbove17/my-userscripts/
// @version      0.1
// @description  Decode the Bing URLs to get the direct result page URL
// @author       Alistair1231
// @icon         https://icons.duckduckgo.com/ip2/bing.com.ico
// @grant        none
// @match        https://www.bing.com/*
// @license GPL-3.0
// ==/UserScript==

(function() {
    'use strict';

    function decodeBingUrl(url) {
        // Remove the leading "a1" characters from the value of the "u" parameter
        const uParamValue = url.searchParams.get('u').substring(2);
        // Decode the URL-safe Base64-encoded value
        const decodedValue = decodeURIComponent(
            atob(uParamValue.replace(/_/g, '/').replace(/-/g, '+'))
        );
        return decodedValue;
    }

    function decodeBingUrls(links) {
        links.forEach(link => {
            const decodedUrl = decodeBingUrl(new URL(link.href));
            link.href = decodedUrl;
        });
    }

    // Decode all "u" parameters in Bing URLs on the page
    const links = document.querySelectorAll('main a[href*="bing.com"][href*="&u="]');
    decodeBingUrls(links);

    // Use MutationObserver to detect new links added to the page
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            if (mutation.type === 'childList') {
                const newLinks = mutation.addedNodes;
                decodeBingUrls(newLinks);
            }
        });
    });

    // Observe changes in the main content area of the page
    const mainContent = document.querySelector('main');
    observer.observe(mainContent, { childList: true, subtree: true });

})();