EH Plus

Gallery index/search: Improves appearance/layout, parses and cleans up titles. Can hide/fade galleries by tag (requires flagging perk). Can resort gallery thumbs which is useful when hiding. Gallery view: Can adjust thumb sizes to make neat rows (requires large thumb perk). General: Option for grey color scheme by rewriting css (might have a few issues). Settings panel pops out on the left on mouseover on pages where it works.

  1. // ==UserScript==
  2. // @name EH Plus
  3. // @namespace https://greasyfork.org/users/4293
  4. // @description Gallery index/search: Improves appearance/layout, parses and cleans up titles. Can hide/fade galleries by tag (requires flagging perk). Can resort gallery thumbs which is useful when hiding. Gallery view: Can adjust thumb sizes to make neat rows (requires large thumb perk). General: Option for grey color scheme by rewriting css (might have a few issues). Settings panel pops out on the left on mouseover on pages where it works.
  5. // @version 2015.2.1
  6.  
  7. // @include http://g.e-hentai.org/*
  8. // @include /^http://(g\.e-|e.)hentai\.org/.*$/
  9. // @include /^http://95\.211\.199\.\d{1,3}/archive/.*$/
  10. // @include /^http://95\.211\.209\.\d{1,3}/archive/.*$/
  11. // @include /^http://37\.48\.81\.\d{1,3}/archive/.*$/
  12.  
  13. // @grant GM_getValue
  14. // @grant GM_setValue
  15. // @grant GM_deleteValue
  16.  
  17. // @run-at document-start
  18.  
  19. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  20. // @author fyxie
  21. // ==/UserScript==
  22.  
  23. //suspend reflow
  24. $('<style type="text/css">html{background:#34353B;} body{display:none;}</style>').appendTo("head");
  25.  
  26.  
  27. function showPage() {
  28. $('<style type="text/css">body{display:block;}</style>').appendTo("head");
  29. }
  30. //chrome fix for eval, only needed temporarily for initial fix of saved bad values
  31. function safeEval(x) {
  32. if (x.substring(0,6) == '\\$1 = ') {
  33. return eval("("+x.slice(6).slice(0, -1) +");");
  34. }
  35. else {
  36. return eval(x);
  37. }
  38. }
  39.  
  40. //chrome fix for uneval
  41. function safeUneval(x) {
  42. var ux = uneval(x);
  43. if (ux.substring(0,6) == '\\$1 = ') {
  44. return "("+ ux.slice(6).slice(0, -1) +");";
  45. }
  46. else {
  47. return ux;
  48. }
  49. }
  50.  
  51. //var $galcache = {};
  52. function isGalVisited(gid) {
  53.  
  54. //if (typeof $galcache[gid] === 'undefined') { //load to mem if needed
  55. var md = GM_getValue("g_"+gid,0);
  56. //}
  57. if (md == 1) {
  58. return true;
  59. }
  60. return false;
  61. }
  62.  
  63. function visitGal(gid) {
  64. GM_setValue("g_"+gid,1);
  65. }
  66.  
  67. function unVisitGal(gid) {
  68. GM_setValue("g_"+gid,0);
  69. }
  70.  
  71.  
  72. //$galdb = safeEval(GM_getValue("eh_galdb", "({});")); //load visited gal dv
  73. function migrateOldVisitedDB() {
  74. var galdb = safeEval(GM_getValue("eh_galdb", "({});")); //load visited gal dv
  75. var i=0;
  76. var j=0;
  77. $.each(galdb, function(gid,visited) {
  78. if(visited) {
  79. visitGal(gid);
  80. //console.log(gid + ": visited");
  81. i++;
  82. }
  83. else j++;
  84. });
  85. console.log("visited galleries migrated: "+i);
  86. console.log("not visited total: "+j);
  87. return i;
  88. }
  89. function deleteOldVisitedDB() {
  90. GM_deleteValue("eh_galdb");
  91. console.log("old visited data deleted ");
  92. }
  93. //GM_setValue("eh_tagdb", safeUneval({})); //reset tagdb
  94. //GM_setValue("eh_galdb", safeUneval({})); //reset galdb
  95.  
  96. function ehp() {
  97.  
  98. //grey css override
  99. function grey_css() {
  100. if (!document.URL.match(/^http:\/\/g\.e-hentai\.org\/.*$/)) return;
  101.  
  102. var ss = document.styleSheets;
  103.  
  104. //replace colors in linked css
  105. for (var i=0; i<ss.length; i++) {
  106. var rules = ss[i].cssRules || ss[i].rules;
  107. for (var j=0; j<rules.length; j++) {
  108. if (rules[j].style.backgroundColor) {
  109. rules[j].style.backgroundColor=rules[j].style.backgroundColor.replace('rgb(224, 222, 211)','rgb(52, 53, 59)');
  110. rules[j].style.backgroundColor=rules[j].style.backgroundColor.replace('rgb(242, 240, 228)','rgb(52, 53, 59)');
  111. rules[j].style.backgroundColor=rules[j].style.backgroundColor.replace('rgb(227, 224, 209)','rgb(52, 53, 59)');
  112. rules[j].style.backgroundColor=rules[j].style.backgroundColor.replace('rgb(237, 234, 218)','rgb(52, 53, 59)');
  113. rules[j].style.backgroundColor=rules[j].style.backgroundColor.replace('rgb(237, 235, 223)','rgb(79, 83, 91)');
  114. rules[j].style.backgroundColor=rules[j].style.backgroundColor.replace('rgb(242, 239, 223)','rgb(79, 83, 91)');
  115. rules[j].style.backgroundColor=rules[j].style.backgroundColor.replace('rgb(255, 255, 204)','rgb(79, 83, 91)');
  116. }
  117.  
  118. if (rules[j].style.color) {
  119. rules[j].style.color=rules[j].style.color.replace('rgb(92, 13, 17)','rgb(221, 221, 221)');
  120. rules[j].style.color=rules[j].style.color.replace('rgb(155, 78, 3)','rgb(255, 251, 219)');
  121. }
  122.  
  123.  
  124. if (rules[j].style.borderColor) {
  125. rules[j].style.borderColor=rules[j].style.borderColor.replace('rgb(92, 13, 17)','rgb(0, 0, 0)');
  126. rules[j].style.borderColor=rules[j].style.borderColor.replace('rgb(92, 13, 18)','rgb(0, 0, 0)');
  127. rules[j].style.borderColor=rules[j].style.borderColor.replace('rgb(227, 224, 209)','rgb(52, 53, 59)');
  128. }
  129.  
  130. if (rules[j].style.borderBottomColor) {
  131. rules[j].style.borderBottomColor=rules[j].style.borderBottomColor.replace('rgb(92, 13, 18)','rgb(0, 0, 0)');
  132. }
  133.  
  134. if (rules[j].style.borderLeftColor) {
  135. rules[j].style.borderLeftColor=rules[j].style.borderLeftColor.replace('rgb(92, 13, 18)','rgb(0, 0, 0)');
  136. }
  137.  
  138. if (rules[j].style.borderRightColor) {
  139. rules[j].style.borderRightColor=rules[j].style.borderRightColor.replace('rgb(92, 13, 18)','rgb(0, 0, 0)');
  140. rules[j].style.borderRightColor=rules[j].style.borderRightColor.replace('rgb(217, 215, 204)','rgb(0, 0, 0)');
  141. }
  142. }
  143. }
  144.  
  145. function replaceColorInline($search,$replace) {
  146. $('*[style*="'+$search+'"]').each( function() {
  147. $tag = $(this);
  148. $style = $tag.attr('style');
  149. $style = $style.replace($search,$replace);
  150. $tag.attr('style',$style);
  151. });
  152. }
  153.  
  154.  
  155. replaceColorInline('#5C0D12','#000000');
  156. replaceColorInline('#C2C1C1','#000000');
  157. replaceColorInline('#F2EFDF','#4F535B');
  158. replaceColorInline('#F2F0E4','#34353B');
  159.  
  160. $('<style type="text/css">'+
  161. ' table.itg tr:nth-child(2n) { background: none repeat scroll 0 0 #4F535B !important; }' +
  162. ' table.itg tr:nth-child(2n+1) { background: none repeat scroll 0 0 #42464d !important; }' +
  163. '</style>').appendTo("head");
  164.  
  165. }
  166.  
  167.  
  168. function i() {
  169. $('<style type="text/css">'+
  170. 'div.fxs {width:195px; height:auto; left:-185px; top:100px; position:fixed; background-color:#4F535B; text-align:left; padding-left:10px; color:#DDDDDD;border: 2px solid #34353B;z-index: 10;}'+
  171. 'div.fxs:hover {left:0px;}'+
  172. 'input#cust[type=checkbox]:checked ~ div#custdiv { display:block !important;}'+
  173. '#highlight:focus, #highlight:hover { width:400px !important;}'+
  174. 'div.fxt {width:65px; height:auto; position:fixed; margin-left:-76px; background-color:#4F535B; color:skyblue;border: 1px solid #000000; z-index: 10; cursor:pointer; }'+
  175. 'div.fxt div.minitab { margin:6px; }'+
  176. 'div.thidden { opacity:0.5; color:#d5d5d5;}'+
  177. '</style>').appendTo("head");
  178.  
  179.  
  180. var $cfg_grey;
  181. var $cfg_shortentags;
  182. var $cfg_searchexpunged;
  183.  
  184. var $cfg_fadevisited;
  185. var $cfg_hidevisited;
  186.  
  187. var $cfg_fade;
  188. var $cfg_hide;
  189.  
  190. var $cfg_unchop;
  191. var $cfg_group;
  192. var $cfg_group_radius;
  193.  
  194. var $cfg_columns;
  195. var $cfg_sortdef;
  196. var $cfg_sortsize;
  197. var $cfg_sortzig;
  198. var $cfg_sorttag;
  199. var $cfg_minimal;
  200.  
  201.  
  202.  
  203. var $cfg_hidelist;
  204. var $cfg_showlist;
  205. var $cfg_fadealpha;
  206.  
  207. function getSettings() {
  208.  
  209. $cfg_stars = GM_getValue("ehp_stars", false);
  210. $cfg_torrents = GM_getValue("ehp_torrents", false);
  211.  
  212. $cfg_cust = GM_getValue("ehp_cust", false);
  213. $cfg_grey = GM_getValue("ehp_grey", true);
  214. $cfg_shortentags = GM_getValue("ehp_shortentags", true);
  215. $cfg_searchexpunged = GM_getValue("ehp_searchexpunged", false);
  216.  
  217. $cfg_minimal = GM_getValue("ehp_minimal", true);
  218. $cfg_columns = parseInt(GM_getValue("ehp_columns", "6").replace(/[^0-9-]/,""),10);
  219. $cfg_columns = $cfg_columns ? $cfg_columns : 6;
  220.  
  221. $cfg_fadevisited = GM_getValue("ehp_fadevisited", false);
  222. $cfg_hidevisited = GM_getValue("ehp_hidevisited", false);
  223.  
  224. $cfg_fade = GM_getValue("ehp_fade", true);
  225. $cfg_fadealpha = GM_getValue("ehp_fadealpha", 0.2);
  226. $cfg_hide = GM_getValue("ehp_hide", false);
  227.  
  228. $cfg_unchop = true;
  229. $cfg_group = GM_getValue("ehp_group", true);
  230. $cfg_group_radius = parseInt(GM_getValue("ehp_group_radius", "30").replace(/[^0-9-]/,""),10);
  231.  
  232.  
  233. $cfg_sortdef = GM_getValue("ehp_sortdef", false);
  234. $cfg_sortsize = GM_getValue("ehp_sortsize", true);
  235. $cfg_sortzig = GM_getValue("ehp_sortzig", false);
  236. $cfg_sorttag = GM_getValue("ehp_sorttag", false);
  237.  
  238. $cfg_titleformat = GM_getValue("ehp_titleformat", 'title<br><span style="font-size:10px;color:#dddddd !important;">parody lang</span>');
  239.  
  240.  
  241.  
  242. $cfg_hidelist = GM_getValue("ehp_hidelist", '');
  243. $cfg_showlist = GM_getValue("ehp_showlist", '');
  244. $cfg_highlight = GM_getValue("ehp_highlight", '');
  245. }
  246. getSettings();
  247.  
  248.  
  249.  
  250. $('div.ido').prepend('<div class="fxt"><div class="minitab" id="toggleseen">Seen - <span id="seencount">0</span></div>'+
  251. '</div>');
  252.  
  253. $('div.ido').before('<div class="fxs"><br>'+
  254. '<input id="cust" type="checkbox" '+($cfg_cust?'checked':'') +'>Custom Title [Advanced]<br>'+
  255. '<div id="custdiv" style="display:none;">Valid Tags: category, con, circle,<br>artist, title, parody, lang, misc, rawtitle</b><br>'+
  256. '<a style="padding-left:140px;" id="customreset" href="#">reset</a>'+
  257. '<textarea class="stdinput" style="width:160px;" id="titleformat" rows="8"></textarea><br><br></div>'+
  258.  
  259. '<label><input id="shortentags" type="checkbox" '+($cfg_shortentags?'checked':'') +'>Shorten Tags</label><br>'+
  260. '<label><input id="searchexpunged" type="checkbox" '+($cfg_searchexpunged?'checked':'') +'>Search Expunged</label><br>'+
  261. '<label><input id="minimal" type="checkbox" '+($cfg_minimal?'checked':'') +'>Minimal UI</label><br>'+
  262. '<label><input id="grey" type="checkbox" '+($cfg_grey?'checked':'') +'>Grey e-hentai</label><br>'+
  263. '<label><input id="stars" type="checkbox" '+($cfg_stars?'checked':'') +'>Show Stars, Etc</label><br>'+
  264.  
  265.  
  266. '<label style="line-height:24px;"><input class="stdinput" id="columns" style="width:15px;margin:0;padding:1px;border:0;text-align:center;" type="textbox" value="'+$cfg_columns+'"> Tiles wide</label><br>'+
  267.  
  268.  
  269. '<br><b style="margin-left:6px;font-size:110%;">Gallery sorting</b><br>'+
  270. '<label><input id="sortdef" type="radio" name="order" '+($cfg_sortdef?'checked':'')+'>Default (fast, no grouping)</label><br>'+
  271.  
  272. '<label><input id="group" type="checkbox" '+($cfg_group?'checked':'') +'>Group by title - Range</label>'+
  273. '<label><input class="stdinput" id="group_radius" style="width:20px;margin:0;padding:1px;border:0;text-align:center;" type="textbox" value="'+$cfg_group_radius+'"> px</label><br>'+
  274. '<label><input id="sortsize" type="radio" name="order" '+($cfg_sortsize?'checked':'')+'>Compact (tall to short)</label><br>'+
  275. '<label><input id="sortzig" type="radio" name="order" '+($cfg_sortzig?'checked':'')+'>Compact (tall/short zigzag)</label><br>'+
  276. '<label><input id="sorttag" type="radio" name="order" '+($cfg_sorttag?'checked':'')+'>Good tags first</label><br><br>'+
  277.  
  278. '<label><input id="fade" type="checkbox" '+($cfg_fade?'checked':'') +'>Fade all bad tags to </label>'+
  279. '<input class="stdinput" id="fadealpha" style="width:30px;margin:0;padding:1px;border:0;" type="textbox" value="'+$cfg_fadealpha+'"><br>'+
  280. '<label><input id="hide" type="checkbox" '+($cfg_hide?'checked':'') +'>Hide all bad tags</label><br>'+
  281.  
  282. '<label><input id="fadevisited" type="checkbox" '+($cfg_fadevisited?'checked':'') +'>Fade visited galleries</label><br>'+
  283. '<label><input id="hidevisited" type="checkbox" '+($cfg_hidevisited?'checked':'') +'>Hide visited galleries</label><br>'+
  284.  
  285. '<br><b>Hide with these tags</b><br>(hidetag1, hidetag2, etc)<br>'+
  286. '<input class="stdinput" style="width:160px;" id="hidelist" type="textbox" value="'+$cfg_hidelist+'"><br>'+
  287.  
  288. '<br><b>Never hide with these tags</b><br>(* in hide box for show only)<br>'+
  289. '<input class="stdinput" style="width:160px;" id="showlist" type="textbox" value="'+$cfg_showlist+'"><br>'+
  290.  
  291. '<br><br><b>Highlight</b> (advanced)<a href="javascript:void(0)" style="margin-left:40px;" onclick="(function(){ var e = document.getElementById(\'hihelp\');if(e.style.display == \'block\') e.style.display = \'none\'; else e.style.display = \'block\'; })()">help</a>'+
  292. '<div id="hihelp" style="display:none;">'+
  293. 'Highlight gallery frames.<br><br>'+
  294. '<div style="padding-right:22px;">All selectors except tag search text within the title. Specific tags like artist need properly formatted gallery titles to work. When multiple matches, last is used. Tags search highlight is applied after title.</div><br><br>' +
  295. '<div style="font-family:consolas">Usage:<br>selector:search text:color:[mode]<br>selector:#match regexp:color</div><br>Valid Selectors:<br><div style="font-family:consolas">* tag title parody <br>circle artist category</div>(* matches anywhere in the title)<br><br>Valid Modees:<br><div style="font-family:consolas">border top<br>fcolor fgrad (tag selector only)</div>(border is used when omitted)<br><br>'+
  296. 'Examples:<br><div style="font-family:consolas">title:pixiv:yellow<br>title:touhou:blue<br>tag:ahegao:#ff0000<br>tag:schoolgirl:red:top<br>circle:archives:pink<br>category:manga:orange:border<br>category:non-h:lightblue:top<br><br>parody:#(k\\-on!|haruhi):green</div></b><br>'+
  297. '</div>'+
  298. '<br>Enter highlights one per line. ' +
  299. '<textarea class="stdinput" style="width:160px;" id="highlight" rows="8"></textarea><br><br>'+
  300. '<span id="migratebtn" style="text-decoration:underline;cursor:pointer;">Migrate Old Visited DB</span>'+
  301. '<br><br><input id="applybtn" type="button" value="Apply" /><br><div id="cBox" style="display:hidden"></div>&nbsp;');
  302. $('textarea#titleformat').val($cfg_titleformat);
  303. $('textarea#highlight').val($cfg_highlight);
  304.  
  305.  
  306. $('div#searchbox > form').append('<div id="fxs2">'+
  307. '<input id="fsrcb" class="starsetenable" type="checkbox" name="f_sr">'+
  308. '<input id="star5" class="starset" type="radio" name="f_srdd" value="5"><label for="star5" class="irx"></label>'+
  309. '<input id="star4" class="starset" type="radio" name="f_srdd" value="4"><label for="star4" class="irx"></label>'+
  310. '<input id="star3" class="starset" type="radio" name="f_srdd" value="3"><label for="star3" class="irx"></label>'+
  311. '<input id="star2" class="starset" type="radio" name="f_srdd" value="2"><label for="star2" class="irx"></label>'+
  312. '<input id="star1" type="radio" name="f_srdd"><label for="star1" class="irx" id="irxn"></label>'+
  313. '<br></div>');
  314.  
  315.  
  316.  
  317. $.urlParam = function(name){
  318. var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
  319. if (results==null){ return null; }
  320. else{ return results[1] || 0; }
  321. }
  322. $(function() {
  323. if ($.urlParam('f_sr')=='on')
  324. xtt();
  325. var i = $.urlParam('f_srdd')
  326. $('div#fxs2 input[value="'+i+'"]').prop('checked', true);
  327.  
  328. curStarView='star'+i;
  329. if (i == '' || i == 'on' || i == null)
  330. curStarView='star'+1;
  331. });
  332.  
  333.  
  334.  
  335.  
  336.  
  337. $('<style type="text/css">'+
  338. 'div#fxs2 {width:195px; position:absolute; right:-8px; top:-27px; visibility:hidden;}'+
  339. 'label.irx{background-image: url("http://st.exhentai.net/img/rt.png"); background-repeat: no-repeat; height: 16px; width:16px; float:right;}'+
  340. 'label.irx{background-position:-80px -1px; opacity:0.1; }'+
  341.  
  342. 'input.starset:checked ~ label.irx {background-position:0 -1px; opacity:0.7; }'+
  343. 'div#fxs2 label.irx:hover,label.irx:hover ~ label.irx {background-position:0 -1px; opacity:1; }'+
  344.  
  345.  
  346. '#fxs2 input { position: absolute; visibility:hidden;}'+
  347. '</style>').appendTo("head");
  348.  
  349.  
  350. $('#customreset').click(function (e) {
  351. e.preventDefault();
  352. $('#titleformat').val('title<br><span class="subtitle">parody lang</span><div class="category catbox stroke2">category</div>');
  353. GM_setValue("ehp_titleformat", $('#titleformat').val());
  354. });
  355.  
  356.  
  357.  
  358.  
  359. $('div.fxs input[type="checkbox"]').click(function (e) {
  360. GM_setValue("ehp_"+$(this).attr("id"), $(this).prop("checked")?true:false);
  361. });
  362.  
  363.  
  364. $('div.fxs input[type="radio"][name="order"]').click(function (e) {
  365. GM_setValue("ehp_sortdef", false);
  366. GM_setValue("ehp_sortsize", false);
  367. GM_setValue("ehp_sortzig", false);
  368. GM_setValue("ehp_sorttag", false);
  369.  
  370. GM_setValue("ehp_"+$(this).attr("id"), $(this).prop("checked")?true:false);
  371. });
  372.  
  373.  
  374.  
  375. $('div.fxs input[type="textbox"], div.fxs textarea').keyup(function (e) {
  376. GM_setValue("ehp_"+$(this).attr("id"), $(this).val());
  377. });
  378.  
  379.  
  380. $('div.fxs input#applybtn').click(function (e) {
  381. //try { $("head").html($head_html); }
  382. //catch(err) { }
  383.  
  384. //try { $('div.ido').html($body_html); }
  385. //catch(err) { }
  386. loadGalState();
  387.  
  388. getSettings();
  389. applychanges();
  390. });
  391.  
  392.  
  393. $('div.fxs span#migratebtn').click(function (e) {
  394. try {
  395. if (confirm("Mirgate old database? (this may take a while, will confirm on complete)")) {
  396. console.log("Migrating old db...");
  397. var i = migrateOldVisitedDB();
  398. if (confirm("Migration completed. "+i+" galleries marked as visited.\r\nDelete old visisted DB? (No longer needed in newest version, but shouldn't hurt to keep it.)")) {
  399. console.log("Deleting old db...");
  400. deleteOldVisitedDB();
  401. }
  402. }
  403. }
  404. catch(e) {alert("error in migration: "+e);}
  405. });
  406.  
  407.  
  408. //////////////////////////////////////////
  409. //
  410. //
  411.  
  412.  
  413. //minimal gallery ui
  414. function minimal_css() {
  415. //copy paste
  416. $inner = $cfg_columns * ($gtile_width + $gtile_pad ) + 25;
  417. $outer = $inner + 50;
  418.  
  419.  
  420.  
  421. if (document.URL.match(/(stats.php|home.php|uconfig.php|archiver.php|hentaiathome.php|adoptaserver.php|bitcoin.php|hathperks.php|exchange.php)(\?.*)?$/)) return;
  422. $('<style type="text/css">'+
  423. ' div#toppane { position:relative; } ' +
  424. ' h1.ih { position:absolute; top:-74px; right:-6px; } ' +
  425. ' table.itc { display:none; } ' +
  426. ' div.idi { border: medium none; } ' +
  427. ' p.nopm { position:absolute; top: -20px; right:0; } ' +
  428. ' div#iw { padding-top: 23px; } ' +
  429. ' p.nopm > input + input { display:none; } ' +
  430. ' p.nopm input.stdinput { background: none repeat scroll 0 0 #34353B; border: 1px dashed #616161; }' +
  431. ' p.nopm input.stdinput:focus { background: none repeat scroll 0 0 #4F535B; border: 1px dashed #B1B1B1; }' +
  432. ' p#nb a { text-decoration: none; padding: 0 5px; color:#B1B1B1; }' +
  433. ' p#nb a:hover { text-decoration: underline; }' +
  434. ' p#nb img + a + img + a { visibility:hidden; }' +
  435. ' p#nb:hover img + a + img + a { visibility:visible; }' +
  436.  
  437. ' p#nb img { display:none; }' +
  438. ' div.ido { margin-top:45px; margin-bottom:68px; } ' +
  439. ' table.ptt { position:relative; top:-62px } ' +
  440. ' div#toppane + div { margin-bottom:-28px; }' +
  441. ' table.ptb { position:relative; bottom:-8px; } ' +
  442. ' table.ptb { position:relative; bottom:-8px; } ' +
  443. ' div#searchbox a { text-decoration: none; }' +
  444. ' div.ido div p.ip { position:relative; top: -66px; width:400px;} ' +
  445. ' div#dmo { display:none } ' +
  446. ' p.nopm + p.nopm { display: none } ' +
  447. ' div#searchbox p.nopm { position:absolute; right:-10px; top:-55px; } ' +
  448. ' p#nb { position:relative; left:'+(-468 - ($outer / 2 - 688))+'px; top:44px;} ' +
  449. ' div.itg { margin-top:-50px; } ' +
  450. ' div.ido p.ip { position:absolute; bottom:-45px; width: 100%; } ' +
  451. ' div#fxs2 { visibility:visible;}'+
  452. '</style>').appendTo("head");
  453.  
  454. //for real low res
  455. if ($cfg_columns < 4)
  456. $('<style type="text/css">'+
  457. ' p.nopm input.stdinput { position:relative; top:-18px; } ' +
  458. ' h1.ih { visibility: hidden; } ' +
  459. ' p#nb { top: 3px;} ' +
  460. '</style>').appendTo("head");
  461.  
  462. }
  463.  
  464.  
  465. $(
  466. '<style type="text/css">'+
  467. 'div.fxs:not(:hover) div#hihelp { visibility: collapse; } '+
  468. 'div#hihelp {background: #4F535B; display: block; padding: 4px; position: absolute; right: -214px; top: 211px; width: 206px;} ' +
  469. 'div.itd4 {margin: 2px auto !important;}'+
  470. 'img.n { padding-top:1px; padding-left: 1px; padding-right: 1px; }'+
  471. 'img.rt { padding-right: 5px; width:56px;} '+
  472. '.Non-H {color:lightblue;} '+
  473. '.Image.Sets {color:#9966FF;} '+
  474. '.Cosplay {color:#FF99FF;} '+
  475. '.Asian.Porn {color:pink;} '+
  476. '.Misc {color:white;} '+
  477. '.Western {color:lightgreen;} '+
  478. '.Game.CG {color:#99FFCC; } '+
  479. '.Artist.CG {color:yellow; } '+
  480. '.Manga {color:orange; } '+
  481. '.Doujinshi{ color:salmon; } '+
  482. '</style>').appendTo("head");
  483.  
  484.  
  485. function zeroPad(n) {
  486. return (n < 10)? '00' + n : (n < 100)? '0' + n : '' + n;
  487. }
  488.  
  489. //$tagdb = safeEval(GM_getValue("eh_tagdb", "({});"));
  490.  
  491. $gtile_width = 216;
  492. $gtile_pad = 4;
  493.  
  494.  
  495. $baseColors = new Object();
  496. $baseColors['fr1'] = "#f93c3c"
  497. $baseColors['fr2'] = "#d9a834"
  498. $baseColors['fr3'] = "#d7d934"
  499. $baseColors['fb1'] = "#34d934"
  500. $baseColors['fb2'] = "#34cbd9"
  501. $baseColors['fb3'] = "#c434d9"
  502. $baseColors['fbx'] = "#bdbdbd"
  503.  
  504.  
  505. $(
  506. '<style type="text/css">'+
  507.  
  508. '.fr1 {color:#f93c3c;}'+ //red d93434
  509. '.fr2 {color:#d9a834;}'+ //orange
  510. '.fr3 {color:#d7d934;}'+ //yellow
  511. '.fb1 {color:#34d934;}'+ //green
  512. '.fb2 {color:#34cbd9;}'+ //blue
  513. '.fb3 {color:#c434d9;}'+ //purple
  514. '.fbx {color:#bdbdbd;}'+ //grey
  515. '.itd1 ~ .c {display:none;}'+
  516. '.itd1, .ido > h1.ih ~ div {'+
  517. ' display: inline-block;'+
  518. ' float: none !important;'+
  519. ' margin: 0 !important;'+
  520. ' vertical-align: top;}'+
  521.  
  522.  
  523. 'div.itg img, div.id3 { border-radius: 4px 4px 4px 4px; }'+
  524. 'div.id3 {position:relative;}'+
  525. 'div.id1 {position:relative; padding: 57px 0 7px; margin:0 '+ $gtile_pad +'px 13px 0; width:'+$gtile_width+'px}'+
  526. 'div.id2 {position:absolute; top:0; z-index:5; background-image: -moz-linear-gradient( rgba(52,53,59, 0.5) 5%, rgba(52,53,59, 0) 100%); width:'+$gtile_width+'px;'+
  527. 'border-radius: 9px 9px 0px 0px;'+
  528. '} '+
  529.  
  530. 'div.id2 a, .stroke { text-shadow: -1px -1px 0 rgba(0,0,0, 0.35), 1px -1px 0 rgba(0,0,0, 0.35), -1px 1px 0 rgba(0,0,0, 0.35), 1px 1px 0 rgba(0,0,0, 0.35), 0 -1px 0 rgba(0,0,0, 0.5), 0 1px 0 rgba(0,0,0, 0.5), -1px 0 0 rgba(0,0,0, 0.5), 1px 0 0 rgba(0,0,0, 0.5); }'+
  531. '.stroke2 { text-shadow: -1px -1px 0 rgba(0,0,0, 0.46), 1px -1px 0 rgba(0,0,0, 0.46), -1px 1px 0 rgba(0,0,0, 0.46), 1px 1px 0 rgba(0,0,0, 0.46), 0 -1px 0 rgba(0,0,0, 0.65), 0 1px 0 rgba(0,0,0, 0.65), -1px 0 0 rgba(0,0,0, 0.65), 1px 0 0 rgba(0,0,0, 0.65); } '+
  532. '.floatflag, .id2 { font-family: \'メイリオ\',Meiryo,Arial,\'DejaVu Sans\',sans-serif; font-size:11.4px; line-height:12.5px; }'+
  533. '.floatflag, .catbox {font-family: \'メイリオ\',Meiryo,Arial,\'DejaVu Sans\',sans-serif; font-size:11.4px; line-height:12.5px;font-weight:bold;} ' +
  534.  
  535.  
  536. 'div.id2 {display: table; height:80px; text-align:left;}'+
  537. 'div.id2 a {font-weight:bold; color:skyblue; font-size:11.4px; line-height:12.5px;}'+
  538. 'span.subtitle {font-weight:normal; color:#d5d5d5; font-size:10.1px;}'+
  539. 'div.id2 a:visited, div.id2 a:visited span, .vx a:visited, .vx a:visited span {font-weight:normal; color:#a9a9a9 !important; }'+
  540. 'div.id4 { position:absolute; bottom:2px; right:1px; text-align:right;}'+
  541.  
  542. 'div.id2 a div.unseen { color:#FFFFFF !important; float:left; width:0; text-shadow:none !important; } ' +
  543. 'div.id2 a:visited div.unseen, div.id2 a:visited div.unseen { color:#41444b !important; } ' +
  544. 'span.expunged { color: #eba286; } '+
  545.  
  546. //along right stacked
  547. 'div.tagbox { position:absolute; line-height:1px; top:0; right:0; text-align:left; width:auto; max-width:185px; padding: 3px 5px 3px 7px; border-radius: 0 0 0 9px; box-shadow: 1px -1px 3px rgba(52, 53, 59, 0.2) inset; background: linear-gradient(to left bottom, rgba(78, 81, 88, 0.5) 15%, rgba(78, 81, 88, 0.2)); }'+
  548.  
  549. //top left
  550. 'div.catbox { background: linear-gradient(to right bottom, rgba(78, 81, 88, 0.5) 15%, rgba(78, 81, 88, 0.2)) repeat scroll 0 0 transparent; border-radius: 0 0 9px 0; box-shadow: 1px -1px 3px rgba(52, 53, 59, 0.2) inset; display: block; left: 4px; padding: 2px 7px; position: absolute; text-align: left; top: 57px; width: auto; } ' +
  551.  
  552. //bottom right
  553. //' div.tagbox { background: linear-gradient(to left top, rgba(78, 81, 88, 0.5) 15%, rgba(78, 81, 88, 0.2)) repeat scroll 0 0 transparent; border-radius: 9px 0 0 0; bottom: 0; box-shadow: 1px 1px 2px rgba(52, 53, 59, 0.25) inset; max-width: 185px; padding: 2px 0 2px 7px; position: absolute; right: 0; text-align: right; width: auto; } ' +
  554.  
  555. 'div.id2 a {display: block; vertical-align:top; padding: 5px 7px; height:100%;} div.id2{display:block}'+
  556.  
  557. //'span.floatflag, div.id4 {pointer-events:none;}'+
  558. 'span.floatflag {pointer-events:none;}'+
  559. 'div.id44 {z-index:11;}'+
  560. 'div.itg {padding-top:15px; padding-left:25px; max-width:1150px;}'+
  561. ' div#pt { padding-top:40px; } ' +
  562.  
  563.  
  564. //list view row colors
  565. ' table.itg tr:nth-child(2n) { background: none repeat scroll 0 0 #F2F0E4 !important; }' +
  566. ' table.itg tr:nth-child(2n+1) { background: none repeat scroll 0 0 #EDEBDF !important; }' +
  567.  
  568. //info footer
  569. ' div.id4 { background: linear-gradient(to top, rgba(78, 81, 88, 1) 15%, rgba(78, 81, 88, 0.1)) repeat scroll 0 0 rgba(0, 0, 0, 0); border-radius:0 0 3px 3px; } ' + //info footer
  570. ' div.id4 { height:23px; width:200px; right:8px; bottom:2px; } ' +
  571. ' div.id44 { width:58px; } ' + //dl button
  572.  
  573. //' div.id41, div.id42, div.id43, div.id44 { display: none; } ' +
  574. ' div.id1 { background: none repeat scroll 0 0 transparent; border: medium none; }' +
  575. ' div.itg { border: medium none; } ' +
  576.  
  577. ' div.id2 { background-image: linear-gradient(rgba(52, 53, 59, 0.5) 5%, rgba(52, 53, 59, 0) 19%); border-radius: 9px 9px 9px 9px; box-shadow: 1px 0px 2px rgba(52, 53, 59, 0.8); height:100%; } '+
  578. ' div.id1 { background:rgba(67,70,78,0.2); }'+
  579. '</style>').appendTo("head");
  580.  
  581. if (!document.URL.match(/^http:\/\/g\.e-hentai\.org\/.*$/)) {
  582. $('<style type="text/css">'+
  583. ' table.itg tr:nth-child(2n) { background: none repeat scroll 0 0 #4F535B !important; }' +
  584. ' table.itg tr:nth-child(2n+1) { background: none repeat scroll 0 0 #363940 !important; }' +
  585. '</style>').appendTo("head");
  586. }
  587.  
  588.  
  589.  
  590. //
  591. //
  592. //
  593. // save page state for soft reload
  594. //$head_html = $("head").html();
  595. //$body_html = $('div.ido').html();
  596. var $head_html;
  597. var $body_html;
  598. function saveGalState() {
  599. $head_html = document.getElementsByTagName('head')[0].innerHTML;
  600. try{ $body_html = document.getElementsByClassName('ido')[0].innerHTML; }
  601. catch(e){} //class not present on non-gal pages, needed when called out of index case from i(); at very bottom can probably refactor and remove try catch
  602. } saveGalState();
  603.  
  604. function loadGalState() {
  605. try {
  606. document.getElementsByTagName('head')[0].innerHTML = $head_html;
  607. } catch(e) {console.log(e);}
  608. try {
  609. document.getElementsByClassName('ido')[0].innerHTML = $body_html;
  610. } catch(e) {console.log(e);}
  611. }
  612.  
  613.  
  614. $cfg_grey = GM_getValue("ehp_grey", true);
  615. if ($cfg_grey) { grey_css(); }
  616.  
  617.  
  618. function RegEscape(str) {
  619. return (str+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
  620. }
  621.  
  622. //
  623. //
  624. //rebuild gallery titles
  625. $list_t = [];
  626. $list_ltm = [];
  627. function fixTitles() {
  628.  
  629. //thumbnail view
  630. $('.id2 a').each( function(i) {
  631. var $fulltitle = $(this).html();
  632.  
  633. //(con) [circle (artist)] title (parody) [lang] [trans] [misc]
  634.  
  635. var $con = '';
  636. var $circle = '';
  637. var $extrahead = '';
  638.  
  639. var $title = '';
  640. var $artist = '';
  641. var $parody = '';
  642. var $lang = '';
  643. var $remains = $fulltitle;
  644.  
  645. var $category = $(this).closest('.id1').find('.id4 .id41').first().attr('title');
  646.  
  647. //var $isExpunged = $(this).closest('.id1').find(".tn[title='This gallery is expunged']").length > 0; //expunged
  648.  
  649. //con
  650. var $match = $remains.match(/^(\([^\)]*\))\s*(.*)/); // ()
  651. if ($match) {
  652. $remains = $match[2];
  653. $con = $match[1];
  654. }
  655. //circle
  656. $match = $remains.match(/^(\[[^\]]*\])\s*(.*)/); //[]
  657. if ($match) {
  658. $remains = $match[2];
  659. $circle = $match[1];
  660. }
  661.  
  662. //artist (inside circle)
  663. $match = $circle.match(/^\[[^\(]*(\([^\)]*\)).*\]$/);
  664. if ($match) {
  665. $artist = $match[1];
  666. $circle = $circle.replace($artist,'');
  667. $circle = $circle.replace(' ]',']');
  668. }
  669.  
  670.  
  671. //extra pre title
  672. $match = $remains.match(/^(\([^\)]*\))\s*(.*)/); // ()
  673. if ($match) {
  674. $remains = $match[2];
  675. $extrahead += $match[1];
  676. }
  677. $match = $remains.match(/^(\[[^\]]*\])\s*(.*)/); // []
  678. if ($match) {
  679. $remains = $match[2];
  680. $extrahead += $match[1];
  681. }
  682.  
  683.  
  684. //title
  685. $match = $remains.match(/^([^\[\((]*)\s*(.*)/); //(con) [circle (artist)] title (parody) [lang] [trans] [misc]
  686. if ($match) {
  687. $remains = $match[2];
  688. $title = $match[1].trim();
  689. }
  690.  
  691. $list_t[i] = $title;
  692. $list_ltm[i] = $remains;
  693.  
  694. //try to detect and balance 2 line titles
  695. var $len = $title.length;
  696. if ($len > 25 && $len < 50) { //26 55
  697. $newt = '';
  698. $issplit = 0;
  699. $words = $title.split(" ");
  700.  
  701. if ($words.length > 1) {
  702. $.each($words, function(i, v) {
  703.  
  704. if (!$issplit && ($newt.length + v.length) > ($len - $newt.length)) {
  705. $newt = $newt.trim()+'<br>';
  706. $issplit = 1;
  707. }
  708. $newt += v + ' ';
  709. });
  710. $newt = $newt.trim();
  711. $title = $newt;
  712. }
  713. }
  714.  
  715.  
  716. //parody
  717. $match = $remains.match(/(\([^\)]*\))\s*(.*)/); // ()
  718. //$match = $remains.match(/\(([^\)]*)\)\s*(.*)/); // () --now excludes parens in capture
  719. if ($match) {
  720. $remains = $match[2];
  721. $parody = $match[1].trim();
  722. }
  723.  
  724. //lang
  725. $match = $remains.match(/^(\[[^\]]*\])\s*(.*)/); //[]
  726. if ($match) {
  727. $remains = $match[2];
  728. $lang = $match[1].trim();
  729. }
  730.  
  731.  
  732. //
  733. //highlight by title contents
  734. $div = $(this).closest('.id1');
  735. $.each($hi_sets, function(i,v) {
  736. $hi_tags = v.split(/:/);
  737.  
  738. if ($hi_tags.length == 3 || $hi_tags.length == 4) {
  739. $selector = $hi_tags[0];
  740. $term = $hi_tags[1];
  741. $color = $hi_tags[2];
  742.  
  743. $mode = "border";
  744. if ($hi_tags.length == 4) {
  745. if ($hi_tags[3] == "top") $mode = "top";
  746. }
  747.  
  748.  
  749. if ($term.charAt(0) != '#')
  750. $term = RegEscape($term);
  751. else
  752. $term = $term.substring(1);
  753.  
  754.  
  755. $match = false;
  756. switch($selector) {
  757. case "*" :
  758. $match = $fulltitle.match(new RegExp($term, "i")); break;
  759.  
  760. case "title" :
  761. if (!$title) break;
  762. $match = $title.match(new RegExp($term, "i")); break;
  763.  
  764. case "parody" :
  765. if (!$parody) break;
  766. $match = $parody.match(new RegExp($term, "i")); break;
  767.  
  768. case "circle" :
  769. if (!$circle) break;
  770. $match = $circle.match(new RegExp($term, "i")); break;
  771.  
  772. case "artist" :
  773. if (!$artist) break;
  774. $match = $artist.match(new RegExp($term, "i")); break;
  775.  
  776. case "category" :
  777. if (!$category) break;
  778. $match = $category.match(new RegExp($term, "i")); break;
  779.  
  780. default :
  781. }
  782. if ($match) {
  783. //highlight top
  784. if ($mode == "top") {
  785. $imgdiv = $div.find(".id3").first();
  786. $imgdiv.css('border-top', '7px solid ' + $color);
  787. $imgdiv.css('background-color', $color);
  788. $imgdiv.css('border-radius', '7px');
  789. $imgdiv.parent().css('padding-bottom','14px'); //fix height
  790. }
  791. //highlight border
  792. else {
  793. $div.css('background', $color);
  794. }
  795.  
  796. }
  797. }
  798.  
  799. });
  800. //$tags = $gettags.split(/,[ ]*/);
  801.  
  802. //if ($isExpunged) $title = '<span class="expunged">' + $title + '</span>';
  803.  
  804. var $newt = '';
  805.  
  806. if (!$cfg_cust) //default fixed title
  807. {
  808. $newt += $title;
  809. $newt +=($title?'<br>':'')+'<span class="subtitle">'+ $parody + ($lang?' '+$lang:'') + '</span>';
  810. $len += $parody.length + $lang.length;
  811. }
  812. else
  813. {
  814. //custom style
  815. $customt = $cfg_titleformat;
  816. $customt = $customt.replace("rawtitle" ,$fulltitle);
  817. $customt = $customt.replace("con" ,$con);
  818. $customt = $customt.replace("artist",$artist);
  819. $customt = $customt.replace("misc" ,$remains);
  820. $customt = $customt.replace("circle",$circle);
  821. $customt = $customt.replace("lang" ,$lang);
  822. $customt = $customt.replace("parody",$parody);
  823. $customt = $customt.replace("title" ,$title);
  824. $customt = $customt.replace(/category/gi ,$category);
  825.  
  826. $newt = $customt;
  827. }
  828.  
  829.  
  830. //shrink font for long titles
  831. if ($len > 140) { //5 line tiny
  832. $(this).css('font-size','8.4px');
  833. $(this).css('line-height','9.3px');
  834. }
  835. else if ($len > 115) { //5 line small
  836. $(this).css('font-size','10.3px');
  837. $(this).css('line-height','10.1px');
  838. }
  839.  
  840.  
  841. //todo fix with custom
  842. //rescue malformed title (such as circle [ not closed)
  843. if (!$title && !$remains)
  844. $newt = '<span style="font-size:10px;">'+($circle ? $circle : $con)+'</span>';
  845.  
  846. $(this).html($newt);
  847.  
  848. });
  849. }
  850.  
  851.  
  852. function getAppendTag($tagbox,$class,$text) {
  853. $stext = $text.replace(/.*:/,"");
  854. if ($cfg_shortentags) $stext = $stext.substring(0,4); //tag first4 chars without namespace
  855. $stext = $stext [0].toUpperCase() + $stext.slice(1); //upper first char
  856.  
  857. //override color when grad style set
  858. if ($flagLookupC[$text]) {
  859. return '<div class="floatflag stroke2" style="color:'+$flagLookupC[$text]+'">'+$stext+'</div>&nbsp;';
  860. }
  861. else return '<div class="floatflag stroke2 '+$class+'">'+$stext+'</div>&nbsp;';
  862. }
  863.  
  864. function injectTagbox($target,$tagbox) {
  865. $target.closest('.id1').children('.id3').first().append($tagbox);
  866. //alert ($tagbox);
  867. }
  868.  
  869. function alphaThumb($tag) {
  870. $p = $tag.closest('.id1'); //also fade title in gallery
  871.  
  872. var $alpha = parseFloat($cfg_fadealpha);
  873. if (isNaN($alpha))
  874. $alpha = '0.2';
  875.  
  876. //$p.fadeTo(0, 0.15);
  877. $p.css('opacity', $alpha);
  878. //$p.animate({width: '114'}, 'slow'); //could do accordion with this
  879.  
  880. $p.hover(
  881. function() { $(this).stop().fadeTo('fast', 1); },
  882. function() { $(this).stop().fadeTo('fast', $alpha); }
  883. );
  884. }
  885.  
  886. function killThumb($tag) {
  887. $listnode = $tag.closest('.id1');
  888. $listnode.detach();
  889. }
  890.  
  891. function cleanTag($tag) { $tag.detach(); }
  892.  
  893.  
  894. //for hue sorting
  895. function rgbToHue(r, g, b){
  896. r /= 255, g /= 255, b /= 255;
  897. var max = Math.max(r, g, b), min = Math.min(r, g, b);
  898. var h, s, l = (max + min) / 2;
  899.  
  900. if(max == min){
  901. h = s = 0; // achromatic
  902. }else{
  903. var d = max - min;
  904. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  905. switch(max){
  906. case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  907. case g: h = (b - r) / d + 2; break;
  908. case b: h = (r - g) / d + 4; break;
  909. }
  910. h /= 6;
  911. }
  912.  
  913. return h;
  914. }
  915.  
  916.  
  917. //
  918. //foreach tag
  919. function fixuptags() {
  920. $seencount = 0;
  921. $list_rating = [];
  922. $list_rating_faded = [];
  923. $g_hidden = [];
  924. var $tagdb = {};
  925. $j=0;
  926. $rx=0;
  927.  
  928. //old visited code
  929. //$galdb = safeEval(GM_getValue("eh_galdb", "({});")); //load visited gal dv
  930.  
  931. $('.itg > div.id1').each( function(ix) {
  932. $(this).find(".id44").each(function(index) {
  933. $rating = 500; //center on 500
  934.  
  935. //alert(uneval($tagdb));
  936.  
  937. $posmap = [];
  938. $posmap["0px -1px"] = "fr1";
  939. $posmap["0px -18px"] = "fr2";
  940. $posmap["0px -35px"] = "fr3";
  941. $posmap["0px -52px"] = "fb1";
  942. $posmap["0px -69px"] = "fb2";
  943. $posmap["0px -86px"] = "fb3";
  944.  
  945. $tagContainer = $(this);
  946. $div = $(this).closest('.id1');
  947.  
  948. $flagColors = [];
  949. $flagHues = [];
  950. $flagLookupC = new Object();
  951. $flagLookupH = new Object();
  952. $alltags = "";
  953. $tagHues = [];
  954. $taggroup = $(this).find(".tft"); //children
  955. $taggroup.each(function(jx) {
  956. $gettags = $(this).prop("title");
  957. $position = $(this).css("background-position");
  958. $class = $posmap[$position] ? $posmap[$position] : "fbx" ;
  959.  
  960. $tags = $gettags.split(/,[ ]*/);
  961. //for each tag
  962. $.each($tags,function(i,v) {
  963.  
  964. //highlight by tag
  965. $.each($hi_sets, function(i,w) {
  966. $hi_tags = w.split(/:/);
  967.  
  968. if ($hi_tags.length == 3 || $hi_tags.length == 4) {
  969. $selector = $hi_tags[0];
  970. $term = $hi_tags[1];
  971. $color = $hi_tags[2];
  972.  
  973. $mode = "border";
  974. if ($hi_tags.length == 4) {
  975. if ($hi_tags[3] == "top") $mode = "top";
  976. if ($hi_tags[3] == "fgrad") $mode = "fgrad";
  977. if ($hi_tags[3] == "fcolor") $mode = "fcolor";
  978. }
  979.  
  980. if ($term.charAt(0) != '#') $term = RegEscape($term);
  981. else $term = $term.substring(1);
  982.  
  983. $match = false;
  984. if ($selector == "tag")
  985. $match = v.match(new RegExp($term, "i"));
  986.  
  987. if ($match) {
  988. //highlight top
  989. if ($mode == "top") {
  990. $imgdiv = $div.find(".id3").first();
  991. $imgdiv.css('border-top', '7px solid ' + $color);
  992. $imgdiv.css('background-color', $color);
  993. $imgdiv.css('border-radius', '7px');
  994. $imgdiv.parent().css('padding-bottom','14px'); //fix height
  995. }
  996. //background gradient
  997. else if ($mode == "fgrad") {
  998. //decode to rgb, calculate hue for sorting
  999. $("#cBox").css('color',$color);
  1000. $rgb = $("#cBox").css('color');
  1001. $rgbx = $rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
  1002. $hue = rgbToHue($rgbx[1],$rgbx[2],$rgbx[3]);
  1003.  
  1004. $flagLookupC[v] = $color;
  1005. $flagLookupH[v] = $hue;
  1006.  
  1007. $flagHues.push(zeroPad(Math.floor($hue * 256)) + zeroPad($flagColors.length));
  1008. $flagColors.push($color);
  1009. }
  1010. //set flag color only
  1011. else if ($mode == "fcolor") {
  1012. //decode to rgb, calculate hue for sorting
  1013. $("#cBox").css('color',$color);
  1014. $rgb = $("#cBox").css('color');
  1015. $rgbx = $rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
  1016. $hue = rgbToHue($rgbx[1],$rgbx[2],$rgbx[3]);
  1017.  
  1018. $flagLookupC[v] = $color;
  1019. $flagLookupH[v] = $hue;
  1020. }
  1021. //highlight border
  1022. else {
  1023. $div.css('background', $color);
  1024. }
  1025. }
  1026. }
  1027. });
  1028.  
  1029. if (typeof $tagdb[v] === 'undefined' || $tagdb[v] != $class) {
  1030. $tagdb[v] = $class;
  1031. }
  1032. });
  1033.  
  1034. $alltags = $alltags + (jx?",":"") + $tags
  1035. });
  1036. //virtual tag for expunged
  1037. /*
  1038. $tagdb["expunged"] = "fr1";
  1039. var $isExpunged = $(this).closest('.id1').find(".tn[title='This gallery is expunged']").length > 0; //expunged
  1040. if ($isExpunged) {
  1041. $alltags = $alltags + ($alltags.length>0?",":"") + "expunged";
  1042. }*/
  1043.  
  1044. //do hue sort
  1045. $flagHues.sort().reverse();
  1046. $flagColorsX = $flagColors;
  1047. $flagColors = [];
  1048. $.each($flagHues, function(i, v) {
  1049. $ixx = parseInt(v.slice(-3),10);
  1050.  
  1051. //more push = harder, fewer = softer
  1052. $flagColors.push($flagColorsX[$ixx]);
  1053. $flagColors.push($flagColorsX[$ixx]);
  1054. $flagColors.push($flagColorsX[$ixx]);
  1055. $flagColors.push($flagColorsX[$ixx]);
  1056. $flagColors.push($flagColorsX[$ixx]);
  1057. $flagColors.push($flagColorsX[$ixx]);
  1058. });
  1059.  
  1060. //rainbow gradient for each set flag
  1061. if ($flagColors.length > 0) {
  1062. //if ($flagColors.length == 1) $flagColors.push($flagColors[0]);
  1063. $div.css('background', "linear-gradient(to right, "+ $flagColors.join(", ") +")");
  1064. //$div.css('background', "linear-gradient(to right, red, orange, yellow, green, blue)");
  1065. }
  1066.  
  1067.  
  1068. $faded = false;
  1069. $hidden = false;
  1070.  
  1071. //tally and process visited
  1072. var gal_href = $tagContainer.closest('.id1').find('div.id2 a').first().attr('href');
  1073. var gal_idx = gal_href.match(/^http:\/\/(?:g\.e-|e[^-])hentai\.org\/g\/(\d*)\/.*$/);
  1074. if (!isNaN(gal_idx[1])) {
  1075.  
  1076. //old visited code
  1077. var gal_id = parseInt(gal_idx[1],10);
  1078. //if ($galdb[gal_id]) {
  1079. $tagContainer.closest('.id1').find('.id2').addClass('vx');
  1080. if (isGalVisited(gal_id)) {
  1081. $seencount++;
  1082. $tagContainer.closest('.id1').find('div.id2 a').first().attr('href');
  1083. if ($cfg_hidevisited) {
  1084. $hidden = true;
  1085. killThumb($tagContainer);
  1086. }
  1087. else if ($cfg_fadevisited) {
  1088. $faded = true;
  1089. alphaThumb($tagContainer);
  1090. }
  1091.  
  1092. }
  1093. }
  1094. if ($alltags && !$hidden) { //if it has tags
  1095. $tags = $alltags.split(/,[ ]*/);
  1096.  
  1097. //add base class hues to table
  1098. //quick and dirty
  1099. $.each($tags, function(i, v) {
  1100.  
  1101. if ($flagLookupH.hasOwnProperty(v)) return true; //skip overridden tag colors
  1102.  
  1103. $class = $tagdb[v];
  1104. if (!$class) $class = "fbx";
  1105. $col = $baseColors[$class];
  1106. $("#cBox").css('color',$col);
  1107. $rgb = $("#cBox").css('color');
  1108. $rgbx = $rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
  1109. $hue = rgbToHue($rgbx[1],$rgbx[2],$rgbx[3]);
  1110.  
  1111. $flagLookupH[v] = $hue;
  1112. });
  1113.  
  1114.  
  1115.  
  1116. //sort tags by hue
  1117. $tags.sort(function(a,b) {
  1118. if (!$flagLookupH.hasOwnProperty(a) && !$flagLookupH.hasOwnProperty(b)) return 0;
  1119. if (!$flagLookupH.hasOwnProperty(a) && $flagLookupH.hasOwnProperty(b)) return 1;
  1120. if ($flagLookupH.hasOwnProperty(a) && !$flagLookupH.hasOwnProperty(b)) return -1;
  1121.  
  1122. return $flagLookupH[a] < $flagLookupH[b] ? 1 : $flagLookupH[a] > $flagLookupH[b] ? -1 : 0;
  1123. });
  1124.  
  1125. $forceshow=0;
  1126. if ($cfg_showlist) {
  1127. $stags=$cfg_showlist.split(',');
  1128. $.each($stags, function(i, v) {
  1129. $stag = $.trim(v);
  1130.  
  1131. $tags.forEach( function($fulltag, $i) {
  1132. $plaintag = $fulltag.replace(/.*:/,"");
  1133. if ($fulltag == $stag || $plaintag == $stag)
  1134. $forceshow=1;
  1135. });
  1136.  
  1137. });
  1138. }
  1139.  
  1140. var tagbox = '<div class="tagbox">';
  1141. var kill = false;
  1142. var alpha = false;
  1143. $tags.forEach( function($fulltag, $i) {
  1144. //hide specific tags if set and matched unless in show list
  1145. if ($cfg_hidelist && !$forceshow) {
  1146. $htags=$cfg_hidelist.split(',');
  1147.  
  1148. $.each($htags, function(i, v) {
  1149. $htag = $.trim(v);
  1150.  
  1151. $plaintag = $fulltag.replace(/.*:/,""); //strip namespace
  1152. if ($fulltag == $htag || $plaintag == $htag || $htag == '*') {
  1153. $hidden = true;
  1154. kill = true;
  1155. killThumb ($tagContainer);
  1156. return false;//break;
  1157. }
  1158. });
  1159. }
  1160.  
  1161.  
  1162. if ($tagdb[$fulltag]) { //known tag
  1163. $class = $tagdb[$fulltag];
  1164.  
  1165. $type = $class.charAt(1);
  1166. if ($type == 'r' && $cfg_hide && !$forceshow) {
  1167. $hidden = true;
  1168. killThumb ($tagContainer);
  1169. return false;//break;
  1170. }
  1171. if ($type == 'r' && $cfg_fade) alpha = true;
  1172. if ($type == 'r') $rating-=2;
  1173. else if ($type == 'b') $rating++;
  1174.  
  1175. tagbox+=getAppendTag(tagbox,$class,$fulltag);
  1176. }
  1177. else { //unknown tag
  1178. $class = 'fbx';
  1179. tagbox+=getAppendTag(tagbox,$class,$fulltag);
  1180. }
  1181.  
  1182.  
  1183. if ($type == 'r' && $cfg_fade) $faded = true;
  1184.  
  1185. });
  1186. if (!kill) {
  1187. tagbox+='</div>';
  1188. injectTagbox($tagContainer, tagbox);
  1189. if (alpha) alphaThumb ($tagContainer);
  1190. }
  1191. cleanTag($tagContainer);
  1192.  
  1193. if (!$hidden) {
  1194. $list_rating_faded[$j]=$rating - ($faded?100:0); // -100 if faded
  1195. $list_rating[$j++]=$rating;
  1196. }
  1197.  
  1198.  
  1199. }
  1200. else if (!$hidden) {
  1201.  
  1202.  
  1203. //hide untagged if hidetag *
  1204. $tag = $(this);
  1205. $htags=$cfg_hidelist.split(',');
  1206. $.each($htags, function(i, v) {
  1207. $htag = $.trim(v);
  1208. if ($htag == '*') {
  1209. $hidden = true;
  1210. killThumb($tagContainer);
  1211. return false;//break;
  1212. }
  1213. });
  1214.  
  1215.  
  1216. if (!$hidden) {
  1217. $list_rating_faded[$j]=500 - ($faded?100:0); // -100 if faded
  1218. $list_rating[$j++]=500;
  1219. }
  1220. }
  1221. if ($hidden) {
  1222. $list_ltm.splice(ix-($rx),1); //del from lang trans misc
  1223. $list_t.splice(ix-($rx++),1); //del from title
  1224. }
  1225.  
  1226. });
  1227. });
  1228.  
  1229. //preserve stars if enabled
  1230. if (!$cfg_stars) {
  1231. $("div.id4").remove(); //nuke no longer needed id4 stuff
  1232. }
  1233.  
  1234. $("div.id3 img").attr("title","");
  1235. //nuke img title (mouseover)
  1236.  
  1237. $("#seencount").text($seencount);
  1238. }
  1239.  
  1240. function fixthumbheights() {
  1241. $list_h = [];
  1242. $list_hg = [];
  1243. $list_e = [];
  1244. //
  1245. //
  1246. //fixup thumb heights
  1247. $('.itg > div.id1').each( function(i) {
  1248. $img = $(this).children('.id3'); //
  1249. $thumb = $(this).children('.id3').find('img')
  1250. $thumb.attr('alt','');
  1251. $src = $thumb.attr("src");
  1252.  
  1253. $thumb_res = $src.match( /^[^-]*-[^-]*-(\d+)-(\d+)-.{3}_l\.jpg$/);
  1254.  
  1255. if (!$thumb_res) {
  1256. //return true; //continue
  1257. $hx = parseInt($img.css('height').replace(/[^0-9-]/,""),10) -3;
  1258. $h = $hx;
  1259. $w = 200;
  1260. }
  1261. else {
  1262. $w = $thumb_res[1];
  1263. $h = $thumb_res[2];
  1264.  
  1265. $h = $h * 200 / $w;
  1266. $w = 200;
  1267. if ($h > 300) {
  1268. $w = $w * 300 / $h;
  1269. $h = 300;
  1270. }
  1271. $w = Math.round($w *1);
  1272. $h = Math.round($h *1);
  1273.  
  1274. $hx = parseInt($img.css('height').replace(/[^0-9-]/,""),10) -3;
  1275. if (!$cfg_unchop && !$cfg_group) {
  1276. $h = Math.min($hx,$h);
  1277. }
  1278. }
  1279.  
  1280. //now set after sort
  1281. if ($cfg_sortdef) {
  1282. $(this).css('height', ($h)+'px'); //main h
  1283. $img.css('height', $h+'px'); //container h
  1284. }
  1285.  
  1286. if ($w < 100) $w = 100; //for thin images so stars/tag visible
  1287. $img.css('width', $w+'px'); //container w
  1288.  
  1289. var $title = $list_t[i];
  1290. var $misc = $list_ltm[i];
  1291.  
  1292. $list_e[i] = $(this);
  1293. $rating = $list_rating_faded[i];
  1294.  
  1295. $list_h[i] = zeroPad($h) + $title + zeroPad($h) + zeroPad(i); //HHH TITLE HHH III
  1296. //sort rating first
  1297. //$list_hg[i] = $title + "_" + zeroPad($rating) + $misc + zeroPad($h) + zeroPad(i); //TITLE _ [MISC] RRR HHH III
  1298. //sort title first (fixes order on mismatched tags in set)
  1299. //$list_hg[i] = $title + "_" + $misc + zeroPad($rating) + zeroPad($h) + zeroPad(i); //TITLE _ [MISC] RRR HHH III
  1300. $list_hg[i] = $title + zeroPad($rating) + zeroPad($h) + zeroPad(i); //TITLE RRR HHH III (must also edit TITLESORT)
  1301. });
  1302.  
  1303.  
  1304.  
  1305. }
  1306.  
  1307. function fuzzy_compare(a,b){
  1308. var al=a.length;
  1309. var bl=b.length;
  1310.  
  1311. var ah = parseInt(a.substring(al-6,al-3), 10);
  1312. var bh = parseInt(b.substring(bl-6,bl-3), 10);
  1313. //radius can lead to circular reference issues [a>b>c>a]
  1314. //see http://exhentai.org/tag/artist:asanagi radius 150px;
  1315. if (ah + $cfg_group_radius < bh) return 1;
  1316. if (bh + $cfg_group_radius < ah) return -1;
  1317.  
  1318. var at = a.substring(0,al-6);
  1319. var bt = b.substring(0,bl-6);
  1320.  
  1321. if (at < bt) return 1;
  1322. if (at > bt) return -1;
  1323. return 0;
  1324. }
  1325.  
  1326.  
  1327. function sort_default() {
  1328. $.each ($list_e, function(i,v) { v.detach(); });
  1329. $('.itg').children('.c').each( function() { $(this).remove(); }); //strip clears
  1330. $div = $('.itg');
  1331.  
  1332. $.each($list_e, function(i,v) {
  1333. v.appendTo($div);
  1334.  
  1335. if (((i+1) % $cfg_columns) == 0) {
  1336. $div.append('<div class="c"></div>');
  1337. }
  1338.  
  1339. });
  1340. return;
  1341. }
  1342.  
  1343. //a too small compared to b, considering fuzzy radius
  1344. function aTooSmall(a,b) {
  1345. var al = a.length;
  1346. var bl = b.length;
  1347.  
  1348. var ah = parseInt(a.substring(al-6,al-3), 10);
  1349. var bh = parseInt(b.substring(bl-6,bl-3), 10);
  1350. if (ah + $cfg_group_radius < bh) return true;
  1351. if (a>b) return true; //out of order
  1352. return false;
  1353. }
  1354.  
  1355. Array.prototype.move = function(from, to) {
  1356. this.splice(to, 0, this.splice(from, 1)[0]);
  1357. };
  1358.  
  1359. //
  1360. // sort by height etc
  1361. function sort_compact() {
  1362.  
  1363. //fuzzy sort
  1364. if ($cfg_group) {
  1365.  
  1366. //strip chars
  1367. for(var $i=0; $i<$list_hg.length; $i++) {
  1368. //$list_hg[$i] = $list_hg[$i].replace(/[\s\.!,~~?:+”'="|//()[\]-]/g,"").toLowerCase(); //conservative
  1369. $list_hg[$i] = $list_hg[$i].replace(/[^a-zA-Z0-9]/g,"").toLowerCase();
  1370. }
  1371.  
  1372. //0 prefix single digit numbers
  1373. for(var $i=0; $i<$list_hg.length; $i++) {
  1374. $list_hg[$i] = $list_hg[$i].replace(/([^\d])(\d)([^\d])/g,"$10$2$3") //mid string
  1375. $list_hg[$i] = $list_hg[$i].replace(/([^\d])(\d)([\d]{9})$/,"$10$2$3") //end of string
  1376. }
  1377.  
  1378. //01 suffix non numbered files
  1379. for(var $i=0; $i<$list_hg.length; $i++) {
  1380. $list_hg[$i] = $list_hg[$i].replace(/([^\d])([\d]{9})$/,"$101$2"); //TITLESORT, set above
  1381. }
  1382. //height > alpha sort
  1383. /*
  1384. $list_hg.sort(function(a,b){
  1385. var al=a.length;
  1386. var bl=b.length;
  1387. var ah = parseInt(a.substring(al-6,al-3), 10);
  1388. var bh = parseInt(b.substring(bl-6,bl-3), 10);
  1389. if(bh<ah) return -1;
  1390. if(ah<bh) return 1;
  1391. if(b<a) return -1;
  1392. if(a<b) return 1;
  1393. return 0;
  1394. });*/
  1395. //alpha sort
  1396. /*
  1397. $list_hg.sort(function(a,b){
  1398. if(b<a) return -1;
  1399. if(a<b) return 1;
  1400. return 0;
  1401. }); */
  1402. //broken experimental
  1403. /*
  1404. //for each tile see if it should get pushed back by size
  1405. var hgl = $list_hg.length;
  1406. for(var $i=0; $i<(hgl-1); $i++) {
  1407. var a = $list_hg[$i];
  1408. var b = $list_hg[$i+1];
  1409.  
  1410. if (aTooSmall(a,b)) {
  1411. //shift down to good position
  1412. var $j=$i+1;
  1413. while (++$j<hgl) {
  1414. b = $list_hg[$j];
  1415. if (!aTooSmall(a,b)) break;
  1416. }
  1417. $j = Math.min($j,hgl-1);
  1418. //$list_hg.move($i,$j+1);
  1419. }
  1420.  
  1421. }*/
  1422. //fuzzy sort
  1423. //$list_hg.sort(fuzzy_compare);
  1424. //old fuzzy sort
  1425. var hgl = $list_hg.length;
  1426. for(var $i=0; $i<hgl; $i++) {
  1427. for(var $j=$i; $j<hgl; $j++) {
  1428. $cmp = fuzzy_compare($list_hg[$i], $list_hg[$j]);
  1429. if ($cmp == 1) {
  1430. $t = $list_hg[$i]
  1431. $list_hg[$i] = $list_hg[$j];
  1432. $list_hg[$j] = $t;
  1433. }
  1434. }
  1435. //$t = $list_hg[$i];
  1436. //var ih = parseInt($t.substring($t.length-6,$t.length-3), 10);
  1437. //minheight = Math.min(minheight,ih);
  1438. }
  1439. $list_h = $list_hg;
  1440.  
  1441. }
  1442. else {
  1443. $list_h.sort();
  1444. $list_h.reverse();
  1445. }
  1446.  
  1447. $.each ($list_e, function(i,v) { v.detach(); });
  1448. $('.itg').children('.c').each( function() { $(this).remove(); }); //strip clears
  1449. $('#pp').children('.c').each( function() { $(this).remove(); }); //strip clears
  1450. $div = $('.itg');
  1451.  
  1452. //big to small
  1453. if ($cfg_sortsize) {
  1454. $.each($list_h, function(i,v) {
  1455. //alert(v);
  1456. $j = parseInt(v.substring(v.length-3), 10);
  1457. $list_e[$j].appendTo($div);
  1458.  
  1459. if (((i+1) % $cfg_columns) == 0) {
  1460. $div.append('<div class="c"></div>');
  1461. }
  1462.  
  1463. });
  1464. }
  1465.  
  1466. //debug sorting
  1467. //for(var $i=0; $i<$list_h.length; $i++) {
  1468. //console.log($list_h[$i]);
  1469. //}
  1470.  
  1471.  
  1472. try {
  1473. $list_ht = $list_h.slice();
  1474. if ($cfg_sortzig) {
  1475. //zig zag tall and short rows
  1476. $k=$list_ht.length; $j=0;
  1477. for ($i=0; $i<$k; $i++) {
  1478.  
  1479. if ($j) $x = $list_ht.pop();
  1480. else $x = $list_ht.shift();
  1481.  
  1482. $l = parseInt($x.substring($x.length-3), 10);
  1483. $ele = $list_e[$l];
  1484.  
  1485. $ele.appendTo($div);
  1486. if ((($i+1) % $cfg_columns) == 0) {
  1487. $j = !$j;
  1488. $div.append('<div class="c"></div>');
  1489. }
  1490. }
  1491. }
  1492. } catch(e) { alert (e); }
  1493.  
  1494. }
  1495.  
  1496.  
  1497. function crop_tiles_fuzzy_sweep() {
  1498. //fixup heights rowsweep fuzzy
  1499. $mindif = 0.1; //crop no more than this % round up (can be more in sweep case)
  1500. for(var $i=0;$i<$list_h.length;$i+=$cfg_columns) {
  1501.  
  1502. $min=999;
  1503. //scan row
  1504. $newh = [];
  1505. for ($j=$i; $j<Math.min($list_h.length, $i+ $cfg_columns); $j++) {
  1506. $v = $list_h[$j];
  1507. $h = parseInt($v.substring($v.length-6,$v.length-3), 10);
  1508.  
  1509. $min = Math.min($h,$min);
  1510. }
  1511.  
  1512.  
  1513. for ($j=Math.min($list_h.length, $i+ $cfg_columns)-1; $j>=$i; $j--) {
  1514.  
  1515. //if all to left are > mindif taller then bump up size
  1516. $minleft = 999;
  1517. for ($k=$j; $k>=$i; $k--) {
  1518. $v = $list_h[$k];
  1519. $h = parseInt($v.substring($v.length-6,$v.length-3), 10);
  1520.  
  1521. $minleft = Math.min($h,$minleft);
  1522. }
  1523. if ($minleft > ($mindif + 1) * $min) $min = $minleft;
  1524.  
  1525. $v = $list_h[$j];
  1526. $k = parseInt($v.substring($v.length-3), 10);
  1527. $e = $list_e[$k];
  1528. $e.css('height', ($min)+'px'); //main h
  1529. $e.children('.id3').css('height', $min+'px'); //container h
  1530.  
  1531. }
  1532. }
  1533. }
  1534.  
  1535. function crop_tiles_fuzzy() {
  1536. //fixup heights fuzzy
  1537. $mindif = 0.1; //crop no more than this % round up
  1538. for(var $i=0;$i<$list_h.length;$i+=$cfg_columns) {
  1539.  
  1540.  
  1541. $rowmax = Math.min($list_h.length, $i+ $cfg_columns);
  1542. $rowcount = $rowmax - $i;
  1543.  
  1544. $doneCount = 0;
  1545. $done = [];
  1546. while ($doneCount < $rowcount) {
  1547. //find min from undone
  1548. $min=999;
  1549. for ($j=$i; $j<$rowmax; $j++) {
  1550. if ($done[$j] !== undefined) continue;
  1551.  
  1552. $v = $list_h[$j];
  1553. $h = parseInt($v.substring($v.length-6,$v.length-3), 10);
  1554.  
  1555. $min = Math.min($h,$min);
  1556. }
  1557.  
  1558. //crop all undone within radius, mark done
  1559. for ($j=$i; $j<$rowmax; $j++) {
  1560. if ($done[$j] !== undefined) continue;
  1561.  
  1562. $v = $list_h[$j];
  1563. $h = parseInt($v.substring($v.length-6,$v.length-3), 10);
  1564.  
  1565. if ($h <= $min * (1 + $mindif)) {
  1566. $k = parseInt($v.substring($v.length-3), 10);
  1567. $e = $list_e[$k];
  1568. $e.css('height', ($min)+'px'); //main h
  1569. $e.children('.id3').css('height', $min+'px'); //container h
  1570. $doneCount++;
  1571. $done[$j] = true;
  1572. }
  1573. }
  1574. }
  1575. }
  1576. }
  1577.  
  1578.  
  1579. function crop_tiles() {
  1580. if (!$cfg_group || $cfg_group_radius < 30) {
  1581. crop_tiles_fuzzy_sweep();
  1582. }
  1583. else {
  1584. crop_tiles_fuzzy();
  1585. }
  1586.  
  1587. }
  1588.  
  1589. function sort_tag() {
  1590. //
  1591. // sort by rating each good tag +1 bad -2
  1592.  
  1593. // RRR Title HHH III R=rating H=height I=index
  1594. //$.each ($list_rating, function(i,v) { $list_h[i] = zeroPad(v) + $list_hg[i]; });
  1595.  
  1596. // RRR HHH III R=rating H=height I=index
  1597. $.each ($list_rating, function(i,v) { $list_h[i] = zeroPad(v) + $list_h[i].substring($list_h[i].length-6,$list_h[i].length); });
  1598.  
  1599.  
  1600. $list_h.sort();
  1601. $list_h.reverse();
  1602.  
  1603.  
  1604. $.each ($list_e, function(i,v) { v.detach(); });
  1605. $('.itg').children('.c').each( function() { $(this).remove(); });
  1606.  
  1607. $div = $('.itg');
  1608.  
  1609.  
  1610. //big to small
  1611. $.each($list_h, function(i,v) {
  1612. $j = parseInt(v.substring(v.length-3,v.length), 10);
  1613. if ((i % $cfg_columns) == 0) { $div.append('<div class="c"></div>'); }
  1614. $list_e[$j].appendTo($div);
  1615. });
  1616.  
  1617. }
  1618.  
  1619. function fixColumns() {
  1620. $inner = $cfg_columns * ($gtile_width + $gtile_pad ) + 25;
  1621. $outer = Math.max($inner + 50);
  1622.  
  1623. $(
  1624. '<style type="text/css">'+
  1625. 'div.itg { width: ' + $inner + 'px; max-width: ' + $inner + 'px; min-width: ' + $inner + 'px; }'+
  1626. 'div.ido { width: ' + $outer + 'px; max-width: ' + $outer + 'px; min-width: ' + $outer + 'px; }'+
  1627. 'div#pp { width: ' + $outer + 'px; max-width: ' + $outer + 'px; }'+
  1628. '</style>').appendTo("head");
  1629. }
  1630.  
  1631.  
  1632. function xtt() { $("#fsrcb").prop('checked',true); }
  1633. function xttn() { $("#fsrcb").prop('checked',false); }
  1634. var curStarView = "";
  1635. var lastStarClick = "";
  1636. function setupStarButtons() {
  1637. //toggle advancedsearchenable
  1638. $("label.irx").click(xtt);
  1639. $("#irxn").click(xttn);
  1640.  
  1641. //submit when double click a star, but not on that star filter view
  1642. $("label.irx, #irxn").click(function(){
  1643.  
  1644. if (lastStarClick == $(this).attr('for') && curStarView != $(this).attr('for')) {
  1645. $('#searchbox > form').trigger('submit');
  1646. }
  1647. else lastStarClick = $(this).attr('for');
  1648. });
  1649. }
  1650.  
  1651. function setupMiniButtons() {
  1652. $('#toggleseen').parent().click(function (e) {
  1653.  
  1654. $cfg_hidevisited = !$cfg_hidevisited;
  1655.  
  1656. GM_setValue("ehp_hidevisited", $cfg_hidevisited);
  1657.  
  1658. try { $("head").html($head_html); }
  1659. catch(err) { }
  1660.  
  1661. try { $('div.ido').html($body_html); }
  1662. catch(err) { }
  1663.  
  1664. applychanges();
  1665. });
  1666. }
  1667.  
  1668.  
  1669. function applychanges() {
  1670. if ($cfg_grey) { grey_css(); }
  1671. if ($cfg_minimal) { minimal_css(); }
  1672.  
  1673. $hi_sets = $cfg_highlight.split(/[ ]*[,\n][ ]*/); //for highlighting
  1674.  
  1675. fixColumns();
  1676. fixTitles();
  1677. fixuptags();
  1678. fixthumbheights();
  1679.  
  1680. setupStarButtons();
  1681. setupMiniButtons();
  1682.  
  1683. if ($cfg_hidevisited) { $('#toggleseen').parent().addClass('thidden'); }
  1684.  
  1685.  
  1686. if ($cfg_sortsize || $cfg_sortzig) {
  1687. sort_compact();
  1688. crop_tiles();
  1689. }
  1690. else if ($cfg_sorttag) {
  1691. sort_tag();
  1692. crop_tiles_fuzzy();
  1693. }
  1694. else sort_default();
  1695.  
  1696. //fix links only when not already searching
  1697. if ($cfg_searchexpunged) {
  1698.  
  1699. //fix home link
  1700. var $front_link = $("p#nb a").first();
  1701. if ($front_link) {
  1702. var $new_href = $front_link.attr('href').replace(/(.*)\/$/, '$1/?page=0&f_sh=on');
  1703. $front_link.attr('href',$new_href);
  1704. }
  1705.  
  1706. //add expunge search to form
  1707. $("form").append('<input type="hidden" name="f_sh" value="on">');
  1708.  
  1709. if (!/Filter(&f_sh=on)?$/.test(document.location)) {
  1710. $('<script type="text/javascript">'+
  1711. 'getrowurl = "http://exhentai.org/?page={?page?}&f_sh=on";'+
  1712. 'function sp(a){document.location=getrowurl.replace("{?page?}",a);}'+
  1713. '</script>').appendTo("div#toppane");
  1714.  
  1715. $page_links = $("table.ptt td, table.ptb td");
  1716. $page_links.each(function (i,v) {
  1717. if (v.onclick) {
  1718. var page =v.onclick.toString().replace(/[\s\S]*sp\((\d*)[\s\S]*/,"$1");
  1719. if (!isNaN(page)) {
  1720. v.onclick = function(){sp(page);};
  1721. }
  1722. }
  1723.  
  1724. });
  1725.  
  1726. }
  1727.  
  1728.  
  1729. }
  1730.  
  1731.  
  1732. showPage();
  1733. }
  1734.  
  1735. try { applychanges(); }
  1736. catch (err) {
  1737. showPage();
  1738. alert(err);
  1739. }
  1740.  
  1741. } // i()
  1742.  
  1743.  
  1744. // *************************************************
  1745. // *************************************************
  1746. // *************************************************
  1747.  
  1748. function g() {
  1749.  
  1750. $(
  1751. '<style type="text/css">'+
  1752. 'div.fxs {width:195px; height:auto; left:-185px; top:100px; position:fixed; background-color:#4F535B; text-align:left; padding-left:10px; color:#DDDDDD;border: 2px solid #34353B;z-index: 10;}'+
  1753. 'div.fxs:hover {left:0px;}'+
  1754. '</style>').appendTo("head");
  1755.  
  1756. function mini_css() {
  1757.  
  1758.  
  1759. var $basex = $cfg_gal_width;
  1760. if ($cfg_thumbd) $basex = $cfg_thumbr_un * 228 + 25;
  1761. var $linkx = Math.floor($basex/2)-134;
  1762.  
  1763. $( '<style type="text/css">'+
  1764. ' body { font-family: \'メイリオ\',Meiryo,Arial,\'DejaVu Sans\',sans-serif; }'+
  1765. ' h1#gj {border:none;} '+
  1766. ' div.gm:not(#cdiv) { margin-top: -4px; width: 229px; min-width:0; float:right; height:0px; background:none; border:none; height:40px; } '+
  1767. ' div#gd1 { padding-left: 13px; background: none repeat scroll 0 0 #4F535B; border: 1px black; padding: 15px; line-height:0; height:auto; } ' +
  1768. ' div#gd2 { overflow:visible; white-space:nowrap; right:281px; width: auto; text-align:right; position:absolute; top:5px; background:none; } '+
  1769. ' div#gd3 { right:0; top:0; z-index:4; position:absolute; } '+
  1770. ' div#gd4 { position:relative; width:235px; border:none; padding-top:28px; padding-bottom:20px; margin:0;} ' +
  1771. ' div#gd5 { width:220px; }' +
  1772. ' div#gd5 table { display:none; }' +
  1773. ' div#gdn { text-align:left; position:absolute; right:20px; text-align:right; top:4px; margin:0; } ' +
  1774. ' div#gdn a { text-decoration:none; z-index:11;} ' +
  1775. ' div#gdd, div#gdd table { width:auto; } ' +
  1776. ' div#gdd { margin:0; position:absolute; left:-51px; top:-28px;} ' +
  1777. ' div#gdd td.gdt1 { display:none; } ' +
  1778. ' div#gdd td.gdt2 { padding-top:0; padding-bottom:0; } ' +
  1779. ' div#gdf { display:none; } ' +
  1780. ' div.gt { border:none !important; padding:0 2px; margin:0 0 1px 0; } ' +
  1781. ' div.gtl { border:none !important; padding:0 2px; margin:0 0 1px 0; opacity:0.7 !important;} ' +
  1782. ' div#taglist div { clear: left; float: left; text-align:left; white-space:normal; color:#b1b1b1;}' +
  1783. ' div#taglist div a { color: #E6A82D; font-family:consolas; font-size:12px; font-weight:700;}' +
  1784. ' div#taglist div a[id^="ta_group:"], div#taglist div a[id^="ta_artist:"] { color: #FF7E59; }' +
  1785. ' div#taglist div a[id^="ta_character:"] { color: #43CD34; }' +
  1786. ' div#taglist div a[id^="ta_parody:"] { color: #FF82FF; }' +
  1787. ' div#taglist tr td { float:left;clear:left; }' +
  1788. ' div#taglist tr td:first-child { padding:4px 0px 0px 4px !important;}' +
  1789. ' div#taglist { height:auto !important; width:auto;}' +
  1790. ' div#taglist a:hover { text-decoration: underline; } ' +
  1791. ' div#gdc, div#gd7 { display:none; } ' +
  1792. ' div#gleft { position:relative; height:0 !important; } ' +
  1793. ' div#gright { height:auto; width:auto; position:relative; z-index:3; background:none;} ' +
  1794. ' div#gmid { width:235px; height:auto; position:relative; right:-6px; top:-29px; bottom:-611px; padding-bottom:5px;} ' +
  1795. ' div#gd6, div#gd5 p.nopm, div#gd5 p.g1, div#gd5 p.g3, div#gdr { display:none; } '+
  1796. ' img.mr { float:left; clear:left; margin-top:6px; margin-right:2px; } ' +
  1797. ' div#taglist { width:220px; padding: 2px 0 2px 12px; } ' +
  1798. ' div#tagmenu_act a { float: left; line-height:20px;} ' +
  1799. ' div#tagmenu_act { position:absolute; right:0; width:231px; height:69px; background:#4F535B;} ' +
  1800.  
  1801. ' div#tagmenu_act img + a + img + a + img + a + img { display:none; } ' +
  1802. ' div#tagmenu_act img + a + img + a + img + a + img + a { display:none; } ' +
  1803.  
  1804. ' div#tagmenu_new { position:absolute; bottom:10px; left:47px; width:auto;} ' +
  1805. ' input#newtagfield { width:100px !important; } ' +
  1806. ' td.gdt2 { text-align:left; } ' +
  1807. ' p.g2 + p.g2 { display:none; } ' +
  1808. ' p.g2 img { display:none; } ' +
  1809. ' p.g2 a { padding: 278px 6px 1px 93px; color:rgba(241,241,241, 0); } ' +
  1810. ' p.g2 a:hover { background:rgba(0,0,0, 0.35); color:rgba(255,251,219, 1); } ' +
  1811. ' p.g2 { width: auto; } ' +
  1812. ' div#gdd table tr + tr + tr { display:none; } ' +
  1813. ' p#nb a + img + a { display:none; } ' +
  1814. ' p#nb a + img { display:none; } ' +
  1815. ' p#nb { position:relative; height:0; top: 56px; right:'+ $linkx +'px; display:inline; color:#b1b1b1 !important; } ' +
  1816. ' p#nb a { color:#b1b1b1; } ' +
  1817. ' p#nb img { display:none; } ' +
  1818. ' img.ygm { display:none; } ' +
  1819. ' p#nb a { text-decoration:none; } ' +
  1820. ' p#nb a:hover { text-decoration:underline; } ' +
  1821. ' div#taglist {height:auto;} ' +
  1822. ' p.g2 { float:left; padding-top:0 !important; }' +
  1823. ' div#gright { top:-36px; right:-9px; }' +
  1824. ' div#tagmenu_new .stdinput { border: 1px dashed #000000; background: none repeat scroll 0 0 #4F535B; } ' +
  1825. ' body { overflow-x:hidden; }'+
  1826. ' p.ip { display:none;}'+
  1827. //' p.ip { position:relative; top:-20px; padding:0; margin:-20px; color: #b8b8b8;}'+
  1828. '</style>').appendTo("head");
  1829.  
  1830. }
  1831.  
  1832.  
  1833. var $cfg_fixt;
  1834.  
  1835. function getSettings() {
  1836. $cfg_fixt = GM_getValue("ehp_thumb", true);
  1837. $cfg_grey = GM_getValue("ehp_grey", true);
  1838. $cfg_mini = GM_getValue("ehp_mini", true);
  1839. $cfg_linktags = GM_getValue("ehp_linktags", true);
  1840. $cfg_autodl = GM_getValue("ehp_autodl", false);
  1841.  
  1842. $cfg_thumbd = GM_getValue("ehp_thumbd", false);
  1843. $cfg_thumbh = GM_getValue("ehp_thumbh", true);
  1844. $cfg_thumbr = GM_getValue("ehp_thumbr", false);
  1845. $cfg_thumbv = GM_getValue("ehp_thumbv", false);
  1846.  
  1847.  
  1848. $cfg_thumbh_px = parseInt(GM_getValue("ehp_thumbh_px", "280").replace(/[^0-9-]/,""),10);
  1849. $cfg_thumbr_un = parseInt(GM_getValue("ehp_thumbr_un", "5").replace(/[^0-9-]/,""),10);
  1850. $cfg_thumbr_n = parseInt(GM_getValue("ehp_thumbr_n", "5").replace(/[^0-9-]/,""),10);
  1851. $cfg_gal_width = parseInt(GM_getValue("ehp_gal_width", "1260").replace(/[^0-9-]/,""),10);
  1852.  
  1853. $cfg_grey = GM_getValue("ehp_grey", true);
  1854. }
  1855. getSettings();
  1856.  
  1857.  
  1858. $('div#gdt').before('<div class="fxs"><br>'+
  1859.  
  1860. '<b style="margin-left:6px;font-size:110%;">Thumb Scaling</b><br>'+
  1861. '<label><input id="thumbd" type="radio" name="order" '+($cfg_thumbd?'checked':'')+'>Unscaled </label>'+
  1862. '<input class="stdinput" id="thumbr_un" style="width:15px;margin:0;padding:1px;border:0;" type="textbox" value="'+$cfg_thumbr_un+'">(per row)<hr style="margin-left:4px;width:160px;border:none;border-top:1px dashed grey;">'+
  1863. '<label style="padding-left:5px; line-height:18px;"> Scale Gallery Width <input class="stdinput" id="gal_width" style="width:30px;margin:0;padding:1px;border:0;" type="textbox" value="'+$cfg_gal_width+'"></label> (px)<br>'+
  1864. '<label><input id="thumbh" type="radio" name="order" '+($cfg_thumbh?'checked':'')+'>Scale to height ~</label>'+
  1865. '<input class="stdinput" id="thumbh_px" style="width:30px;margin:0;padding:1px;border:0;" type="textbox" value="'+$cfg_thumbh_px+'">(px)<br>'+
  1866. '<label><input id="thumbr" type="radio" name="order" '+($cfg_thumbr?'checked':'')+'>Scale to count </label>'+
  1867. '<input class="stdinput" id="thumbr_n" style="width:15px;margin:0;padding:1px;border:0;" type="textbox" value="'+$cfg_thumbr_n+'">(per row)<br><br>'+
  1868.  
  1869.  
  1870. '<label><input id="mini" type="checkbox" '+($cfg_mini?'checked':'') +'>Minimal UI</label><br>'+
  1871. '<label><input id="linktags" type="checkbox" '+($cfg_linktags?'checked':'') +'>Direct Link Tags</label><br>'+
  1872. '<label><input id="grey" type="checkbox" '+($cfg_grey?'checked':'') +'>Grey e-hentai</label><br><br>'+
  1873. '<label><input id="autodl" type="checkbox" '+($cfg_autodl?'checked':'') +'>Auto Start Archive DL</label><br><div style="padding-right:22px;">Automatically accepts/begins archive download when you click to get an archive. Archives take GP so be careful.</div><br>'+
  1874.  
  1875. '<br><input id="applybtn" type="button" value="Apply" /><br>&nbsp;');
  1876.  
  1877.  
  1878. $('div.fxs input[type="checkbox"]').click(function (e) {
  1879. GM_setValue("ehp_"+$(this).attr("id"), $(this).prop("checked")?true:false);
  1880. });
  1881.  
  1882. $('div.fxs input[type="radio"]').click(function (e) {
  1883. GM_setValue("ehp_thumbd", false); //hack
  1884. GM_setValue("ehp_thumbh", false);
  1885. GM_setValue("ehp_thumbr", false);
  1886. GM_setValue("ehp_thumbv", false);
  1887.  
  1888. GM_setValue("ehp_"+$(this).attr("id"), $(this).prop("checked")?true:false);
  1889. });
  1890.  
  1891. $('div.fxs input[type="textbox"], div.fxs textarea').keyup(function (e) {
  1892. GM_setValue("ehp_"+$(this).attr("id"), $(this).val());
  1893. });
  1894.  
  1895.  
  1896. $('div.fxs input#applybtn').click(function (e) {
  1897. try { $("head").html($head_html); }
  1898. catch(err) { }
  1899.  
  1900. try { $('div#gdt').html($body_html); }
  1901. catch(err) { }
  1902.  
  1903. getSettings();
  1904. if ($cfg_grey) { grey_css(); }
  1905. if ($cfg_mini) { mini_css(); }
  1906. applychanges();
  1907. });
  1908.  
  1909. //////////////////////////////////////////
  1910. //
  1911. //
  1912.  
  1913.  
  1914.  
  1915. //
  1916. //
  1917. //
  1918. // save page state for soft reload
  1919. $head_html = $("head").html();
  1920. $body_html = $('div#gdt').html();
  1921.  
  1922. if ($cfg_grey) { grey_css(); }
  1923. if ($cfg_mini) { mini_css(); }
  1924.  
  1925. function measure_thumbs() {
  1926. $('.gdtl').each( function(i) {
  1927. $src = $(this).find('img').attr("src");
  1928. $con = $src.match( /^[^-]*-[^-]*-(\d+)-(\d+)-.{3}_l\.jpg$/);
  1929. $w = $con[1];
  1930. $h = $con[2];
  1931.  
  1932. $h = $h * 200 / $w;
  1933. $w = 200;
  1934. if ($h > 300) {
  1935. $w = $w * 300 / $h;
  1936. $h = 300;
  1937. }
  1938. $wx[i] = $w;//Math.round($w);
  1939. $hx[i] = $h;//Math.round($h);
  1940. $img[i] = $(this).find('img');
  1941.  
  1942. $total += $h;
  1943. $count++;
  1944. });
  1945. }
  1946.  
  1947. function default_css() {
  1948.  
  1949. //default tiles are 320px
  1950. //$tx = Math.floor(($cfg_gal_width - 25) / 228) * 228 + 25; //25px left padding
  1951. $tx = $cfg_thumbr_un * 228 + 25;
  1952. $('<style type="text/css">'+
  1953. 'div#gdt { max-width:'+$tx+'px; width:'+$tx+'px; min-width:'+$tx+'px;} '+
  1954. 'div#gdt { padding: 15px 0 15px 25px !important; } '+
  1955. 'div.gdtl { padding-bottom:20px; padding-left:8px;} '+
  1956. 'div.gdtl img { border-radius: 4px 4px 4px 4px; } '+
  1957. 'div.gdtl { text-align:left } ' +
  1958. 'div.gdtl a { color:#C2A8A4; } ' +
  1959. 'div.gdtl * { display:block; margin-top:1px;} ' +
  1960. 'div.gdtl { width: 220px } ' +
  1961. '</style>').appendTo("head");
  1962. }
  1963.  
  1964.  
  1965. function target_css() {
  1966. $('<style type="text/css">'+
  1967. 'div#gdt { max-width:'+$cfg_gal_width+'px; width:'+$cfg_gal_width+'px; min-width:'+$cfg_gal_width+'px;} '+
  1968. 'div#gdt { padding: 15px 25px !important; } '+
  1969. 'div.gdtl { padding-bottom:20px; padding-left:8px;} '+
  1970. 'div.gdtl img { border-radius: 4px 4px 4px 4px; } '+
  1971. 'div.gdtl { text-align:right } ' +
  1972. 'div.gdtl a { color:#C2A8A4; } ' +
  1973. 'div.gdtl * { display:block; margin-top:1px;} ' +
  1974. '</style>').appendTo("head");
  1975. }
  1976.  
  1977.  
  1978. function fixup_thumbs_height() {
  1979.  
  1980. $wx = [];
  1981. $hx = [];
  1982. $img = [];
  1983.  
  1984. $count = 0;
  1985. $total = 0;
  1986. measure_thumbs();
  1987.  
  1988. $padding = 8;
  1989.  
  1990. $sf=1;
  1991. $k=0;
  1992. $lastmaxh=$cfg_thumbh_px;
  1993. //todo reject extreme aspects
  1994. for ($i=0; $i<$img.length; $i++) {
  1995. //scale and add images until width passes limit
  1996. $k = $i;
  1997. $last = 0;
  1998. do {
  1999. $k++;
  2000. $targeth = $cfg_thumbh_px; //clamp scale to target
  2001.  
  2002. //calc width based on target
  2003. $last = $total;
  2004. $total=0;
  2005. for ($j=$i; $j<=$k; $j++) {
  2006. $w = $wx[$j] * $targeth / $hx[$j];
  2007. $total += $w + $padding;
  2008.  
  2009. if ($j == $img.length ) { //past end case, fix totals (hack)
  2010. $w = $wx[$j] * $targeth / $hx[$j];
  2011. $total += $w + $padding;
  2012. }
  2013.  
  2014. }
  2015. } while ($total < ($cfg_gal_width - $padding) && $k<($img.length-1));
  2016.  
  2017. //remove last image if it's farther from target height than with
  2018. if ((($cfg_gal_width - $padding) - $last) < ($total - ($cfg_gal_width - $padding))) $k--;
  2019. if ($k>=($img.length-1)) $k = $img.length-1; //keep k in bounds at end of list
  2020.  
  2021.  
  2022. $maxh=0; //find maxh
  2023. for ($j=$i; $j<=$k; $j++) { $maxh = Math.max($maxh, $hx[$j]); }
  2024.  
  2025. $notlast = ($k+1) < $img.length;
  2026. if ($notlast || $total > ($cfg_gal_width - $padding)) { //normal row case (and last row too big case)
  2027.  
  2028. $total=0;
  2029. for ($j=$i; $j<=$k; $j++) {
  2030. $w = $wx[$j] * $maxh / $hx[$j];
  2031. $total += $w + $padding;
  2032. }
  2033.  
  2034. $n = $k-$i+1;
  2035. $padt = $padding * $n;
  2036. $sf = ($cfg_gal_width - $padding - $padt) / ($total - $padt); //solve to $cfg_gal_width width
  2037. }
  2038. else $maxh = $lastmaxh; //ensure same ratio aspect as previous row
  2039.  
  2040. $lastmaxh = $maxh;
  2041. //setup image dimensions
  2042. for ($j=$i; $j<=$k; $j++) {
  2043. $wx[$j] = Math.floor($sf * $wx[$j] * $maxh / $hx[$j]);
  2044. $hx[$j] = Math.floor($sf * $maxh);
  2045. }
  2046.  
  2047.  
  2048. if ($i > $k) break; //sanity check, probably not needed
  2049. $i=$k;
  2050. }
  2051.  
  2052.  
  2053. //apply fit row heights
  2054. $.each($img, function(i,v) {
  2055. v.attr('width', $wx[i]);
  2056. v.attr('height', $hx[i]);
  2057.  
  2058. v.parent().parent().css('width', $wx[i] +'px');
  2059. v.parent().parent().css('height', $hx[i] +'px');
  2060. });
  2061. }
  2062.  
  2063.  
  2064. function fixup_thumbs_count() {
  2065.  
  2066. $wx = [];
  2067. $hx = [];
  2068. $th = [];
  2069. $img = [];
  2070.  
  2071. $count = 0;
  2072. $total = 0;
  2073. measure_thumbs();
  2074.  
  2075. $padding = 8;
  2076.  
  2077. $sf=1;
  2078. $sfx=1;
  2079. $k=0;
  2080. for ($i=0; $i<$img.length; $i++) {
  2081. //pull images until width passes limit
  2082. $k=Math.min($i-1+$cfg_thumbr_n, $img.length-1); // n per row
  2083.  
  2084. $islast = ($k+1) >= $img.length;
  2085.  
  2086. $n = $k-$i+1;
  2087. $padt = $padding * $n;
  2088. $maxh=0; //find maxh
  2089. for ($j=$i; $j<=$k; $j++) { $maxh = Math.max($maxh, $hx[$j]); } //$maxh = Math.max.apply(Math, $hx);
  2090.  
  2091.  
  2092. $total=0;
  2093. for ($j=$i; $j<=$k; $j++) {
  2094. $w = $wx[$j] * $maxh / $hx[$j];
  2095. $total += $w + $padding;
  2096. }
  2097.  
  2098. //solve to $cfg_gal_width width unless last row with < num items
  2099. $sfx = ($cfg_gal_width - $padding - $padt) / ($total - $padt);
  2100. if ($islast && $n < $cfg_thumbr_n) {
  2101. $sf = ($cfg_gal_width - $padding - $padt) / ($total * $cfg_thumbr_n /$n - $padt);
  2102. if ($sfx < $sf) $sf = $sfx; //reduce if needed
  2103.  
  2104. }
  2105. else $sf = $sfx;
  2106.  
  2107.  
  2108. //setup image dimensions
  2109. for ($j=$i; $j<=$k; $j++) {
  2110. $wx[$j] = Math.floor($sf * $wx[$j] * $maxh / $hx[$j]);
  2111. $hx[$j] = Math.floor($sf * $maxh);
  2112. }
  2113.  
  2114. //advance i
  2115. $i=$k;
  2116. }
  2117.  
  2118.  
  2119. //apply fit row heights
  2120. $.each($img, function(i,v) {
  2121. v.attr('width', $wx[i]);
  2122. v.attr('height', $hx[i]);
  2123.  
  2124. v.parent().parent().css('width', $wx[i] +'px');
  2125. v.parent().parent().css('height', $hx[i] +'px');
  2126. });
  2127.  
  2128. }
  2129.  
  2130.  
  2131. //remove click hanler for tags, reverts to direct link for search
  2132. function directlink_tags() {
  2133. $(".gt a").each(function() {
  2134. $(this).prop("onclick", null);
  2135. });
  2136. $(".gtl a").each(function() {
  2137. $(this).prop("onclick", null);
  2138. });
  2139. }
  2140.  
  2141. function applychanges() {
  2142.  
  2143. if($cfg_thumbh || $cfg_thumbr) target_css();
  2144. else default_css();
  2145.  
  2146. if ($cfg_thumbh) fixup_thumbs_height(); //try for x height rows
  2147. else if ($cfg_thumbr) fixup_thumbs_count(); //try for n images per row
  2148.  
  2149. if($cfg_linktags) directlink_tags();
  2150. showPage();
  2151. }
  2152. try { applychanges(); }
  2153. catch (err) {
  2154. showPage();
  2155. alert(err);
  2156. }
  2157. }// g()
  2158.  
  2159. $cfg_autodl = GM_getValue("ehp_autodl", false);
  2160. $cfg_fadevisited = GM_getValue("ehp_fadevisited", false);
  2161. $cfg_hidevisited = GM_getValue("ehp_hidevisited", false);
  2162.  
  2163. var t0;
  2164. function tstart() {
  2165. t0 = performance.now();
  2166. }
  2167.  
  2168. function tcheck(desc) {
  2169. var t1 = performance.now();
  2170. console.log(desc + ": " + (t1 - t0).toFixed(0) + " ms");
  2171. t0 = t1;
  2172. }
  2173. tstart();
  2174.  
  2175. //for subloop tallying of perf
  2176. var pdata = {}
  2177. function tstartx(slice) {
  2178. pdata[slice+"_t0"] = performance.now();
  2179. }
  2180. function tendx(slice) {
  2181. pdata[slice+"_t1"] = performance.now();
  2182. if (typeof pdata[slice+"_tt"] === "undefined") pdata[slice+"_tt"] = 0;
  2183. pdata[slice+"_tt"] += pdata[slice+"_t1"] - pdata[slice+"_t0"];
  2184. }
  2185. function toutx(slice) {
  2186. if (typeof pdata[slice+"_tt"] !== "undefined")
  2187. console.log(slice + ": " + pdata[slice+"_tt"].toFixed(0) + " ms");
  2188. else
  2189. console.log(slice + ": no samples");
  2190. }
  2191.  
  2192.  
  2193. if (document.URL.match(/^http:\/\/g.e-hentai\.org\/[gs]\/.*$/)) { //gallery or image
  2194. if ($("div.d p:first-child").text() === "This gallery has been removed, and is unavailable.") {
  2195. var loc = window.location.toString();
  2196. var ex = loc.replace(/:\/\/g.e-/i,"://ex");
  2197. if (ex !== loc) window.location.replace(ex);
  2198. }
  2199. }
  2200. if (document.URL.match(/^http:\/\/(g\.e-|e[^-])hentai\.org\/g\/.*$/)) { //gallery case
  2201. //record visited galleries to local DB
  2202. var gal_idx = document.URL.match(/^http:\/\/(?:g\.e-|e[^-])hentai\.org\/g\/(\d*)\/.*$/);
  2203. if (!isNaN(gal_idx[1])) {
  2204. var gal_id = parseInt(gal_idx[1],10);
  2205. //old visited code
  2206. //$galdb = safeEval(GM_getValue("eh_galdb", "({});")); //load visited gal db
  2207. //alert(JSON.stringify($galdb).length);
  2208. //window.prompt("Copy to clipboard: Ctrl+C, Enter", safeUneval($galdb));
  2209. visitGal(gal_id);
  2210. //old visited code
  2211. //if (!$galdb[gal_id]) { //update visited db if not already saved
  2212. // $galdb[gal_id] = true;
  2213. // GM_setValue("eh_galdb", safeUneval($galdb));
  2214. //}
  2215. }
  2216.  
  2217.  
  2218. g();
  2219. }
  2220. else if (document.URL.match(/^http:\/\/(g\.e-|e[^-])hentai\.org\/archiver.php\?.*$/)) { //archive downloader step1
  2221. showPage();
  2222. if($cfg_autodl) {
  2223. $(function() {
  2224. $button = $('input.stdbtn');
  2225. if ($button.attr('value') == 'Download Archive')
  2226. $button[0].click();
  2227. //$button.trigger('click');
  2228. });
  2229. }
  2230. else return;
  2231. }
  2232. else if (document.URL.match(/^http:\/\/95\.211\.(199|209)\.\d{1,3}\/archive\/.*$/) || document.URL.match(/^http:\/\/37\.48\.81\.\d{1,3}\/archive\/.*$/)) { //archive downloader step2
  2233. showPage();
  2234. if($cfg_autodl) {
  2235. $(function() {
  2236. $link = $('div#db a');
  2237. if ($link.text() == 'Click Here To Start Downloading') {
  2238. $archive = 'http://' + window.location.hostname + $link.attr('href');
  2239. window.location.href = $archive;
  2240. setTimeout(function(){ window.close(); },10000);
  2241. }
  2242. });
  2243. }
  2244. else return;
  2245. }
  2246. else if (document.URL.match(/^http:\/\/(g\.e-|e[^-])hentai\.org\/(?!s).*$/) && self == top) { //search / index case, exclude iframe
  2247. i();
  2248. }
  2249. else {
  2250. showPage();
  2251. }
  2252. tcheck('ehp total');
  2253. } // ehp();
  2254. addEventListener('DOMContentLoaded', ehp, false);