Advertisement
Guest User

Untitled

a guest
Jan 14th, 2020
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.87 KB | None | 0 0
  1. // ==UserScript==
  2. // @name E-Hentai & ExHentai Fade or hide viewed galleries and tag hider
  3. // @namespace https://greasyfork.org/users/25356
  4. // @description Fade or hide viewed galleries and hide flagged tags on e-hentai and exhentai. Now working with GM4
  5. // @version 6.0
  6.  
  7. // @include https://exhentai.org/*
  8. // @include https://e-hentai.org/*
  9.  
  10. // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
  11. // @require https://code.jquery.com/jquery-git.min.js
  12.  
  13.  
  14.  
  15. // @grant GM.getValue
  16. // @grant GM.setValue
  17. // @grant GM_getValue
  18. // @grant GM_setValue
  19. // @author CoLdAsIcE
  20. // ==/UserScript==
  21.  
  22. (async () => {
  23. 'use strict';
  24.  
  25. let $hideGal = await GM.getValue("EHXFade_hidevisited", false);
  26.  
  27. async function isGalVisited(gid) {
  28. let $md = await GM.getValue("g_" + gid, 0);
  29. if ($md == 1) {
  30. return true;
  31. }
  32. return false;
  33. }
  34.  
  35. async function visitGal(gid) {
  36.  
  37. if (!await isGalVisited(gid)) {
  38. GM.setValue("g_" + gid, 1);
  39. }
  40. }
  41.  
  42. function saveViewedGal() {
  43.  
  44. if (document.URL.match(/^https?:\/\/(e-|e[^-])hentai\.org\/g\/.*$/)) { //gallery case
  45. //record visited galleries to local DB
  46. const $gal_idx = document.URL.match(/^https?:\/\/(?:e-|e[^-])hentai\.org\/g\/(\d*)\/.*$/);
  47.  
  48. if (!isNaN($gal_idx[1])) {
  49.  
  50. const gal_id = parseInt($gal_idx[1])
  51.  
  52. visitGal(gal_id);
  53. }
  54.  
  55. }
  56. }
  57.  
  58. function fadeThumb($tag, tr=false) {
  59.  
  60. let $p
  61. const $alpha = parseFloat(0.2);
  62. if(tr) {
  63. $p = $tag.closest('tr');
  64. } else {
  65. $p = $tag.closest('.gl1t');
  66. }
  67.  
  68. if (isNaN($alpha))
  69. $alpha = '0.2';
  70.  
  71. $p.css('opacity', $alpha);
  72.  
  73. $p.hover(
  74. function () {
  75. $(this).stop().fadeTo('fast', 1);
  76. },
  77. function () {
  78. $(this).stop().fadeTo('fast', $alpha);
  79. }
  80. );
  81. }
  82.  
  83.  
  84. //fades thumbnails that is divs
  85. async function fadeViewedGalThumb() {
  86. $('.itg.gld > div.gl1t').each(async function () {
  87. if (document.URL.match(/^https?:\/\/(e-|e[^-])hentai\.org\/(?!s).*$/) && self == top) { //search / index case, exclude iframe
  88. const $tagContainer = $(this);
  89. const $gallery = $(this).closest('.gl1t');
  90. const $gal_href = $tagContainer.closest('.gl1t').find('div.gl3t a').first().attr('href');
  91. const $gal_idx = $gal_href.match(/^https?:\/\/(?:e-|e[^-])hentai\.org\/g\/(\d*)\/.*$/);
  92.  
  93. if (!isNaN($gal_idx[1])) {
  94. const gal_id = parseInt($gal_idx[1], 10);
  95.  
  96. if (await isGalVisited(gal_id)) {
  97. if (!$hideGal) {
  98. fadeThumb($tagContainer);
  99. $gallery.show();
  100.  
  101. //apply visited color to a tag
  102. $('<style type="text/css">' +
  103. '.gl1t > a:visited > div {font-weight:normal; color:#4b90eb !important; }' +
  104. '</style>')
  105. .appendTo("head");
  106.  
  107. } else {
  108. $gallery.hide();
  109. }
  110.  
  111. }
  112.  
  113. }
  114.  
  115. }
  116. });
  117. }
  118.  
  119. //fades anything with table
  120. async function fadeViewedGalTable(compact=null) {
  121. const className = compact ? 'gl1c' : 'gl1m'
  122. const title = compact ? '.gl3c' : '.gl3m'
  123.  
  124. $('table.itg > tbody > tr').each(async function () {
  125.  
  126. const isAGallery = this.firstElementChild.classList[0] === className
  127.  
  128. if (document.URL.match(/^https?:\/\/(e-|e[^-])hentai\.org\/(?!s).*$/) && self == top && isAGallery) { //search / index case, exclude iframe
  129.  
  130. const $tagContainer = $(this);
  131. const $gallery = $(this).closest('tr');
  132. const $gal_href = $tagContainer.closest('tr').find(title + ' a').first().attr('href');
  133. const $gal_idx = $gal_href.match(/^https?:\/\/(?:e-|e[^-])hentai\.org\/g\/(\d*)\/.*$/);
  134.  
  135.  
  136. if (!isNaN($gal_idx[1])) {
  137. const gal_id = parseInt($gal_idx[1], 10);
  138.  
  139. if (await isGalVisited(gal_id)) {
  140. if (!$hideGal) {
  141. fadeThumb($tagContainer, true);
  142. $gallery.show();
  143. if (compact) {
  144. //apply visited color to compact a tag
  145. $('<style type="text/css">' +
  146. title + ' > a:visited > div {font-weight:normal; color:#4b90eb !important; }' +
  147. '</style>')
  148. .appendTo("head");
  149. } else {
  150. //apply visited color to minimal and minimal+ a tag
  151. $('<style type="text/css">' +
  152. title + ' > a:visited > div {font-weight:normal; color:#4b90eb !important; }' +
  153. '</style>')
  154. .appendTo("head");
  155. }
  156. } else {
  157. $gallery.hide();
  158. }
  159. }
  160. }
  161.  
  162. }
  163. });
  164. }
  165.  
  166. //fades extended
  167. async function fadeViewedGalExt() {
  168.  
  169. $('table.itg > tbody > tr').each(async function () {
  170.  
  171. if (document.URL.match(/^https?:\/\/(e-|e[^-])hentai\.org\/(?!s).*$/) && self == top) { //search / index case, exclude iframe
  172.  
  173. const $tagContainer = $(this);
  174. const $gallery = $(this).closest('tr');
  175. const $gal_href = $tagContainer.closest('tr').find('.gl2e a').last().attr('href');
  176. const $gal_idx = $gal_href.match(/^https?:\/\/(?:e-|e[^-])hentai\.org\/g\/(\d*)\/.*$/);
  177.  
  178. if (!isNaN($gal_idx[1])) {
  179. const gal_id = parseInt($gal_idx[1], 10);
  180.  
  181. if (await isGalVisited(gal_id)) {
  182. if (!$hideGal) {
  183. fadeThumb($tagContainer, true);
  184. $gallery.show();
  185.  
  186. //apply visited color to minimal and minimal+ a tag
  187. $('<style type="text/css">' +
  188. '.gl2e div a:visited div > div {font-weight:normal; color:#4b90eb !important; }' +
  189. '</style>')
  190. .appendTo("head");
  191. } else {
  192. $gallery.hide();
  193. }
  194. }
  195. }
  196.  
  197. }
  198. });
  199. }
  200.  
  201. async function removeBadTags() {
  202. $('.itg.gld > div.gl1t').each(function () {
  203.  
  204. const $blankGif = $(this).find(".gl6t")
  205. const $image = $(this);
  206.  
  207. if ($blankGif.length > 0) {
  208. $image.hide();
  209. }
  210. });
  211. }
  212.  
  213. function css() {
  214. if(document.URL.match(/^https?:\/\/(e-)hentai\.org/)){
  215. $('<style type="text/css">' +
  216. 'div.hideGal {width:65px; height:auto; position:fixed; margin-left:-76px; background-color:#EDEBDF; color:#5C0D11; border: 1px solid #5C0D11; z-index: 10; cursor:pointer; }' +
  217. 'div.hideGal div.tab { margin:6px; text-align: center;}' +
  218. '</style>').appendTo("head");
  219. }else{
  220. $('<style type="text/css">' +
  221. 'div.hideGal {width:65px; height:auto; position:fixed; margin-left:-76px; background-color:#4F535B; color:skyblue; border: 1px solid #000000; z-index: 10; cursor:pointer; }' +
  222. 'div.hideGal div.tab { margin:6px; text-align: center;}' +
  223. '</style>').appendTo("head");
  224. }
  225.  
  226.  
  227. }
  228.  
  229. function hideVisitedGal() {
  230.  
  231. //add a hide gallery tab
  232. if (!$hideGal) {
  233. $('div.ido').prepend('<div class="hideGal"><div class="tab" id="toggleseen">Hide</div></div>');
  234. } else {
  235. $('div.ido').prepend('<div class="hideGal"><div class="tab" id="toggleseen">Show</div></div>');
  236. }
  237.  
  238. //hide or show gallery
  239. $('#toggleseen').parent().click(function (e) {
  240.  
  241. $hideGal = !$hideGal;
  242.  
  243. GM.setValue("EHXFade_hidevisited", $hideGal);
  244.  
  245. if ($hideGal) {
  246. $("#toggleseen").text("Show");
  247. } else {
  248. $("#toggleseen").text("Hide");
  249. }
  250.  
  251. applyChanges();
  252.  
  253. });
  254. }
  255.  
  256. function applyChanges() {
  257. fadeViewedGal();
  258. }
  259.  
  260. const $select = $('#dms div select')
  261.  
  262. css();
  263. hideVisitedGal();
  264.  
  265. saveViewedGal();
  266.  
  267. //fade based on what viewing style is used
  268. if($select.val() === 'm' || $select.val() === 'p') { //minimal
  269. fadeViewedGalTable();
  270. } else if ($select.val() === 'l') { //compact
  271. fadeViewedGalTable(true);
  272. } else if ($select.val() === 'e') { //extended
  273. fadeViewedGalExt();
  274. } else if ($select.val() === 't') { //thumbnail
  275. fadeViewedGalThumb();
  276. }
  277.  
  278. removeBadTags();
  279.  
  280. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement