ExH login

Login to exhentai without modifying cookie by your self.

  1. // ==UserScript==
  2. // @name ExH login
  3. // @namespace https://blog.maple3142.net/
  4. // @version 0.1
  5. // @description Login to exhentai without modifying cookie by your self.
  6. // @author maple3142
  7. // @connect e-hentai.org
  8. // @require https://code.jquery.com/jquery-3.2.1.slim.min.js
  9. // @match https://exhentai.org/
  10. // @grant GM_xmlhttpRequest
  11. // ==/UserScript==
  12.  
  13. ;(function($) {
  14. 'use strict'
  15.  
  16. const $ct = $('<div>')
  17. .css('position', 'absolute')
  18. .css('height', '100%')
  19. .css('width', '100%')
  20. .css('background-color', 'white')
  21. const $lgb = $('<div>')
  22. .css('position', 'absolute')
  23. .css('left', '50%')
  24. .css('top', '50%')
  25. .css('transform', 'translateX(-50%) translateY(-50%)')
  26. .css('display', 'flex')
  27. .css('align-items', 'center')
  28. .css('width', '30%')
  29. const $ac = $('<input>')
  30. const $acl = $('<label>')
  31. .text('ac: ')
  32. .css('flex', 1)
  33. .append($ac)
  34. const $pw = $('<input>')
  35. const $pwl = $('<label>')
  36. .text('pw: ')
  37. .css('flex', 1)
  38. .append($pw)
  39. .attr('type', 'password')
  40. const $lg = $('<button>').text('Login')
  41. $lgb.append($acl)
  42. .append($pwl)
  43. .append($lg)
  44. $ct.append($lgb)
  45.  
  46. $lg.on('click', e => doLogin($ac.val(), $pw.val()))
  47.  
  48. function parseHeaders(h) {
  49. return Object.assign(
  50. ...h
  51. .split('\n')
  52. .map(x => x.split(/:\s+/))
  53. .map(([k, v]) => ({ [k]: v }))
  54. )
  55. }
  56. function doLogin(UserName, PassWord) {
  57. GM_xmlhttpRequest({
  58. url: 'https://forums.e-hentai.org/index.php?act=Login&CODE=01',
  59. method: 'POST',
  60. headers: {
  61. 'Content-Type': 'application/x-www-form-urlencoded'
  62. },
  63. data: `UserName=${UserName}&PassWord=${PassWord}&ipb_login_submit=Login!&b=d&bt=1-1&CookieDate=1`,
  64. onload: xhr => {
  65. const res = xhr.responseText
  66. const h = parseHeaders(xhr.responseHeaders)
  67. if (res && res.includes('You are now logged in as')) {
  68. document.cookie = 'yay=louder; Max-Age=0; path=/; domain=.exhentai.org'
  69. for (const tok of h['set-cookie'].split(',')) {
  70. document.cookie = tok.replace(/e-hentai/, 'exhentai')
  71. }
  72. location.href = location.href
  73. }
  74. },
  75. onerror: console.error
  76. })
  77. }
  78.  
  79. if ($('img[src="https://exhentai.org/"]').length) {
  80. $(document.body).append($ct)
  81. //if(ac&&pw)doLogin(ac,pw)
  82. }
  83. document.cookie = document.cookie.replace('yay=louder', '')
  84. })(jQuery.noConflict())