ArchiveFap

A userscript that adds an Expand All Images button to Barchive and Archived.moe

  1. // ==UserScript==
  2. // @name ArchiveFap
  3. // @namespace Horniness
  4. // @version 1.0.2
  5. // @description A userscript that adds an Expand All Images button to Barchive and Archived.moe
  6. // @author Glint
  7. // @match https://thebarchive.com/b/thread/*
  8. // @match https://archived.moe/*/thread/*
  9. // @require http://code.jquery.com/jquery-3.4.1.min.js
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. //Compatibility for existing instances of jQuery on site.
  17. var j = $.noConflict();
  18.  
  19. j(".post_image").on("click", function(e) {
  20. settingClickHandler(e, this);
  21. });
  22.  
  23. document.querySelector(".post_data").innerHTML += '<a style="color:#9999FF;" id="archivefap_expand_all" href="#">Expand all images!</a>';
  24.  
  25. j("#archivefap_expand_all").on("click", function(e) {
  26. j(".post_image").each(function(i, obj){
  27. settingClickHandler(e, obj);
  28. });
  29. });
  30.  
  31. function settingClickHandler(e, node) {
  32. //e.preventDefault();
  33. if (node === document.getElementsByClassName("post_image")[0]) {
  34. node.src = node.parentNode.href;
  35. node.attributes.removeNamedItem("height");
  36. node.attributes.removeNamedItem("width");
  37. } else {
  38. if (node.src.split("/")[5] === "thumb") {
  39. let fileRow = node.parentNode.parentNode.parentNode.querySelector(".post_file");
  40. let widthHeightArr = fileRow.children[2].innerText.split(", ")[1].trim().split("x");
  41. if (fileRow.children[1].href.slice(-4) === "webm") {
  42. let newVideoNode = document.createElement("video");
  43. newVideoNode.src = fileRow.children[1].href;
  44. newVideoNode.controls = true;
  45. newVideoNode.autoplay = true;
  46. newVideoNode.loop = true;
  47. newVideoNode.width = widthHeightArr[0];
  48. node.parentNode.insertBefore(newVideoNode, node);
  49. node.style.display = "none";
  50. let newSpan = document.createElement("span");
  51. newSpan.style.paddingLeft = "5px";
  52. newSpan.style.color = "#81a2be";
  53. newSpan.innerText = "[close webm]";
  54. fileRow.appendChild(newSpan);
  55. let sizeSpan = document.createElement("span");
  56. let increaseSize = document.createElement("span");
  57. increaseSize.classList.add("videoIncreaseSize");
  58. let decreaseSize = document.createElement("span");
  59. decreaseSize.classList.add("videoDecreaseSize");
  60. let increaseSizeMore = document.createElement("span");
  61. increaseSizeMore.classList.add("videoIncreaseSizeMore");
  62. increaseSizeMore.innerHTML = `(<span style="font-size: 17px; position: relative; top: 2px">++</span>)`;
  63. let decreaseSizeMore = document.createElement("span");
  64. decreaseSizeMore.classList.add("videoDecreaseSizeMore");
  65. decreaseSizeMore.innerHTML = `(<span style="font-size: 24px; position: relative; top: 3.5px">--</span>)`;
  66. decreaseSizeMore.style.paddingRight = "4px";
  67. sizeSpan.classList.add("sizeSpan");
  68. increaseSize.innerText = "(++)";
  69. increaseSize.style.padding = "0px 4px";
  70. decreaseSize.innerText = "(--)";
  71. decreaseSize.style.padding = "0px 4px";
  72. sizeSpan.style.paddingLeft = "5px";
  73. sizeSpan.style.color = "#81a2be";
  74. let resetSpan = document.createElement("span");
  75. resetSpan.innerText = "Reset";
  76. resetSpan.classList.add("resetMediaSize");
  77. resetSpan.style.paddingLeft = "4px";
  78. resetSpan.style.position = "relative";
  79. resetSpan.style.top = "1px";
  80. sizeSpan.innerHTML = `[Size - ${decreaseSize.outerHTML} ${decreaseSizeMore.outerHTML} | ${increaseSize.outerHTML} ${increaseSizeMore.outerHTML} | ${resetSpan.outerHTML} ]`;
  81. fileRow.appendChild(sizeSpan);
  82. newVideoNode.addEventListener("click", function(e) {
  83. if (e.target.paused) e.target.play();
  84. else e.target.pause();
  85. }, false);
  86. newSpan.addEventListener("click", function(e) {
  87. newVideoNode.remove();
  88. node.style.display = "";
  89. newSpan.remove();
  90. sizeSpan.remove();
  91. });
  92. fileRow.querySelector(".resetMediaSize").addEventListener("click", function(e) {
  93. newVideoNode.width = widthHeightArr[0];
  94. });
  95. fileRow.querySelector(".videoIncreaseSize").addEventListener("click", function(e) {
  96. let numWidth = Number(newVideoNode.width);
  97. newVideoNode.width = `${(numWidth + 10)}`;
  98. });
  99. fileRow.querySelector(".videoDecreaseSize").addEventListener("click", function(e) {
  100. let numWidth = Number(newVideoNode.width);
  101. newVideoNode.width = numWidth > 10 ? `${(numWidth - 10)}` : "0";
  102. });
  103. fileRow.querySelector(".videoIncreaseSizeMore").addEventListener("click", function(e) {
  104. let numWidth = Number(newVideoNode.width);
  105. newVideoNode.width = `${(numWidth + 100)}`;
  106. });
  107. fileRow.querySelector(".videoDecreaseSizeMore").addEventListener("click", function(e) {
  108. let numWidth = Number(newVideoNode.width);
  109. newVideoNode.width = numWidth > 100 ? `${(numWidth - 100)}` : "0";
  110. });
  111. return;
  112. }
  113. let fileExt = fileRow.children[1].href.split(".")[2];
  114. node.dataset.originalSrc = node.src;
  115. node.src = node.parentNode.href;
  116. node.style.width = widthHeightArr[0] + "px";
  117. node.style.height = widthHeightArr[1] + "px";
  118. let sizeSpan = document.createElement("span");
  119. sizeSpan.classList.add("mediaChangeSize");
  120. let increaseSize = document.createElement("span");
  121. increaseSize.classList.add("mediaIncreaseSize");
  122. increaseSize.style.padding = "0px 4px";
  123. let decreaseSize = document.createElement("span");
  124. decreaseSize.classList.add("mediaDecreaseSize");
  125. let increaseSizeMore = document.createElement("span");
  126. increaseSizeMore.classList.add("mediaIncreaseSizeMore");
  127. increaseSizeMore.innerHTML = `(<span style="font-size: 17px; position: relative; top: 2px">++</span>)`;
  128. let decreaseSizeMore = document.createElement("span");
  129. decreaseSizeMore.classList.add("mediaDecreaseSizeMore");
  130. decreaseSizeMore.innerHTML = `(<span style="font-size: 24px; position: relative; top: 3.5px">--</span>)`;
  131. decreaseSizeMore.style.padding = "0px 4px";
  132. decreaseSize.style.paddingLeft = "4px";
  133. increaseSize.innerText = "(++)";
  134. decreaseSize.innerText = "(--)";
  135. let resetSpan = document.createElement("span");
  136. resetSpan.innerText = "Reset";
  137. resetSpan.classList.add("resetMediaSize");
  138. resetSpan.style.paddingLeft = "4px";
  139. resetSpan.style.position = "relative";
  140. resetSpan.style.top = "1px";
  141. sizeSpan.innerHTML = `[Size - ${decreaseSize.outerHTML} ${decreaseSizeMore.outerHTML} | ${increaseSize.outerHTML} ${increaseSizeMore.outerHTML} | ${resetSpan.outerHTML} ]`;
  142. sizeSpan.style.paddingLeft = "5px";
  143. sizeSpan.style.color = "#81a2be";
  144. fileRow.appendChild(sizeSpan);
  145. fileRow.querySelector(".resetMediaSize").addEventListener("click", function(e) {
  146. node.style.width = widthHeightArr[0] + "px";
  147. node.style.height = widthHeightArr[1] + "px";
  148. });
  149. fileRow.querySelector(".mediaIncreaseSize").addEventListener("click", function(e) {
  150. let numWidth = Number(node.style.width.match(/(\d+)px/)[1]);
  151. let numHeight = Number(node.style.height.match(/(\d+)px/)[1]);
  152. node.style.width = `${numWidth + 10}px`;
  153. node.style.height = `${numHeight + 10}px`;
  154. });
  155. fileRow.querySelector(".mediaDecreaseSize").addEventListener("click", function(e) {
  156. let numWidth = Number(node.style.width.match(/(\d+)px/)[1]);
  157. node.style.width = numWidth > 10 ? `${numWidth - 10}px` : "0px";
  158. let numHeight = Number(node.style.height.match(/(\d+)px/)[1]);
  159. node.style.height = numHeight > 10 ? `${numHeight - 10}px` : "0px";
  160. });
  161. fileRow.querySelector(".mediaIncreaseSizeMore").addEventListener("click", function(e) {
  162. let numWidth = Number(node.style.width.match(/(\d+)px/)[1]);
  163. let numHeight = Number(node.style.height.match(/(\d+)px/)[1]);
  164. node.style.width = `${numWidth + 100}px`;
  165. node.style.height = `${numHeight + 100}px`;
  166. });
  167. fileRow.querySelector(".mediaDecreaseSizeMore").addEventListener("click", function(e) {
  168. let numWidth = Number(node.style.width.match(/(\d+)px/)[1]);
  169. node.style.width = numWidth > 100 ? `${numWidth - 100}px` : "0px";
  170. let numHeight = Number(node.style.height.match(/(\d+)px/)[1]);
  171. node.style.height = numHeight > 100 ? `${numHeight - 100}px` : "0px";
  172. });
  173. } else {
  174. node.src = node.dataset.originalSrc;
  175. node.style.width = "";
  176. node.style.height = "";
  177. node.parentNode.parentNode.parentNode.querySelector(".mediaChangeSize").remove();
  178. }
  179. }
  180. }
  181.  
  182. document.onkeydown = checkKey;
  183.  
  184. //Handles behaviour when keys are pressed
  185. function checkKey(e){
  186. e = e || window.event;
  187.  
  188. // -- FILE SET NAVIGATION --
  189. //If you press left or A, go to the previous file
  190. //nice
  191. if(e.keyCode == '69'){
  192. j(".post_image").each(function(i, obj){
  193. settingClickHandler(e, obj);
  194. }
  195. );
  196. }
  197. }
  198. })();