VivifyGmail

Keep your POP3 account in Gmail up to date

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         VivifyGmail
// @namespace    https://github.com/jonas0616/vivifygmail
// @version      0.1.3
// @description  Keep your POP3 account in Gmail up to date
// @author       jonas0616
// @grant        none
// @include      https://mail.google.com/*
// @license      Apache License 2.0
// ==/UserScript==

(function () { // eslint-disable-line func-names
  'use strict'; // eslint-disable-line

  function refresh(refreshUrl) {
    // console.log(`VivifyGamil: refresh ${refreshUrl}`);
    const fetchInit = {
      method: 'POST',
      headers: new Headers(),
      credentials: 'include',
    };
    fetch(refreshUrl, fetchInit).then(data => {
      // console.log(data);
    }).catch(e => {
      console.log(e);
    });
  }

  Promise.resolve()
    .then(() => new Promise((resolve) => {
      const id = setInterval(() => {
        if (window.GM_ACTION_TOKEN !== undefined &&
            window.GLOBALS !== undefined) {
          clearInterval(id);
          resolve();
        }
      }, 5000);
    }))

    .then(() => {
      const l = window.location;
      const url = `${l.origin}${l.pathname}`;
      const at = window.GM_ACTION_TOKEN;
      const ik = window.GLOBALS[9];
      const refreshUrl = `${url}?ik=${ik}&&at=${at}&view=up&act=par&rt=j`;

      refresh(refreshUrl);
      // repeat by one minute
      window.setInterval(refresh, 60000, refreshUrl);
    });
}());