Greasy Fork

Greasy Fork is available in English.

QuickDownloader

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

当前为 2024-10-11 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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();
})();