QuickDownloader

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

目前为 2024-10-11 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name QuickDownloader
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description 添加一个图标按钮来打开特定网页,带有当前页面的参数
  6. // @match *://*.amazon.com/*
  7. // @match *://*.amazon.co.uk/*
  8. // @match *://*.amazon.de/*
  9. // @match *://*.amazon.fr/*
  10. // @match *://*.amazon.it/*
  11. // @match *://*.amazon.es/*
  12. // @match *://*.amazon.ca/*
  13. // @match *://*.amazon.co.jp/*
  14. // @match *://*.amazon.cn/*
  15. // @match *://*.amazon.in/*
  16. // @match *://*.amazon.com.br/*
  17. // @match *://*.amazon.com.mx/*
  18. // @match *://*.amazon.com.au/*
  19. // @match *://*.amazon.nl/*
  20. // @match *://*.amazon.sg/*
  21. // @grant GM_addStyle
  22. // @require https://kit.fontawesome.com/4c29a4a2e7.js
  23. // @license MIT
  24. // ==/UserScript==
  25.  
  26. (function() {
  27. 'use strict';
  28.  
  29. // 添加 Font Awesome 样式
  30. GM_addStyle(`
  31. @import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css');
  32. `);
  33.  
  34. // 创建按钮
  35. function createButton() {
  36. var button = document.createElement('button');
  37. button.innerHTML = '<i class="fas fa-download"></i>';
  38. button.title = '下载书籍'; // 添加tooltip
  39. button.style.top = '10px';
  40. button.style.right = '10px';
  41. button.style.zIndex = '9999';
  42. button.style.background = 'none';
  43. button.style.border = 'none';
  44. button.style.fontSize = '24px';
  45. button.style.color = '#0066c0'; // 修改为蓝色
  46. button.style.cursor = 'pointer';
  47. return button;
  48. }
  49.  
  50. // 从页面提取参数
  51. function extractParams() {
  52. var productTitle = document.querySelector('#productTitle')?.textContent.trim();
  53. return encodeURIComponent(productTitle)
  54. }
  55.  
  56. // 构建目标URL
  57. function buildTargetUrl(params) {
  58. return `https://zh.singlelogin.re/s/${params}?`;
  59. }
  60.  
  61. // 插入按钮到指定位置
  62. function insertButton(button) {
  63. // 这里假设我们要将按钮插入到一个 ID 为 'product-title' 的元素后面
  64. var targetElement = document.querySelector('#productTitle');
  65. if (targetElement) {
  66. targetElement.parentNode.insertBefore(button, targetElement.nextSibling);
  67. } else {
  68. console.error('Target element for button insertion not found');
  69. }
  70. }
  71.  
  72. // 主函数
  73. function main() {
  74. var button = createButton();
  75.  
  76. button.addEventListener('click', function() {
  77. var params = extractParams();
  78. var targetUrl = buildTargetUrl(params);
  79. window.open(targetUrl, '_blank');
  80. });
  81.  
  82. insertButton(button);
  83. }
  84.  
  85. // 运行主函数
  86. main();
  87. })();