pocketSelectAll

9/Oct/2020

  1. // ==UserScript==
  2. // @name pocketSelectAll
  3. // @namespace Violentmonkey Scripts
  4. // @match https://app.getpocket.com/*
  5. // @grant none
  6. // @version 1.2
  7. // @author AdrianSkar
  8. // @description 9/Oct/2020
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. setTimeout(() => {// Pocket loads content (including buttons) asynchronously
  13. let listen = document.querySelector("button[aria-label='Bulk Edit']");
  14.  
  15. function buttons() {
  16.  
  17. setTimeout(() => {// Pocket loads content (including buttons) asynchronously
  18. let selectVis = function () {
  19. function eventFire(el) {
  20. let evt = new MouseEvent("click", {
  21. view: window,
  22. bubbles: true,
  23. cancelable: true,
  24. });
  25. el.dispatchEvent(evt);
  26. }
  27. //svg
  28. let target = document.getElementsByTagName("use");
  29.  
  30. //loop trough <use> elements (some are not articles)
  31. for (let i = 0; i < target.length; i++) {
  32. // check if targets are selectable articles
  33. if ((target[i].getAttribute('xlink:href').indexOf("CheckOpen") > -1)) {
  34. //click on them
  35. eventFire(target[i]);
  36. }
  37. else {
  38. // console.log(target[i], 'is not clickable');
  39. }
  40. }
  41.  
  42. };
  43. // console.log(' close bulk');
  44.  
  45. //prepend buttons before the close bulk edit one
  46. //prepend buttons before the close bulk edit one
  47. let responsiveX = document.querySelector('[*|href*="CloseX"]'); // X button on responsive
  48.  
  49. let bulk = document.querySelector("button[aria-label='Close Bulk Edit']");
  50. let selVis = bulk.cloneNode();
  51. let selAll = bulk.cloneNode();
  52.  
  53. selVis.textContent = 'Select visible';
  54. selAll.textContent = 'Select all';
  55.  
  56. //load styles depending on responsive or desktop version
  57. if (responsiveX) {
  58. let styleRes = 'margin-right: 0.5em; min-width: 4em; font-size: 0.8em; border: 1px solid lightgray; border-radius: 4px;';
  59. selVis.setAttribute('style', styleRes);
  60. selAll.setAttribute('style', styleRes);
  61. } else {
  62. let styleDes = 'margin-right: 0.5em;';
  63. selVis.setAttribute('style', styleDes);
  64. selAll.setAttribute('style', styleDes);
  65. }
  66. bulk.parentElement.prepend(selVis);
  67. bulk.parentElement.prepend(selAll);
  68.  
  69. // select all articles (selectVis + scroll every 2secs)
  70. let selectAll = function () {
  71. let target = document.getElementsByTagName("use"),
  72. last = target[target.length - 1];
  73.  
  74. function scrollEnd() {
  75. if (last.getAttribute('xlink:href').indexOf("CheckOpen") === -1) {
  76. selAll.textContent = 'Selected';
  77. // console.log('done');
  78. clearInterval(timer);
  79. selectVis();
  80. }
  81. else {
  82. selectVis();
  83. last.scrollIntoView();
  84. selAll.textContent = 'working...';
  85. console.log('scrolling');
  86. }
  87. }
  88. let timer = setInterval(() => {
  89. target = document.getElementsByTagName("use");
  90. last = target[target.length - 1];
  91. scrollEnd();
  92. }, 2000);
  93. };
  94.  
  95. selVis.addEventListener('click', selectVis);
  96. selAll.addEventListener('click', selectAll);
  97. }, 100);
  98. }
  99. if (Boolean(listen)) {
  100. console.log('listen');
  101. listen.addEventListener('click', buttons);
  102. }
  103. else {
  104. console.log('no listen');
  105. }
  106. }, 2000);
  107. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址