ExHentai.org - quick search artist on nhentai.net

Adds link next to artist name to quickly find him on nhentai.net

  1. // ==UserScript==
  2. // @name ExHentai.org - quick search artist on nhentai.net
  3. // @namespace exhentai_org_search_artist_on_nhentai_net
  4. // @description Adds link next to artist name to quickly find him on nhentai.net
  5. // @match *://*.exhentai.org/g/*/*
  6. // @match *://*.e-hentai.org/g/*/*
  7. // @match *://*.nhentai.net/nope/*/*
  8. // @version 1.16
  9. // @homepageURL https://greasyfork.org/en/scripts/448730-exhentai-search-artist-on-nhentai-net/
  10. // @run-at document-start
  11. // @grant GM_registerMenuCommand
  12. // @grant GM_setValue
  13. // @grant GM_getValue
  14. // @author miwoj
  15. // @license Mozilla Public License 2.0; http://www.mozilla.org/MPL/2.0/
  16. // @license CC Attribution-ShareAlike 4.0 International; http://creativecommons.org/licenses/by-sa/4.0/
  17. // @icon https://exhentai.org/favicon.ico
  18. // ==/UserScript==
  19. var config = {
  20. 'debug': false
  21. }
  22. var debug = config.debug ? console.log.bind(console) : function () {
  23. };
  24.  
  25.  
  26. var nhentaiSite;
  27.  
  28. function SearchNhentai() {
  29. var title=document.title.replace(/( - ExHentai\.org)|( - E-Hentai Galleries)|[^\w\d\[\]]/g," ");
  30. var artist=document.querySelector('[id^="td_artist"]').id;
  31. var artist2=artist.split(":").pop()
  32.  
  33. var artist_name=artist2.replaceAll("_","+");
  34.  
  35. // YOU CAN ADD YOUR CUSTOM TAGS YOU WANT ADDED TO EVERY SEARCH
  36. var artist_name_plus_extra_tags=artist_name+"+some_tag+other_tag";
  37.  
  38. // SWITCH COMMENT IN THESE 2 LINES BELOW
  39. window.open("https://nhentai.net/search/?q="+encodeURI(artist_name));
  40. //window.open("https://nhentai.net/search/?q="+encodeURI(artist_name_plus_extra_tags));
  41. }
  42.  
  43. function CreateButton(text,func){
  44. var btn=document.createElement("button");
  45. btn.type="button";
  46. btn.onclick="";
  47. btn.innerHTML=text;
  48. btn.addEventListener('click',func);
  49. var artist_link=document.querySelector('[id^="td_artist"]');
  50.  
  51. var all = document.getElementsByClassName('gt');
  52. for (var i = 0; i < all.length; i++) {
  53. all[i].style.border = '0px';
  54. }
  55.  
  56. artist_link.style.border="0px";
  57. //alert (artist_link);
  58.  
  59. btn.style.display="block";
  60. btn.style.backgroundColor="#4f535b00";
  61. btn.style.color="#ff6c85";
  62. btn.style.border="none";
  63. btn.style.marginTop="5px";
  64. btn.style.marginLeft="0px";
  65. btn.style.paddingLeft="0px";
  66. btn.style.cursor="pointer";
  67. btn.style.fontSize="8pt";
  68. btn.style.fontFamily="arial,helvetica,sans-serif";
  69. btn.style.fontWeight="bold";
  70. artist_link.insertBefore(btn, null);
  71. }
  72.  
  73. var init = function () {
  74. nhentaiSite=GM_getValue('nhentaiSite')||'https://nhentai.net';
  75. CreateButton('search nhentai.net',function () {
  76. SearchNhentai();
  77. });
  78.  
  79. }
  80. window.addEventListener('DOMContentLoaded', init);
  81. function setUserPref(varName, defaultVal, menuText, promtText, sep){
  82. GM_registerMenuCommand(menuText, function() {
  83. var val = prompt(promtText, GM_getValue(varName, defaultVal));
  84. if (val === null) { return; } // end execution if clicked CANCEL
  85. // prepare string of variables separated by the separator
  86. if (sep && val){
  87. var pat1 = new RegExp('\\s*' + sep + '+\\s*', 'g'); // trim space/s around separator & trim repeated separator
  88. var pat2 = new RegExp('(?:^' + sep + '+|' + sep + '+$)', 'g'); // trim starting & trailing separator
  89. //val = val.replace(pat1, sep).replace(pat2, '');
  90. }
  91. //val = val.replace(/\s{2,}/g, ' ').trim(); // remove multiple spaces and trim
  92. GM_setValue(varName, val);
  93. // Apply changes (immediately if there are no existing highlights, or upon reload to clear the old ones)
  94. //if(!document.body.querySelector(".THmo")) THmo_doHighlight(document.body);
  95. //else location.reload();
  96. });
  97. }