Raw Source
Bluscream / Edge Extension Download Link Generator

// ==UserScript==
// @name Edge Extension Download Link Generator
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Generates a download link for Edge extensions and places it next to the Get button
// @author Bluscream
// @match https://microsoftedge.microsoft.com/addons/detail/*/*
// @grant none
// @license MIT
// @updateURL https://gist.github.com/Bluscream/5fef08f5782773b883f81d2c128773f9/raw/edge_extension_download_link_generator.user.js
// ==/UserScript==

(function() {
    'use strict';

    // Function to extract the extension ID from the URL path
    function getExtensionIdFromPath(url) {
        const pathParts = window.location.pathname.split('/');
        const extensionId = pathParts[pathParts.length - 1];
        console.log(`Extracted extension ID from path: ${extensionId}`); // Debug log
        return extensionId;
    }

    // Function to generate the download link
    function generateDownloadLink(extensionId) {
        const baseUrl = "https://edge.microsoft.com/extensionwebstorebase/v1/crx?response=redirect";
        const encodedId = encodeURIComponent(extensionId);
        const downloadLink = `${baseUrl}&x=id%3D${encodedId}%26installsource%3Dondemand%26uc`;
        console.log(`Generated download link: ${downloadLink}`); // Debug log
        return downloadLink;
    }

    // Function to create and style the download button
    function createDownloadButton(downloadLink) {
        const button = document.createElement('a');
        button.href = downloadLink;
        button.textContent = 'Get CRX';
        button.style.display = 'inline-block'; // Make it inline with the Get button
        button.style.marginInlineEnd = '8px'; // Match the spacing of the Get button
        button.className = 'c0195 c0196'; // Apply the same classes as the Get button // disable=c01102
        console.log('Creating download button...'); // Debug log
        return button;
    }

    // Main logic to execute when the page loads
    window.addEventListener('load', () => {
        console.log('Page loaded'); // Debug log
        const currentUrl = window.location.href;
        const extensionId = getExtensionIdFromPath(currentUrl);

        if (!extensionId) {
            console.error("Extension ID not found."); // Error log
            return;
        }

        const downloadLink = generateDownloadLink(extensionId);
        console.log(`Download link: ${downloadLink}`); // Debug log

        // Find the parent div of the Get button and insert the download button after it
        const getButtonParentDiv = document.querySelector('.css-87');
        if (!getButtonParentDiv) {
            console.error("Get button parent div not found."); // Error log
            return;
        }
        const downloadButton = createDownloadButton(downloadLink);
        getButtonParentDiv.appendChild(downloadButton);
        console.log('Download button added successfully.'); // Success log
    });
})();