Feedly Youtube Playlist and Open Multiple Links

try to take over the world!

  1. // ==UserScript==
  2. // @name Feedly Youtube Playlist and Open Multiple Links
  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 isYoutube = window.location.href.indexOf('youtube') > -1 ? true:false;
  19.  
  20. var doStuff = function(){
  21. var isYoutube = window.location.href.indexOf('youtube') > -1 ? true:false;
  22. var t = document.getElementsByClassName('unread')
  23. //var ctr = 10;
  24. var ctr = parseInt(document.getElementsByClassName("hint centered")[0].innerText.split(" ")[1], 10);
  25. //ctr = ctr -1;
  26. var index = 0
  27. var aa = []
  28. //await sleep(2000);
  29. Array.prototype.forEach.call(t, function(e) {
  30. if(index<ctr) {
  31. var link = e.getAttribute('data-alternate-link')
  32. aa.push(link)
  33. demo(e);
  34. } else if(index===(ctr-1)) {
  35. playlist(aa)
  36. end()
  37. }
  38. index += 1
  39. });
  40. playlist(aa)
  41. end()
  42. function sleep(ms) {
  43. return new Promise(resolve => setTimeout(resolve, ms));
  44. }
  45.  
  46. async function demo(e) {
  47. await sleep(2000);
  48. e.click()
  49. }
  50.  
  51. async function end() {
  52. await sleep(4000);
  53. document.getElementsByClassName('giant-mark-as-read')[0].click()
  54. }
  55.  
  56. function playlist(aa){
  57.  
  58. var URI = "http://www.youtube.com/watch_videos?video_ids=";
  59. var final = URI;
  60. var counter = 1;
  61. aa.forEach(function(n, index) {
  62.  
  63. if(isYoutube) {
  64. if(counter <= ctr) { // As youtube only allows 20 videos/playlist in this case
  65. final += n.split("?v=")[1] + ","
  66. counter += 1;
  67. } else {
  68. console.log(final);
  69. final = URI;
  70. counter = 1;
  71. final += n.split("?v=")[1] + ","
  72. counter += 1;
  73. }
  74. } else{
  75. window.open(n)
  76. }
  77.  
  78. });
  79. if(isYoutube){
  80. console.log(final);
  81. window.open(final);
  82. }
  83.  
  84.  
  85. }
  86. }
  87.  
  88. document.onkeydown = function(evt) {
  89. evt = evt || window.event;
  90. if (evt.keyCode == 81) {
  91.  
  92. doStuff();
  93. }
  94. };
  95.  
  96.  
  97. // document.getElementsByClassName('titleBar')[0].onclick = function(e){
  98. // doStuff()
  99. //}
  100. })();
  101.