ExEveryDay

It is the dawn of a new day!

  1. // ==UserScript==
  2. // @name ExEveryDay
  3. // @namespace https://github.com/FlandreDaisuki
  4. // @description It is the dawn of a new day!
  5. // @version 1.0
  6. // @author FlandreDaisuki
  7. // @match https://exhentai.org/*
  8. // @match https://e-hentai.org/*
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @grant GM_xmlhttpRequest
  12. // @connect *
  13. // @license MIT
  14. // @noframes
  15. // ==/UserScript==
  16.  
  17. const DAY_MS = 86400 * 1e3;
  18.  
  19. class Cookie {
  20. constructor(cookie = document.cookie) {
  21. this.map = document.cookie.split('; ')
  22. .reduce((c, s) => {
  23. const i = s.indexOf('=');
  24. c.set(s.slice(0, i), s.slice(i + 1));
  25. return c;
  26. }, new Map());
  27. }
  28.  
  29. get id() {
  30. return this.map.get('ipb_member_id');
  31. }
  32.  
  33. toString() {
  34. return [...this.map.entries()]
  35. .map(([k, v]) => `${k}=${v}`)
  36. .join('; ');
  37. }
  38. }
  39.  
  40. const cookie = new Cookie;
  41.  
  42. const lastDate = new Date(GM_getValue(cookie.id, new Date().toJSON()));
  43. const dateDiff = Date.now() - lastDate;
  44.  
  45. const onerror = (resp) => {
  46. console.error('ExEveryDay', resp);
  47. }
  48.  
  49. const onload = (resp) => {
  50. console.info('ExEveryDay', resp);
  51. if(resp.responseText.match(/It is the dawn of a new day/g)) {
  52. GM_setValue(cookie.id, new Date().toJSON());
  53. }
  54. }
  55.  
  56. if(dateDiff > DAY_MS || dateDiff === 0) {
  57. GM_xmlhttpRequest({
  58. method: 'GET',
  59. url: 'https://e-hentai.org/news.php',
  60. headers: {
  61. Cookie: cookie.toString(),
  62. },
  63. onload,
  64. onerror,
  65. });
  66. }