-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiitc-portal-coords.user.js
102 lines (88 loc) · 3.49 KB
/
iitc-portal-coords.user.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// ==UserScript==
// @id iitc-plugin-portal-coords
// @name IITC plugin: portal-coords
// @category Misc
// @version 0.2.0
// @namespace https://github.com/vrabcak/iitc-portal-coords
// @description Portal coords
// @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 wrapper(plugin_info) {
// ensure plugin framework is there, even if iitc is not yet loaded
if (typeof window.plugin !== 'function') {
window.plugin = function () {};
}
// PLUGIN START ////////////////////////////////////////////////////////
// use own namespace for plugin
window.plugin.pocoo = function () {};
window.plugin.pocoo.portaldetailsUpdated = function (data) {
var ll = {};
ll.lat = data.portalData.latE6/1E6;
ll.lng = data.portalData.lngE6/1E6;
window.plugin.pocoo.render(ll);
};
window.plugin.pocoo.render = function (ll) {
var html = '<div id="coords-container">' +
'Coords: ' +
'<span id="coords-text">' +
ll.lat + ' ' + ll.lng +
'</span></div>';
$('#portaldetails > .imgpreview').after(html);
$('#coords-container').click( function() {
var selection = window.getSelection(),
range = document.createRange(),
tmpEl = document.createElement("input"),
tmpUrl = "https://www.ingress.com/intel?ll=" + ll.lat + "," + ll.lng + "&pll=" + ll.lat + "," + ll.lng;
// copy url portal to clipboard
tmpEl.setAttribute("value",tmpUrl);
document.body.appendChild(tmpEl);
tmpEl.select();
document.execCommand("copy");
document.body.removeChild(tmpEl);
//highlight coords
range.selectNodeContents(document.getElementById('coords-text'));
selection.removeAllRanges();
selection.addRange(range);
});
};
window.plugin.pocoo.setupCSS = function() {
$("<style>")
.prop("type", "text/css")
.html('#coords-container {' +
'color: #aaaaaa;' +
'text-align: center;' +
'}'
)
.appendTo("head");
};
var setup = function () {
window.plugin.pocoo.setupCSS();
window.addHook('portalDetailsUpdated', window.plugin.pocoo.portaldetailsUpdated);
};
// PLUGIN END //////////////////////////////////////////////////////////
setup.info = plugin_info; //add the script info data to the function as a property
if (!window.bootPlugins) {
window.bootPlugins = [];
}
window.bootPlugins.push(setup);
// if IITC has already booted, immediately run the 'setup' function
if (window.iitcLoaded && typeof setup === 'function') {
setup();
}
} // wrapper end
// inject code into site context
var script = document.createElement('script');
var info = {};
if (typeof GM_info !== 'undefined' && GM_info && GM_info.script) {
info.script = {
version: GM_info.script.version,
name: GM_info.script.name,
description: GM_info.script.description
};
}
script.appendChild(document.createTextNode('(' + wrapper + ')(' + JSON.stringify(info) + ');'));
(document.body || document.head || document.documentElement).appendChild(script);