Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. class Song{
  2. constructor(){};
  3.  
  4. titleAndAuthor(){
  5. var item = document.getElementsByClassName("track-info__name ellipsis-one-line")[0];
  6. item=item.getElementsByClassName("react-contextmenu-wrapper")[0];
  7. item = item.querySelectorAll("span");
  8. item = item[0].querySelectorAll("a");
  9.  
  10. return item;
  11. };
  12.  
  13. songDurationInfo(){
  14. return document.getElementsByClassName("playback-bar__progress-time");
  15. };
  16.  
  17. getSongTimerString(){
  18. return this.songDurationInfo()[0].innerText;
  19. };
  20.  
  21. getSongDurationString(){
  22. return this.songDurationInfo()[1].innerText;
  23. }
  24.  
  25. getSongTimeTotal(){
  26. var timeTotalStringSeconds = this.getSongDurationString()[this.getSongDurationString().length-2]+[this.getSongDurationString().length-1];
  27. var timeTotalStringMinutes = this.getSongDurationString().substring(0,this.getSongDurationString().length-3);
  28. var timeTotalInSec = parseInt(timeTotalStringMinutes) * 60 + parseInt(timeTotalStringSeconds)
  29. return timeTotalInSec;
  30. };
  31. getSongTimePassed(){
  32. var timePassedStringSeconds = this.getSongTimerString()[this.getSongTimerString().length-2] + [this.getSongTimerString().length-1];
  33. var timePassedStringMinutes = this.getSongTimerString().substring(0,this.getSongTimerString().length-3);
  34. var timePassedInSec = parseInt(timePassedStringMinutes) * 60 + parseInt(timePassedStringSeconds)
  35. return timePassedInSec;
  36. };
  37.  
  38. getSongTimeLeft(){
  39. return this.getSongTimeTotal()-this.getSongTimePassed();
  40. };
  41.  
  42. getTitle(){
  43. return this.titleAndAuthor()[0].innerText;
  44. };
  45.  
  46. getTitleLink(){
  47. return this.titleAndAuthor()[0].href;
  48. };
  49.  
  50. getArtistName(){
  51. var item = document.getElementsByClassName("track-info__artists link-subtle ellipsis-one-line")[0];
  52. item=item.getElementsByClassName("react-contextmenu-wrapper")[0];
  53. item = item.querySelectorAll("span");
  54. item = item[0].querySelectorAll("a");
  55. item = item[0].innerText;
  56. return item;
  57. };
  58. };
  59.  
  60. var test = new Song();
  61. // console.log(test.getTitle());
  62. // console.log(test.getArtistName());
  63. // console.log(test.getTitleLink());
  64. //console.log(test.getSongTimerString());
  65. //console.log(test.getSongDurationString());
  66.  
  67.  
  68.  
  69. console.log(test.getSongTimeTotal());
  70. console.log(test.getSongTimePassed());
  71. console.log(test.getSongTimeLeft());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement