Feedly Youtube Playlist v2

try to take over the world!

  1. // ==UserScript==
  2. // @name Feedly Youtube Playlist v2
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://feedly.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. var stateObj = {
  15. foo: "bar",
  16. };
  17.  
  18. var doStuff = function(){
  19. var t = document.getElementsByClassName('unread')
  20. //var ctr = 10;
  21. var ctr = parseInt(document.getElementsByClassName("hint centered")[0].innerText.split(" ")[1], 10);
  22. //ctr = ctr -1;
  23. var index = 0
  24. var aa = []
  25. //await sleep(2000);
  26. Array.prototype.forEach.call(t, function(e) {
  27. if(index<ctr) {
  28. var link = e.getAttribute('data-alternate-link')
  29. aa.push(link)
  30. demo(e);
  31. } else if(index===(ctr-1)) {
  32. playlist(aa)
  33. end()
  34. }
  35. index += 1
  36. });
  37. playlist(aa)
  38. end()
  39. function sleep(ms) {
  40. return new Promise(resolve => setTimeout(resolve, ms));
  41. }
  42.  
  43. async function demo(e) {
  44. await sleep(2000);
  45. e.click()
  46. }
  47.  
  48. async function end() {
  49. await sleep(4000);
  50. document.getElementsByClassName('close-button icon-fx-cross-ios-sm-black')[0].click()
  51. }
  52.  
  53. function playlist(aa){
  54.  
  55. var URI = "http://www.youtube.com/watch_videos?video_ids=";
  56. var final = URI;
  57. var counter = 1;
  58. aa.forEach(function(n, index) {
  59.  
  60. if(counter <= ctr) { // As youtube only allows 20 videos/playlist in this case
  61. final += n.split("?v=")[1] + ","
  62. counter += 1;
  63. } else {
  64. console.log(final);
  65. final = URI;
  66. counter = 1;
  67. final += n.split("?v=")[1] + ","
  68. counter += 1;
  69. }
  70.  
  71. });
  72. console.log(final);
  73. window.open(final);
  74.  
  75. }
  76. }
  77.  
  78. document.onkeydown = function(evt) {
  79. evt = evt || window.event;
  80. if (evt.keyCode == 89) {
  81. doStuff();
  82. }
  83. };
  84.  
  85.  
  86. // document.getElementsByClassName('titleBar')[0].onclick = function(e){
  87. // doStuff()
  88. //}
  89. })();
  90.