Last active
July 12, 2024 19:10
-
-
Save Bluscream/5fef08f5782773b883f81d2c128773f9 to your computer and use it in GitHub Desktop.
Edge Extension Download Link Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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 | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment