Pocket

Count all the links, open on middle click

  1. // ==UserScript==
  2. // @name Pocket
  3. // @version 0.3.3
  4. // @description Count all the links, open on middle click
  5. // @author Cáno
  6. // @match https://getpocket.com/a/queue/list/*
  7. // @grant unsafeWindow, chrome, notifications
  8. // @require http://code.jquery.com/jquery-latest.js
  9. // @namespace http://tampermonkey.net/
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15.  
  16. unsafeWindow.openLinks = function() {
  17. var els = $('.original_url');
  18.  
  19. Array.prototype.forEach.call(els, function(el) {
  20. if ($(el).parent().parent().parent().parent('.item:not(.removed)').length === 0) {
  21. return;
  22. }
  23. var address = el.href.substr(el.href.indexOf('redirect?url=') + 13);
  24. address = address.substr(0, address.indexOf('&formCheck='));
  25. address = decodeURIComponent(address);
  26. // console.log(address);
  27. unsafeWindow.open(address,'_blank');
  28. });
  29. };
  30.  
  31. //document.getElementsByClassName("queue_secondarynav_actions")[0].childNodes[1].innerHTML = document.getElementsByClassName("queue_secondarynav_actions")[0].childNodes[1].innerHTML + '<li style="color:#909090; margin-top: 18px; font-size: 16px; cursor: pointer; font-weight: bold" onclick="openLinks()">Open all links</li>';
  32.  
  33. unsafeWindow.openTwentyLinksAndArchive = function(howMany) {
  34.  
  35. $('.original_url').each(function(index) {
  36. if (index >= howMany) {
  37. return;
  38. }
  39. var el = this;
  40. if ($(el).parent().parent().parent().parent('.item:not(.removed)').length === 0) {
  41. return;
  42. }
  43. var address = el.href.substr(el.href.indexOf('redirect?url=') + 13);
  44. address = address.substr(0, address.indexOf('&formCheck='));
  45. address = decodeURIComponent(address);
  46. $(el).parent().parent().parent().find('ul.buttons li.action_mark a')[0].click();
  47. unsafeWindow.open(address,'_blank');
  48. });
  49. setTimeout(function() {
  50. location.reload();
  51. }, 8000);
  52. };
  53.  
  54. document.getElementsByClassName("queue_secondarynav_actions")[0].childNodes[1].innerHTML = document.getElementsByClassName("queue_secondarynav_actions")[0].childNodes[1].innerHTML + '<li style="color:#909090; margin-top: 18px; font-size: 16px; cursor: pointer; font-weight: bold" onclick="openTwentyLinksAndArchive(20)">Open and archive 20 links</li>';
  55.  
  56.  
  57. unsafeWindow.archiveLinks = function() {
  58. var els = $('li.item:not(.removed) .action_mark');
  59.  
  60. if (els.length > 0) {
  61. els[0].childNodes[0].click();
  62. setTimeout(unsafeWindow.archiveLinks, 160);
  63. }
  64. };
  65.  
  66. var html = document.getElementsByClassName("queue_secondarynav_actions")[0].childNodes[1].innerHTML;
  67.  
  68. setInterval( setUp, 2000 );
  69. function setUp() {
  70.  
  71. unsafeWindow.$('.item.item_type_normal .item_content').each(function() {
  72. unsafeWindow.$(this).trigger("mouseover");
  73. });
  74.  
  75. var state = document.readyState;
  76. if (state == 'interactive') {
  77. } else if (state == 'complete') {
  78. var count = $('.original_url').parent().parent().parent().parent('.item:not(.removed)').length;
  79. $('#archive-all-links').remove();
  80. $('.pagenav_bulkedit').after('<li id="archive-all-links" style="color:#909090; margin-top: 18px; font-size: 16px; cursor: pointer; font-weight: bold" onclick="archiveLinks()">Archive all links (' + count + ')</li>');
  81. }
  82. }
  83.  
  84. function triggerMouseEvent (node, eventType) {
  85. var clickEvent = document.createEvent('MouseEvents');
  86. clickEvent.initEvent (eventType, true, true);
  87. node.dispatchEvent (clickEvent);
  88. }
  89.  
  90. function archiveOnClick(e) {
  91. if (e.which != 2) return false;
  92. $(e.target).parent().parent().parent().find('ul.buttons li.action_mark a')[0].click();
  93. }
  94.  
  95. setInterval( setUpArichiveOnClick, 2000 );
  96. function setUpArichiveOnClick() {
  97. $('a.original_url').off('mouseup', archiveOnClick);
  98. $('a.original_url').on('mouseup', archiveOnClick);
  99. }
  100. })();