VivifyGmail

Keep your POP3 account in Gmail up to date

  1. // ==UserScript==
  2. // @name VivifyGmail
  3. // @namespace https://github.com/jonas0616/vivifygmail
  4. // @version 0.1.3
  5. // @description Keep your POP3 account in Gmail up to date
  6. // @author jonas0616
  7. // @grant none
  8. // @include https://mail.google.com/*
  9. // @license Apache License 2.0
  10. // ==/UserScript==
  11.  
  12. (function () { // eslint-disable-line func-names
  13. 'use strict'; // eslint-disable-line
  14.  
  15. function refresh(refreshUrl) {
  16. // console.log(`VivifyGamil: refresh ${refreshUrl}`);
  17. const fetchInit = {
  18. method: 'POST',
  19. headers: new Headers(),
  20. credentials: 'include',
  21. };
  22. fetch(refreshUrl, fetchInit).then(data => {
  23. // console.log(data);
  24. }).catch(e => {
  25. console.log(e);
  26. });
  27. }
  28.  
  29. Promise.resolve()
  30. .then(() => new Promise((resolve) => {
  31. const id = setInterval(() => {
  32. if (window.GM_ACTION_TOKEN !== undefined &&
  33. window.GLOBALS !== undefined) {
  34. clearInterval(id);
  35. resolve();
  36. }
  37. }, 5000);
  38. }))
  39.  
  40. .then(() => {
  41. const l = window.location;
  42. const url = `${l.origin}${l.pathname}`;
  43. const at = window.GM_ACTION_TOKEN;
  44. const ik = window.GLOBALS[9];
  45. const refreshUrl = `${url}?ik=${ik}&&at=${at}&view=up&act=par&rt=j`;
  46.  
  47. refresh(refreshUrl);
  48. // repeat by one minute
  49. window.setInterval(refresh, 60000, refreshUrl);
  50. });
  51. }());