Bing Link Redirect Decoder

Decode Bing redirect URLs and replace them with the actual URLs.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Bing Link Redirect Decoder
// @namespace    MickyFoley
// @version      1.0
// @description  Decode Bing redirect URLs and replace them with the actual URLs.
// @author       MickyFoley
// @match        *://*.bing.com/*
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function decodeBingURL(encodedURL) {
        // Modify the encoded URL to match Base64 encoding
        let modifiedEncodedURL = encodedURL.replace('-', '+').replace('_', '/');

        // Add padding if necessary
        let paddingNeeded = modifiedEncodedURL.length % 4;
        if (paddingNeeded) {
            modifiedEncodedURL += '='.repeat(4 - paddingNeeded);
        }

        // Decode the URL and return
        return atob(modifiedEncodedURL);
    }

    function processLinks() {
        const links = document.querySelectorAll('a[href*="bing.com/ck/"]');
        links.forEach(link => {
            const urlMatch = link.href.match(/u=([^&]+)/);
            if (urlMatch && urlMatch[1]) {
                const decodedURL = decodeBingURL(urlMatch[1].slice(2));
                link.href = decodedURL;
                link.title = "Decoded URL: " + decodedURL;
            }
        });
    }

    // Process links when the page loads and also when new content is added
    processLinks();
    new MutationObserver(processLinks).observe(document.body, { childList: true, subtree: true });
})();