Guest User

Tampermonkey (Soundgasm)

a guest
May 7th, 2024
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | Source Code | 0 0
  1. // ==UserScript==
  2. // @name Soundgasm
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description adds keyboard controls and extends container to utilize more screen realestate
  6. // @author gigi
  7. // @match *://*.soundgasm.net/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=soundgasm.net
  9. // @grant none
  10. // ==/UserScript==
  11. var a=document.getElementById('jp_audio_0');
  12. document.body.appendChild(document.createElement('style')).textContent = `
  13. #jp_container_1 {width:auto;}
  14. .jp-progress {right:120px; width:auto !important;}
  15. .jp-volume-controls {right:-90px; left:auto;}
  16. .jp-speed {position:absolute; top:0px; left:230px; padding:0 5px; background:#ccc; border-radius:7px; border:solid 1.5px #3eafe7; font-weight:bolder; cursor:pointer; font-size:10.24px;}
  17. .jp-speed-info {position:absolute; top:0px; left:252px; padding:0 8px; font-size:10.24px; font-style:oblique; line-height:16px;}
  18. body {overflow-x:hidden; background:black;}
  19. `;
  20. var slower=document.createElement('div');
  21. var faster=document.createElement('div');
  22. var info=document.createElement('div');
  23. info.id='speed-info';
  24. slower.id='slower';
  25. faster.id='faster';
  26. slower.classList.add('jp-speed');
  27. faster.classList.add('jp-speed');
  28. info.classList.add('jp-speed-info')
  29. slower.textContent='-';
  30. faster.textContent='+';
  31. info.textContent='1.0';
  32. faster.style.left='290px';
  33. faster.style.padding='0 3px';
  34. document.getElementsByClassName('jp-time-holder')[0].appendChild(slower);
  35. document.getElementsByClassName('jp-time-holder')[0].appendChild(faster);
  36. document.getElementsByClassName('jp-time-holder')[0].appendChild(info);
  37. document.getElementById('slower').addEventListener ("click", function(){a.playbackRate-=0.1;document.getElementById('speed-info').textContent=a.playbackRate.toFixed(1);} , false);
  38. document.getElementById('faster').addEventListener ("click", function(){a.playbackRate+=0.1;document.getElementById('speed-info').textContent=a.playbackRate.toFixed(1);} , false);
  39.  
  40. window.addEventListener("keydown",
  41. (event) => {
  42. if (event.defaultPrevented) {
  43. return; // Do nothing if the event was already processed
  44. }
  45.  
  46. if('1234567890'.indexOf(event.key)>=0) {
  47. document.getElementsByTagName('audio')[0].fastSeek((document.getElementsByTagName('audio')[0].duration/10)*event.key);
  48. } else if(event.key == ' ') {
  49. document.getElementsByTagName('audio')[0].paused ? document.getElementsByTagName('audio')[0].play() : document.getElementsByTagName('audio')[0].pause()
  50. } else if(event.key == 'ArrowRight') {
  51. document.getElementsByTagName('audio')[0].fastSeek((document.getElementsByTagName('audio')[0].currentTime+5));
  52. } else if(event.key == 'ArrowLeft') {
  53. document.getElementsByTagName('audio')[0].fastSeek((document.getElementsByTagName('audio')[0].currentTime-5));
  54. } else if(event.key == 'ArrowUp') {
  55. a.playbackRate+=0.1;document.getElementById('speed-info').textContent=a.playbackRate.toFixed(1);
  56. } else if(event.key == 'ArrowDown') {
  57. a.playbackRate-=0.1;document.getElementById('speed-info').textContent=a.playbackRate.toFixed(1);
  58. }
  59. else {
  60. console.log(event.key);
  61. return;
  62. }
  63.  
  64. // Cancel the default action to avoid it being handled twice
  65. event.preventDefault();
  66. },
  67. true,
  68. );
Advertisement
Add Comment
Please, Sign In to add comment