VivifyGmail

Keep your POP3 account in Gmail up to date

目前為 2018-02-02 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
    });
}());