Insert a custom link before the first child element on specific app pages, fill in the URL, and auto-click the button
当前为
// ==UserScript==
// @name UWP App Jump to Download
// @version 0.0.2
// @description Insert a custom link before the first child element on specific app pages, fill in the URL, and auto-click the button
// @author aspen138
// @match *://apps.microsoft.com/detail/*
// @namespace tampermonkey
// @license MIT
// @grant none
// ==/UserScript==
// test case: https://apps.microsoft.com/detail/9nt1r1c2hh7j?hl=en-us&gl=US
(function() {
'use strict';
// Wait until the DOM is fully loaded
window.addEventListener('load', function() {
// The link you want to insert
const linkURL = 'https://store.rg-adguard.net/';
// Find the first child element of the body or any desired element
const firstChild = document.body.firstElementChild;
if (firstChild) {
// Create a new div to serve as the banner
const banner = document.createElement('div');
banner.style.display = 'flex';
banner.style.justifyContent = 'center';
banner.style.alignItems = 'center';
banner.style.height = '100px'; // Adjust the height as needed
banner.style.backgroundColor = '#FF0000'; // Red background for visibility
banner.style.color = '#FFFFFF'; // White text for contrast
banner.style.margin = '10px 0'; // Margin for spacing
banner.style.borderRadius = '5px'; // Rounded corners for the link
banner.style.textDecoration = 'none'; // Remove underline
banner.style.boxSizing = 'border-box'; // Ensure padding and border are included in the element’s total width/height
// Create a new anchor tag element
const newLink = document.createElement('a');
newLink.href = linkURL;
newLink.textContent = 'Click here to download app from store.rg-adguard.net';
newLink.target = '_blank';
newLink.style.textAlign = 'center'; // Centers the text
newLink.style.fontSize = '20px'; // Larger font for readability
newLink.style.fontWeight = 'bold'; // Bold text
newLink.style.width = '100%'; // Ensures the link spans the full width of the container
newLink.style.height = '100%'; // Ensures the link spans the full height of the container
newLink.style.display = 'block'; // Makes the link a block-level element (takes full width)
// Append the link to the banner
banner.appendChild(newLink);
// Insert the new banner before the first child element
document.body.insertBefore(banner, firstChild);
}
// Find the input field by its ID and the button to click
const urlInput = document.getElementById('url');
const generateButton = document.querySelector('input[type="button"][value="✔"]');
// Check if the elements exist before interacting with them
if (urlInput && generateButton) {
// Fill in the URL input with the current page's URL
urlInput.value = window.location.href;
// Simulate a click on the button to generate temporary links
generateButton.click();
}
});
})();