forked from jonas0616/vivifygmail
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvivify.user.js
More file actions
62 lines (56 loc) · 1.71 KB
/
vivify.user.js
File metadata and controls
62 lines (56 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// ==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 getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
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 = getCookie('GMAIL_AT');
const ik = window.GLOBALS[9];
const refreshUrl = `${url}?ik=${ik}&act=cma_1&at=${at}&view=up&rt=j`;
refresh(refreshUrl);
// repeat by one minute
window.setInterval(refresh, 60000, refreshUrl);
});
}());