4chan/f helper

4chan/f helper script

  1. // ==UserScript==
  2. // @name 4chan/f helper
  3. // @namespace https://greasyfork.org/zh-CN/scripts/412639-4chan-f-fitler
  4. // @version 0.3
  5. // @description 4chan/f helper script
  6. // @description ctrl+<- prev swf
  7. // @description ctrl+-> next swf
  8. // @author Neysummer2000
  9. // @match https://boards.4chan.org/f/
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @grant GM_openInTab
  13. // @grant GM_addStyle
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. // GM_addStyle(".viewing{background-color: blue !important;}");
  19.  
  20. var g_viewing; // dom
  21. var g_viewed = GM_getValue("4chan_viewed", "[]");
  22. g_viewed = JSON.parse(g_viewed);
  23.  
  24. window.addEventListener("keydown", function(ev){
  25. if(g_viewing === undefined) return;
  26. if(ev.ctrlKey){
  27. switch(ev.key){
  28. case "ArrowRight":
  29. var prev = g_viewing.nextElementSibling;
  30. if(prev !== null){
  31. document.getElementById('swf-embed').remove()
  32. prev.children[3].children[0].click();
  33. }
  34. break;
  35.  
  36. case "ArrowLeft":
  37. var next = g_viewing.previousElementSibling;
  38. if(next !== null){
  39. document.getElementById('swf-embed').remove()
  40. next.children[3].children[0].click();
  41. }
  42. break;
  43.  
  44. }
  45. }
  46. });
  47.  
  48. var g_doms = [];
  49. document.querySelectorAll('.flashListing td:nth-child(4) a').forEach(function(d) {
  50. var parent = d.parentElement.parentElement;
  51. if (g_viewed.indexOf(d.href) != -1){
  52. parent.remove();
  53. }else{
  54. g_doms.push(d);
  55. }
  56. });
  57.  
  58. g_doms.forEach(function(d, i){
  59. var parent = d.parentElement.parentElement;
  60. d.addEventListener("click", function(ev) {
  61. // for(let dom of document.querySelectorAll(".viewing")){
  62. // dom.classList.remove("viewing");
  63. // }
  64. // parent.classList.add("viewing");
  65.  
  66. g_viewed.push(d.href);
  67. g_viewing = parent;
  68. // console.log(g_viewing);
  69. GM_setValue("4chan_viewed", JSON.stringify(g_viewed));
  70.  
  71. var iframe = document.getElementById('swf-embed-header');
  72. var span = document.createElement("span");
  73. span.innerText = " -- " + parent.children[6].innerText;
  74. iframe.appendChild(span);
  75.  
  76. var span_1 = document.createElement("span");
  77. span_1.innerText = "[ " + (i + 1) + "/" + g_doms.length+ "] ";
  78. iframe.prepend(span_1);
  79.  
  80. var a = document.createElement("a");
  81. //a.target = "_blank";
  82. //a.href = d.href;
  83. a.href = "javascript: void(0)";
  84. a.addEventListener("click", function(){GM_openInTab(d.href, true)});
  85. a.innerText = "download";
  86. a.style.cssText = "float: right; margin-right: 10px;";
  87. iframe.appendChild(a);
  88. //console.log(d.href);
  89.  
  90. });
  91. });
  92.  
  93. })();