QuickDownloader

添加一个图标按钮来打开特定网页,带有当前页面的参数

目前為 2024-10-11 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         QuickDownloader
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  添加一个图标按钮来打开特定网页,带有当前页面的参数
// @match        *://*.amazon.com/*
// @match        *://*.amazon.co.uk/*
// @match        *://*.amazon.de/*
// @match        *://*.amazon.fr/*
// @match        *://*.amazon.it/*
// @match        *://*.amazon.es/*
// @match        *://*.amazon.ca/*
// @match        *://*.amazon.co.jp/*
// @match        *://*.amazon.cn/*
// @match        *://*.amazon.in/*
// @match        *://*.amazon.com.br/*
// @match        *://*.amazon.com.mx/*
// @match        *://*.amazon.com.au/*
// @match        *://*.amazon.nl/*
// @match        *://*.amazon.sg/*
// @grant        GM_addStyle
// @require      https://kit.fontawesome.com/4c29a4a2e7.js
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 添加 Font Awesome 样式
    GM_addStyle(`
        @import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css');
    `);

    // 创建按钮
    function createButton() {
        var button = document.createElement('button');
        button.innerHTML = '<i class="fas fa-download"></i>';
        button.title = '下载书籍'; // 添加tooltip
        button.style.top = '10px';
        button.style.right = '10px';
        button.style.zIndex = '9999';
        button.style.background = 'none';
        button.style.border = 'none';
        button.style.fontSize = '24px';
        button.style.color = '#0066c0'; // 修改为蓝色
        button.style.cursor = 'pointer';
        return button;
    }

    // 从页面提取参数
    function extractParams() {
        var productTitle = document.querySelector('#productTitle')?.textContent.trim();
        return encodeURIComponent(productTitle)
    }

    // 构建目标URL
    function buildTargetUrl(params) {
        return `https://zh.singlelogin.re/s/${params}?`;
    }

    // 插入按钮到指定位置
    function insertButton(button) {
        // 这里假设我们要将按钮插入到一个 ID 为 'product-title' 的元素后面
        var targetElement = document.querySelector('#productTitle');
        if (targetElement) {
            targetElement.parentNode.insertBefore(button, targetElement.nextSibling);
        } else {
            console.error('Target element for button insertion not found');
        }
    }

    // 主函数
    function main() {
        var button = createButton();

        button.addEventListener('click', function() {
            var params = extractParams();
            var targetUrl = buildTargetUrl(params);
            window.open(targetUrl, '_blank');
        });

        insertButton(button);
    }

    // 运行主函数
    main();
})();