Samplefocus Downloader

Replaces the original download button with one that directly downloads the mp3 file using a server-side proxy. Adds download notification and customizable filename. Compatible with Chromium, Firefox, and WebKit.

当前为 2025-03-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Samplefocus Downloader
  3. // @name:fr Téléchargeur Samplefocus
  4. // @name:de Samplefocus-Downloader
  5. // @namespace http://tampermonkey.net/
  6. // @version 2.0
  7. // @description Replaces the original download button with one that directly downloads the mp3 file using a server-side proxy. Adds download notification and customizable filename. Compatible with Chromium, Firefox, and WebKit.
  8. // @description:fr Remplace le bouton de téléchargement d'origine par un bouton qui télécharge directement le fichier MP3 via un proxy serveur. Ajoute une notification de téléchargement et un nom de fichier personnalisable.
  9. // @description:de Ersetzt die ursprüngliche Download-Schaltfläche durch eine Schaltfläche, die die MP3-Datei über einen Proxy-Server direkt herunterlädt. Fügt eine Download-Benachrichtigung und einen anpassbaren Dateinamen hinzu.
  10. // @author ToxicBiohazard
  11. // @match *://*.samplefocus.com/*
  12. // @grant none
  13. // @license MIT
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. console.log('Samplefocus Downloader script started.');
  20.  
  21. // Check if the script has already been executed
  22. if (document.getElementById('samplefocus-downloader-script')) {
  23. console.log('Script already executed. Exiting.');
  24. return;
  25. }
  26.  
  27. // Add an element to mark the script execution
  28. const scriptMarker = document.createElement('div');
  29. scriptMarker.id = 'samplefocus-downloader-script';
  30. document.body.appendChild(scriptMarker);
  31.  
  32. const originalLink = document.querySelector('.download-link');
  33.  
  34. if (!originalLink) {
  35. console.warn('Original download link not found.');
  36. return;
  37. }
  38.  
  39. const audioElement = document.querySelector('audio');
  40.  
  41. if (!audioElement || !audioElement.src) {
  42. console.error('No audio element found or no source loaded.');
  43. return;
  44. }
  45.  
  46. const audioSrc = audioElement.src;
  47. console.log('Audio source:', audioSrc);
  48.  
  49. const downloadSample = () => {
  50. const fileName = prompt('Enter the filename for the downloaded audio:', 'extracted-audio.mp3');
  51. if (fileName) {
  52. const link = document.createElement('a');
  53. link.href = `http://localhost:3000/download?url=${encodeURIComponent(audioSrc)}`; // Pass the audio URL as a query parameter
  54. link.download = fileName;
  55. document.body.appendChild(link);
  56. link.click();
  57. document.body.removeChild(link);
  58. console.log('Download initiated.');
  59. alert('Download started!');
  60. }
  61. };
  62.  
  63. const downloadButton = document.createElement('button');
  64. downloadButton.classList.add('btn-large', 'waves-effect', 'waves-light', 'samplefocus-download-btn');
  65. downloadButton.textContent = 'Download Sample';
  66. downloadButton.addEventListener('click', downloadSample);
  67.  
  68. // Add styles for the button
  69. const style = document.createElement('style');
  70. style.textContent = `
  71. .samplefocus-download-btn {
  72. background-color: #4CAF50;
  73. color: white;
  74. padding: 15px 32px;
  75. text-align: center;
  76. font-size: 16px;
  77. margin: 4px 2px;
  78. cursor: pointer;
  79. border: none;
  80. border-radius: 4px;
  81. }
  82. .samplefocus-download-btn:hover {
  83. background-color: #45a049;
  84. }
  85. `;
  86. document.head.appendChild(style);
  87.  
  88. originalLink.parentNode.replaceChild(downloadButton, originalLink);
  89. console.log('Download button added.');
  90. })();