soundcloud scroll queue

Adds a button that automatically scrolls the queue until disabled

目前为 2019-10-06 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name soundcloud scroll queue
  3. // @version 1.0.1
  4. // @description Adds a button that automatically scrolls the queue until disabled
  5. // @author bhackel
  6. // @match https://soundcloud.com/*
  7. // @grant none
  8. // @run-at document-idle
  9. // @noframes
  10. // @namespace https://greasyfork.org/en/users/324178-bhackel
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. /* Injects a button into the Next Up queue that runs the script.
  17. */
  18. function setup() {
  19. var btn = document.createElement('Button');
  20. btn.className = 'bhackelSCScroll sc-button sc-button-medium';
  21. btn.innerHTML = 'Scroll Down';
  22. btn.onclick = function(){ start(this); };
  23.  
  24. var queue_panel = document.getElementsByClassName('queue__panel')[0];
  25. if (queue_panel) {
  26. queue_panel.insertBefore(btn, queue_panel.children[1]);
  27. } else {
  28. setTimeout(setup, 1000);
  29. }
  30. }
  31.  
  32. /* Function called by the button being clicked. Either creates
  33. an interval to run the scroll function or clears the current interval.
  34. */
  35. function start(d){
  36. if (d.interval){
  37. clearInterval(d.interval);
  38. d.interval = 0;
  39. d.innerHTML = 'Scroll Down';
  40. } else {
  41. d.interval = setInterval(scroll, 1000);
  42. d.innerHTML = 'Stop Scrolling';
  43. }
  44. }
  45.  
  46. /* Scrolls the queue down to a pixel value, found in one of the
  47. heights of one of the elements.
  48. */
  49. function scroll() {
  50. var scrollableQueue = document.getElementsByClassName('queue__scrollableInner g-scrollable-inner').item(0);
  51. var queueContainer = document.getElementsByClassName('queue__itemsHeight').item(0);
  52. var scrollToHeight = parseInt(queueContainer.style.height);
  53. scrollableQueue.scroll(0,scrollToHeight);
  54. }
  55.  
  56. setup();
  57.  
  58. })();