Sleazy Fork is available in English.

Soundgasm Progress Bar

Adds a progress bar when uploading a file to Soundgasm. Also displays an estimated time of completion.

  1. // ==UserScript==
  2. // @name Soundgasm Progress Bar
  3. // @description Adds a progress bar when uploading a file to Soundgasm. Also displays an estimated time of completion.
  4. // @namespace RoundPension
  5. // @include https://soundgasm.net/upload
  6. // @version 1.0
  7. // @license MIT-0
  8. // ==/UserScript==
  9.  
  10. var form = document.querySelector("form");
  11.  
  12. var req = new XMLHttpRequest();
  13. var progbar;
  14. var eta;
  15. var starttime;
  16. var lasttime;
  17.  
  18. form.addEventListener("submit", function(e) {
  19. e.preventDefault();
  20. req.upload.addEventListener("progress", prog);
  21. req.upload.addEventListener("loadstart", start);
  22. req.addEventListener("load", end);
  23. req.open("POST", "https://soundgasm.net/upload");
  24. req.send(new FormData(form));
  25. });
  26.  
  27. function start() {
  28. starttime = Date.now();
  29. lasttime = starttime;
  30. var div = document.createElement("div");
  31. document.querySelector("body").append(div);
  32. div.innerHTML += `
  33. <label>
  34. Uploading File: <progress id="prog" value="0"></progress>
  35. </label>
  36. <p>Estimated time remaining: <span id="eta"></span></p>`;
  37. progBar = document.getElementById("prog");
  38. eta = document.getElementById("eta");
  39. }
  40.  
  41. function prog(e) {
  42. var ratio = e.loaded/e.total
  43. progBar.value = ratio;
  44. if (Date.now() - lasttime > 1000) {
  45. updateETA(ratio);
  46. }
  47. }
  48.  
  49. function end() {
  50. document.querySelector("body").innerHTML = `
  51. <p>Upload completed!</p>
  52. <p><a href="https://soundgasm.net/upload">Upload another</a></p>`
  53. }
  54.  
  55. function updateETA(ratio) {
  56. lasttime = Date.now();
  57. var totalTime = (Date.now() - starttime)/ratio;
  58. var etaTime = totalTime*(1-ratio);
  59. eta.innerHTML = msToTime(etaTime);
  60. }
  61.  
  62. //modified from https://stackoverflow.com/a/19700358
  63. function msToTime(duration) {
  64. var seconds = Math.floor((duration / 1000) % 60),
  65. minutes = Math.floor((duration / (1000 * 60)) % 60),
  66. hours = Math.floor(duration / (1000 * 60 * 60));
  67. minutes = (minutes < 10) ? "0" + minutes : minutes;
  68. seconds = (seconds < 10) ? "0" + seconds : seconds;
  69.  
  70. return hours + ":" + minutes + ":" + seconds;
  71. }