E(x)-Hentai CompactSearch

Compacts the search into the topbar, saving vertical space. Supports E-Hentai & EXHentai.

2015-10-01 일자. 최신 버전을 확인하세요.

  1. // ==UserScript==
  2. // @name E(x)-Hentai CompactSearch
  3. // @namespace https://github.com/DakuTree/userscripts
  4. // @author Daku (admin@codeanimu.net)
  5. // @description Compacts the search into the topbar, saving vertical space. Supports E-Hentai & EXHentai.
  6. // @homepageURL https://github.com/DakuTree/userscripts
  7. // @supportURL https://github.com/DakuTree/userscripts/issues
  8. // @include /^http[s]?:\/\/(g\.e-|ex)hentai\.org\/.*$/
  9. // @grant GM_addStyle
  10. // @updated 2015-10-01
  11. // @version 2.0.5
  12. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
  13. // ==/UserScript==
  14.  
  15. //TODO: Make new topbar appear alongside DOM (instead of loading a second or so after).
  16. //Use Stylish
  17. GM_addStyle("#toppane, #nb {display: none !important;}"); //Hide elements before load
  18. var domain = (location.host.match(/([^.]+)\.\w{2,3}(?:\.\w{2})?$/) || [])[1].replace('-', '');
  19.  
  20. function addJQuery(callback){
  21. var script = document.createElement("script");
  22. script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js");
  23. script.addEventListener('load', function() {
  24. var script = document.createElement("script");
  25. script.textContent = "(" + callback.toString() + ")();";
  26. document.body.appendChild(script);
  27. }, false);
  28. document.body.appendChild(script);
  29. }
  30.  
  31. function main(){
  32. jQuery(document).ready(function($){
  33. //Get/set default settings
  34. //This seems to be stored in the uconfig cookie, but it seems to be somewhat encrypted.
  35. var unsafeWindow = this['unsafeWindow'] || window;
  36. var v = new Object();
  37. if($('form input[id*="f_"], #searchbox input[name="f_search"]').length > 0){
  38. $('form input[id*="f_"], input[name="f_search"]').each(function(){ v[$(this).attr('name')] = $(this).attr('value')});
  39. console.log($('html'));
  40. unsafeWindow.localStorage.setItem('s', JSON.stringify(v));
  41. }else{
  42. v = JSON.parse(unsafeWindow.localStorage.getItem('s'));
  43. v['f_search'] = "Search Keywords"; //Show default text on non-search pages.
  44. }
  45.  
  46. var colors = {ehentai: ['#E3E0D1', '#EDEBDF', '#5C0D11', '#9B4E03'], exhentai: ['#34353b', '#4f535b', '#f1f1f1', '#43464e']};
  47.  
  48. var color1 = colors[domain][0],
  49. color2 = colors[domain][1],
  50. color3 = colors[domain][2];
  51. color4 = colors[domain][3];
  52.  
  53. $('#toppane').remove();
  54. $('<style/>').attr('rel', 'stylesheet').attr('type', 'text/css') //{
  55. .text(".ido {padding-top: 0 !important;}\
  56. #navwrap {width: 90%; min-width: 975px; height: 24px; margin: auto; z-index: 99; position: relative; background-color: "+color2+"; border: 1px solid #000000; margin-bottom: 10px;}\
  57. .navbar {height: 24px; padding: 0; margin: 0; position: absolute; width: 100%;}\
  58. .navbar li {height: 24px; width: 150px; float: left; text-align: center; list-style: none; font: normal bold 12px/1.2em Arial, Verdana, Helvetica; padding: 0; margin: 0; background-color: "+color2+";}\
  59. .navbar li a {padding: 5px 0; text-decoration: none; color: "+color3+"; display: block; border-right: 1px solid "+color1+";}\
  60. .navbar li a:hover {background-color: "+color1+";}\
  61. .navbar li ul {display: none; height: auto; margin: 0; margin-left: -1px; padding: 0; border-top: 1px solid "+color1+"; border-left: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000;}\
  62. .navbar li:hover ul {display: block;}\
  63. .navbar li ul {background-color: "+color2+";}\
  64. .navbar li:last-child ul {margin-top: 2px; margin-right: -1px;}\
  65. .navbar li ul a {border-right: 0;}\
  66. .navbar li ul a:not(:first-child) {border-top: 1px solid "+color1+"}\
  67. .navbar li ul a:hover {background-color: "+color1+";}\
  68. .navbar li form {margin-top: 0;}\
  69. .navbar li form input {margin-right: 1px;}\
  70. .navbar li form ul {font-weight: normal;}\
  71. .navbar .nopm a {text-decoration: underline; font-size: 8pt; display: inline; border: 0 !important;}\
  72. .navbar .nopm a:hover {background-color: transparent;}\
  73. .navbar .stdinput:enabled:hover, .navbar .stdinput:enabled:focus {color: "+color3+"; background: "+color4+";}\
  74. .navbar .stdinput, .stdbtn {margin: auto;}\
  75. .navbar .stdbtn {height: 19px !important; padding: 1px 6px; margin: 3px 1px 0px 1px; background-color: "+color1+"; color: "+color3+";}\
  76. .navbar .stdbtn:hover {border: 2px outset "+color3+";}\
  77. .navbar .stdbtn:enabled:hover {color: "+color3+"; background: "+color4+"; border: 2px outset "+color3+";}\
  78. .navbar input.stdinput {width: 350px; background-color: "+color1+"; color: "+color3+"; padding-bottom: 1px; border: 1px solid "+color1+";}\
  79. .navbar table.itc {border-spacing: 1px; padding-top: 1px; padding-bottom: 1px;}\
  80. .navbar table.itc td {padding: 0;}\
  81. .navbar #fill {width: calc(100% - 450px - 507px - 16px);}\
  82. .navbar table.itss {margin: 0; width: calc(100% - 28px); font-size:11px; margin-left: 28px;}\
  83. .navbar table.itss td.ic2 {width: 45%}\
  84. .navbar #fsdiv {font-size: 11px; font-weight: normal;}\
  85. ").appendTo('head'); //}
  86.  
  87. var nav2 = $('<div/>', {id: 'navwrap'});
  88. var nav = $('<ul/>', {class: 'navbar'}).appendTo(nav2);
  89. $('<li/>').append( //{
  90. $('<a/>', {text: "Front Page", href: location.origin})).append(
  91. $('<ul/>').append(
  92. $('<a/>', {text: "News", href: 'http://e-hentai.org/'})).append(
  93. $('<a/>', {text: "Forums", href: 'http://forums.e-hentai.org/'})).append(
  94. $('<a/>', {text: "Wiki", href: 'http://ehwiki.org/wiki/Category:E-Hentai_Galleries'})).append(
  95. $('<a/>', {text: "Torrents", href: location.origin+'/torrents.php'})).append(
  96. $('<a/>', {text: "Bounties", href: 'http://g.e-hentai.org/bounty.php'})).append(
  97. $('<a/>', {text: "Toplists", href: 'http://g.e-hentai.org/toplist.php'}))).appendTo(nav);
  98. $('<li/>').append(
  99. $('<a/>', {text: "My Home", href: 'http://g.e-hentai.org/home.php'})).append(
  100. $('<ul/>').append(
  101. $('<a/>', {text: "Favorites", href: location.origin+'/favorites.php'})).append(
  102. $('<a/>', {text: "Maintain Galleries", href: 'http://ul.'+location.hostname.replace(/^g\./, '')+'/manage.php'})).append(
  103. $('<a/>', {text: "Upload Gallery", href: 'http://ul.'+location.hostname.replace(/^g\./, '')+'/manage.php?act=new'})).append(
  104. $('<a/>', {text: "Options", href: location.origin+'/uconfig.php'}))).appendTo(nav);
  105. $('<li/>').append(
  106. $('<a/>', {text: "HentaiVerse", href: 'http://hentaiverse.org/', onclick: "popUp('http://hentaiverse.org/',1250,720); return false"})).appendTo(nav);
  107. $('<li/>', {id: 'fill', style: "border-right: 1px solid "+color1+";"}).appendTo(nav);
  108. $('<li/>', {style: "border-right: 1px solid "+color1+"; width: 15px !important; min-width: 15px; max-width: 15px;"}).append(
  109. $('<a/>', {href: '#', text: '#', id: 'addenglish'})).appendTo(nav);
  110. $('<li/>', {style: "width: 506px !important; min-width: 506px; max-width: 506px;"}).append(
  111. $('<form/>', {action: "http://"+location.hostname, method: "GET"}).append(
  112. $('<div/>').append(
  113. $('<input/>', {type: "text", name: "f_search", value: v["f_search"], class: "stdinput", onfocus: "if(this.value=='Search Keywords') this.value = '';", size: "50", maxlength: "200"})).append(
  114. $('<input/>', {type: "submit", name: "f_apply", value: "Apply Filter", class: "stdbtn"})).append(
  115. $('<input/>', {type: "submit", name: "f_clear", value: "Clear Filter", class: "stdbtn", onclick: "top.location.href='http://g.e-hentai.org/'; return false"}))).append(
  116. $('<ul/>').append(
  117. $('<table/>', {class: "itc"}).append(
  118. $('<tr/>').append(
  119. $('<td/>').append(
  120. $('<input/>', {type: "hidden", name: "f_doujinshi", value: v["f_doujinshi"], id: "f_doujinshi"})).append(
  121. $('<img/>', {id: "f_doujinshi_img", src: "http://ehgt.org/g/c/doujinshi"+ (v["f_doujinshi"] == 1 ? "" : "_d") + ".png", class: "ic", alt: "doujinshi", style: "cursor:pointer"}))).append(
  122. $('<td/>').append(
  123. $('<input/>', {type: "hidden", name: "f_manga", value: v["f_manga"], id: "f_manga"})).append(
  124. $('<img/>', {id: "f_manga_img", src: "http://ehgt.org/g/c/manga"+ (v["f_manga"] == 1 ? "" : "_d") + ".png", class: "ic", alt: "mangat", style: "cursor:pointer"}))).append(
  125. $('<td/>').append(
  126. $('<input/>', {type: "hidden", name: "f_artistcg", value: v["f_artistcg"], id: "f_artistcg"})).append(
  127. $('<img/>', {id: "f_artistcg_img", src: "http://ehgt.org/g/c/artistcg"+ (v["f_artistcg"] == 1 ? "" : "_d") + ".png", class: "ic", alt: "artistcg", style: "cursor:pointer"}))).append(
  128. $('<td/>').append(
  129. $('<input/>', {type: "hidden", name: "f_gamecg", value: v["f_gamecg"], id: "f_gamecg"})).append(
  130. $('<img/>', {id: "f_gamecg_img", src: "http://ehgt.org/g/c/gamecg"+ (v["f_gamecg"] == 1 ? "" : "_d") + ".png", class: "ic", alt: "gamecg", style: "cursor:pointer"}))).append(
  131. $('<td/>').append(
  132. $('<input/>', {type: "hidden", name: "f_western", value: v["f_western"], id: "f_western"})).append(
  133. $('<img/>', {id: "f_western_img", src: "http://ehgt.org/g/c/western"+ (v["f_western"] == 1 ? "" : "_d") + ".png", class: "ic", alt: "western", style: "cursor:pointer"})))).append(
  134. $('<tr/>').append(
  135. $('<td/>').append(
  136. $('<input/>', {type: "hidden", name: "f_non-h", value: v["f_non-h"], id: "f_non-h"})).append(
  137. $('<img/>', {id: "f_non-h_img", src: "http://ehgt.org/g/c/non-h"+ (v["f_non-h"] == 1 ? "" : "_d") + ".png", class: "ic", alt: "non-h", style: "cursor:pointer"}))).append(
  138. $('<td/>').append(
  139. $('<input/>', {type: "hidden", name: "f_imageset", value: v["f_imageset"], id: "f_imageset"})).append(
  140. $('<img/>', {id: "f_imageset_img", src: "http://ehgt.org/g/c/imageset"+ (v["f_imageset"] == 1 ? "" : "_d") + ".png", class: "ic", alt: "imageset", style: "cursor:pointer"}))).append(
  141. $('<td/>').append(
  142. $('<input/>', {type: "hidden", name: "f_cosplay", value: v["f_cosplay"], id: "f_cosplay"})).append(
  143. $('<img/>', {id: "f_cosplay_img", src: "http://ehgt.org/g/c/cosplay"+ (v["f_cosplay"] == 1 ? "" : "_d") + ".png", class: "ic", alt: "cosplay", style: "cursor:pointer",}))).append(
  144. $('<td/>').append(
  145. $('<input/>', {type: "hidden", name: "f_asianporn", value: v["f_asianporn"], id: "f_asianporn"})).append(
  146. $('<img/>', {id: "f_asianporn_img", src: "http://ehgt.org/g/c/asianporn"+ (v["f_doujinshi"] == 1 ? "" : "_d") + ".png", class: "ic", alt: "asianporn", style: "cursor:pointer"}))).append(
  147. $('<td/>').append(
  148. $('<input/>', {type: "hidden", name: "f_misc", value: v["f_misc"], id: "f_misc"})).append(
  149. $('<img/>', {id: "f_misc_img", src: "http://ehgt.org/g/c/misc"+ (v["f_misc"] == 1 ? "" : "_d") + ".png", class: "ic", alt: "misc", style: "cursor:pointer"}))))).append(
  150. $('<div/>').append(
  151. $('<p/>', {class: "nopm", style: "margin-top:2px;"}).append(
  152. $('<a/>', {href: "#", rel: "nofollow", id: "show_ao", text: "Show Advanced Options", style: "margin-right:5px;"})).append(
  153. $('<a/>', {href: "#", rel: "nofollow", id: "show_fs", text: "Show File Search", style: "margin-left:5px;", disabled: 'disabled'}))).append(
  154. $('<div/>', {id: 'advdiv', style: 'display: none;'}))))).append(
  155. $('<ul/>', {style: 'margin-top: -1px;'}).append(
  156. $('<div/>', {id: 'fsdiv', style: 'display: none;'}))
  157. ).appendTo(nav); //}
  158.  
  159. //$('#nb').replaceWith(nav2);
  160. $('body').prepend(nav2);
  161.  
  162. $('#navwrap').on('click', '.nopm > a', function(e){
  163. var id = ($(this).attr('id') == 'show_ao' ? 'advdiv' : 'fsdiv');
  164.  
  165. if($('#'+id).css('display') == 'none'){
  166. if(id == 'advdiv'){
  167. $('#'+id).append(
  168. $('<input/>', {type: 'hidden', id: 'advsearch', name: 'advsearch', value: '1'})).append(
  169. $('<table/>', {class: 'itss'}).append(
  170. $('<tbody/>').append(
  171. $('<tr/>').append(
  172. $('<td/>', {class: 'ic4'}).append(
  173. $('<input/>', {id: 'adv11', type: 'checkbox', name: 'f_sname', checked: 'checked'})).append(
  174. $('<label/>', {for: 'adv11', text: 'Search Gallery Name'}))).append(
  175. $('<td/>', {class: 'ic4'}).append(
  176. $('<input/>', {id: 'adv12', type: 'checkbox', name: 'f_stags', checked: 'checked'})).append(
  177. $('<label/>', {for: 'adv12', text: 'Search Gallery Tags'}))).append(
  178. $('<td/>', {class: 'ic2'}).append(
  179. $('<input/>', {id: 'adv13', type: 'checkbox', name: 'f_sdesc', colspan: '2'})).append(
  180. $('<label/>', {for: 'adv13', text: 'Search Gallery Description'})))).append(
  181. $('<tr/>').append(
  182. $('<td/>', {class: 'ic2', colspan: '2'}).append(
  183. $('<input/>', {id: 'adv15', type: 'checkbox', name: 'f_storr'})).append(
  184. $('<label/>', {for: 'adv15', text: 'Search Torrent Filenames'}))).append(
  185. $('<td/>', {class: 'ic2', colspan: '2'}).append(
  186. $('<input/>', {id: 'adv16', type: 'checkbox', name: 'f_sto'})).append(
  187. $('<label/>', {for: 'adv16', text: 'Only Show Galleries With Torrents'})))).append(
  188. $('<tr/>').append(
  189. $('<td/>', {class: 'ic2', colspan: '2'}).append(
  190. $('<input/>', {id: 'adv21', type: 'checkbox', name: 'f_sdt1'})).append(
  191. $('<label/>', {for: 'adv21', text: 'Search Low-Power Tags'}))).append(
  192. $('<td/>', {class: 'ic2', colspan: '2'}).append(
  193. $('<input/>', {id: 'adv22', type: 'checkbox', name: 'f_sdt2'})).append(
  194. $('<label/>', {for: 'adv22', text: 'Search Downvoted Tags'})))).append(
  195. $('<tr/>').append(
  196. $('<td/>', {class: 'ic2', colspan: '2'}).append(
  197. $('<input/>', {id: 'adv31', type: 'checkbox', name: 'f_sh'})).append(
  198. $('<label/>', {for: 'adv31', text: 'Show Expunged Galleries'}))).append(
  199. $('<td/>', {class: 'ic2', colspan: '2'}).append(
  200. $('<input/>', {id: 'adv32', type: 'checkbox', name: 'f_sr'})).append(
  201. $('<label/>', {for: 'adv32', text: 'Minimum Rating: '})).append(
  202. $('<select/>', {id: 'adv42', class: 'stdinput imr', name: 'f_srdd'}).append(
  203. $('<option/>', {value: '2', text: '2 stars'})).append(
  204. $('<option/>', {value: '3', text: '3 stars'})).append(
  205. $('<option/>', {value: '4', text: '4 stars'})).append(
  206. $('<option/>', {value: '5', text: '5 stars'}))))
  207. )));
  208. }
  209. else if(id == 'fsdiv'){
  210. $('#'+id).append(
  211. $('<form/>', {action: 'http://ul.'+location.hostname.replace(/^g\./, '')+'/image_lookup.php', method: 'post', enctype: 'multipart/form-data'}).append(
  212. $('<div/>').append(
  213. $('<p/>', {text: 'If you want to combine a file search with a category/keyword search, upload the file first.', style: 'font-weight: bold;'})).append(
  214. $('<p/>', {text: 'Select a file to upload, then hit File Search. All public galleries containing this exact file will be displayed.'})).append(
  215. $('<div/>').append(
  216. $('<input/>', {type: 'file', name: 'sfile', size: '40', style: 'font-size:8pt;'})).append(
  217. $('<input/>', {type: 'submit', name: 'f_sfile', value: 'File Search', style: 'font-size:8pt;'}))).append(
  218. $('<p/>', {text: 'For color images, the system can also perform a similarity lookup to find resampled images.'})).append(
  219. $('<table/>', {class: 'itsf'}).append(
  220. $('<tbody/>').append(
  221. $('<tr/>').append(
  222. $('<td/>', {class: 'ic3'}).append(
  223. $('<input/>', {id: 'fs_similiar', type: 'checkbox', name: 'fs_similar', checked: 'checked'})).append(
  224. $('<label/>', {for: 'fs_similar', text: 'Use Similarity Scan'}))).append(
  225. $('<td/>', {class: 'ic3'}).append(
  226. $('<input/>', {id: 'fs_covers', type: 'checkbox', name: 'fs_covers'})).append(
  227. $('<label/>', {for: 'fs_covers', text: 'Only Search Covers'}))).append(
  228. $('<td/>', {class: 'ic3'}).append(
  229. $('<input/>', {id: 'fs_exp', type: 'checkbox', name: 'fs_exp'})).append(
  230. $('<label/>', {for: 'fs_exp', text: 'Show Expunged'}))))))));
  231. }
  232.  
  233. $(this).text(function(){
  234. return $(this).text().replace("Show", "Hide");
  235. });
  236. }else{
  237. $('#'+id).empty();
  238. $(this).text(function(){
  239. return $(this).text().replace("Hide", "Show");
  240. });
  241. }
  242. $('#'+id).toggle();
  243.  
  244. e.preventDefault();
  245. });
  246.  
  247. $('#addenglish').on('click', function(e){
  248. $('input[name="f_search"]').val(function(i, v){
  249. return v.replace(/(.*)/, 'english'+(v == 'Search Keywords' ? '' : ' "$1"'));
  250. });
  251. });
  252. //TODO: Possibly use jQuery slide?
  253.  
  254. //This is "more or less" the in built "toggle_category" function.
  255. //Sadly that doesn't get loaded on gallery pages, so we use this instead.
  256. $('body').on('click', 'img[id^=f_]', function(){
  257. var e = $(this), //img
  258. d = $(e).prev(), //input
  259. c = parseInt($(d).val()),
  260. a = "http://ehgt.org/g/c/";
  261.  
  262. if(c){
  263. $(d).val(0);
  264. $(e).attr('src', $(e).attr('src').replace('.png', '_d.png'));
  265. }else{
  266. $(d).val(1);
  267. $(e).attr('src', $(e).attr('src').replace('_d.png', '.png'));
  268. }
  269. });
  270. });
  271. }
  272.  
  273. if(typeof window.jQuery === "undefined"){
  274. addJQuery(main); //@require doesn't work, so load JQuery then load the script
  275. }
  276. else{
  277. main(); //@require works, so just load the script
  278. }