Last active
June 7, 2016 15:38
-
-
Save x3388638/b96a8b17fbfb2eb1de9ee48c9c674a50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Captured date tool | |
// @namespace https://PortalExplorer-rhcloud.com/ | |
// @version 0.1 | |
// @description show the captured date of portal | |
// @author Y.Y. | |
// @include https://www.ingress.com/intel* | |
// @include http://www.ingress.com/intel* | |
// @match https://www.ingress.com/intel* | |
// @match http://www.ingress.com/intel* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var baseURL = ''; | |
var injectInterval = setInterval(function() { | |
if(typeof Ij == 'function') { | |
window.Ij = function(a, b) { | |
if(b && b.title && b.A == 'portal' && b.state == 2) { | |
var guid = b.i; | |
fetch(baseURL + 'portals/get/' + guid) | |
.then(res => res.json()) | |
.then((data) => { | |
if(data.exist) { | |
var date = data.portal.date; | |
var countDay = countDayDiff(date); | |
showCount(date, countDay); | |
} | |
}); | |
}); | |
} | |
T(a.a, yj, { | |
H: b, | |
Fc: b.J && !IS_VERSION_MOBILE, | |
oc: b.o.join(", ") | |
}); | |
}; | |
console.log('Injected.'); | |
clearInterval(injectInterval); | |
} | |
}, 1000); | |
var countDayDiff = function(ori) { | |
var date1 = new Date(ori); | |
var date2 = new Date(); | |
var timeDiff = Math.abs(date2.getTime() - date1.getTime()); | |
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); | |
return diffDays; | |
}; | |
var showCount = function(date, count) { | |
var node = document.createElement('div'); | |
node.innerHTML = '<div>Captured: ' + date + '</div><div>Days: ' + count + '</div>'; | |
document.getElementById('portal_metadata').appendChild(node); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment