Soundcloud - Add External Download Button

adds a button on main page and song page to download song automatically from https://soundcloudmp3.org/

  1. // ==UserScript==
  2. // @name Soundcloud - Add External Download Button
  3. // @namespace https://zachhardesty.com
  4. // @author Zach Hardesty <zachhardesty7@users.noreply.github.com> (https://github.com/zachhardesty7)
  5. // @description adds a button on main page and song page to download song automatically from https://soundcloudmp3.org/
  6. // @copyright 2019, Zach Hardesty (https://zachhardesty.com/)
  7. // @license GPL-3.0-only; http://www.gnu.org/licenses/gpl-3.0.txt
  8. // @version 2.1.3
  9.  
  10. // @homepageURL https://github.com/zachhardesty7/tamper-monkey-scripts-collection/raw/master/soundcloud-download-button.user.js
  11. // @homepageURL https://openuserjs.org/scripts/zachhardesty7/Soundcloud_-_Add_External_Download_Button
  12. // @supportURL https://github.com/zachhardesty7/tamper-monkey-scripts-collection/issues
  13.  
  14.  
  15. // @match https://soundcloud.com/*
  16. // @match https://loader.to/*
  17. // @require https://greasyfork.org/scripts/419640-onelementready/code/onElementReady.js?version=887637
  18. // ==/UserScript==
  19. /* global onElementReady */
  20.  
  21. /**
  22. * adds button to soundcloud
  23. *
  24. * @param {HTMLElement} el - most recently added children (for lazy load)
  25. */
  26. function addSoundcloudDownloadButton(el) {
  27. const link = window.location.href
  28. const button = document.createElement("button")
  29. button.textContent = "External Download"
  30.  
  31. // if on soundcloud home and song node is not a playlist, append SC styled button
  32. if (
  33. link.includes("stream") &&
  34. !(
  35. /** @type {HTMLAnchorElement} */ (
  36. el.querySelector(".soundTitle__title")
  37. ).href.includes("/sets/")
  38. )
  39. ) {
  40. button.className = "mp3-button sc-button sc-button-small"
  41. el.querySelector(".soundActions .sc-button-group").append(button)
  42. // else if on individual song page (and not playlist), append SC styled button
  43. } else if (
  44. !link.includes("stream") &&
  45. (!link.includes("/sets/") || link.includes("?in="))
  46. ) {
  47. const toolbar = document.querySelector(".soundActions div:first-child")
  48. button.className = "mp3-button sc-button sc-button-medium"
  49. toolbar.append(button)
  50. }
  51.  
  52. el.querySelector(".mp3-button").addEventListener("click", () => {
  53. window.open(
  54. `https://loader.to/?link=${link}&f=1&s=1&e=1&r=ddownr`,
  55. "_blank"
  56. )
  57. })
  58. }
  59.  
  60. // auto-run on soundcloud mp3
  61. // if referred from soundcloud, grab data from GM storage
  62. // paste and submit to begin conversion to mp3
  63. function mp3() {
  64. const { href } = window.location
  65. if (href.includes("loader.to")) {
  66. onElementReady(
  67. "#ds .card .section:last-of-type > progress",
  68. { findOnce: false },
  69. (/** @type {HTMLProgressElement} */ progress) => {
  70. const timer = setInterval(() => {
  71. if (progress.value === 1000) {
  72. const button = document.querySelector(
  73. "#ds .card .section:last-of-type > a"
  74. )
  75. button.click()
  76. clearInterval(timer)
  77. }
  78. }, 100)
  79. }
  80. )
  81. } else {
  82. onElementReady(
  83. ".l-listen-wrapper",
  84. { findOnce: false },
  85. addSoundcloudDownloadButton
  86. )
  87. onElementReady(
  88. ".lazyLoadingList__list > .soundList__item",
  89. { findOnce: false },
  90. addSoundcloudDownloadButton
  91. )
  92. }
  93. }
  94.  
  95. mp3()