E(x)-Hentai CompactSearch

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

As of 2017-01-23. See the latest version.

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