SoundCloud Keybinder

Allows for customization of SoundCloud keybinds, and adds a keybind to open the Add to Playlist menu.

  1. // ==UserScript==
  2. // @name SoundCloud Keybinder
  3. // @version 1.0
  4. // @description Allows for customization of SoundCloud keybinds, and adds a keybind to open the Add to Playlist menu.
  5. // @author bhackel
  6. // @match https://soundcloud.com/*
  7. // @grant none
  8. // @run-at document-end
  9. // @noframes
  10. // @namespace https://gf.qytechs.cn/en/users/324178-bhackel
  11. // ==/UserScript==
  12. // jshint esversion: 6
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. /****** Settings ******/
  18. let blockedKeys = []; // List of keys that will be blocked. Ex: ['r', 'l'];
  19. let addToPlaylistKey = 'a'; // Key for opening the Add to Playlist menu for the active song
  20. /****** Settings ******/
  21.  
  22. let keybinder = function (event) {
  23. // Do nothing if the user is typing in a text box
  24. if (document.activeElement.tagName === 'INPUT') {
  25. return;
  26. }
  27. // Block keypresses specified in list
  28. else if (blockedKeys.includes(event.key)) {
  29. // Prevent other listeners from doing anything
  30. event.stopPropagation();
  31. }
  32. // Add keybind for Add to Playlist hotkey
  33. else if (event.key === addToPlaylistKey) {
  34. openLoadQueue();
  35. }
  36. };
  37.  
  38. // Insert the listener above the default onkeydown listener
  39. window.addEventListener("keydown", keybinder, true);
  40.  
  41.  
  42. /* Functions for the Add to Playlist hotkey */
  43.  
  44. // Opens and waits for the song queue to load
  45. function openLoadQueue() {
  46. // Check if it is already open
  47. let queue = document.querySelector('.m-queueVisible');
  48. if (queue === null) {
  49. let queueButton = document.querySelector('.playbackSoundBadge__queueCircle');
  50. queueButton.click();
  51. setTimeout(openLoadQueue, 500);
  52. return;
  53. }
  54. // If queue gets opened, wait for it to load before running next part
  55. setTimeout(openAddToPlaylist, 1250);
  56. }
  57.  
  58. // With an open and loaded queue, clicks the Add to Playlist menu
  59. function openAddToPlaylist() {
  60. // Close queue
  61. let queueButton = document.querySelector('.playbackSoundBadge__queueCircle');
  62. queueButton.click();
  63. // Open the menu with additional actions
  64. let activeSong = document.querySelector('.queueItemView.sc-border-box.sc-font-light.m-active');
  65. let moreButton = activeSong.querySelector('.sc-button-more');
  66. moreButton.click();
  67. // Click the Add to Playlist button
  68. let menuActions = document.querySelector('.moreActions');
  69. let addToPlaylist = document.querySelector('.sc-button-addtoset');
  70. addToPlaylist.click();
  71. // Put focus back on play/pause button
  72. document.querySelector('.playControl').focus();
  73. }
  74. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址