-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawtools-tweaks.user.js
110 lines (104 loc) · 4.12 KB
/
drawtools-tweaks.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
103
104
105
106
107
108
109
110
// ==UserScript==
// @id iitc-plugin-drawtools-tweaks@hansolo669
// @name IITC plugin: drawtools tweaks
// @category Tweaks
// @version 0.0.1
// @namespace https://github.com/hansolo669/iitc-tweaks
// @updateURL https://iitc.reallyawesomedomain.com/drawtools-tweaks.user.js
// @downloadURL https://iitc.reallyawesomedomain.com/drawtools-tweaks.user.js
// @description Bolt on functionality for stock drawtools
// @include https://*.ingress.com/intel*
// @include http://*.ingress.com/intel*
// @match https://*.ingress.com/intel*
// @match http://*.ingress.com/intel*
// @include https://*.ingress.com/mission/*
// @include http://*.ingress.com/mission/*
// @match https://*.ingress.com/mission/*
// @match http://*.ingress.com/mission/*
// @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 ////////////////////////////////////////////////////////
window.plugin.drawToolsTweaks = {};
window.plugin.drawToolsTweaks.openPicker = function() {
dialog({
html: '<input type="color" name="drawColor" id="drawtools-color-picker"></input>',
id: 'plugin-drawtools-color',
title: 'Draw Tools Color Picker'
});
$('#drawtools-color-picker').spectrum({
flat: false,
showInput: false,
showButtons: false,
showPalette: true,
showSelectionPalette: false,
palette: [
['#a24ac3','#514ac3','#4aa8c3','#51c34a'],
['#c1c34a','#c38a4a','#c34a4a','#c34a6f'],
['#000000','#666666','#bbbbbb','#ffffff']
],
change: function(color) {
window.plugin.drawTools.setDrawColor(color.toHexString());
document.querySelector("#drawtools-color-picker-button").style.background = window.plugin.drawTools.currentColor;
},
color: window.plugin.drawTools.currentColor
});
}
function attachControls() {
var container = document.querySelector(".leaflet-top.leaflet-left");
var buttonContainer = document.createElement("div");
buttonContainer.classList.add("leaflet-bar");
buttonContainer.classList.add("leaflet-control");
var button = document.createElement("a");
button.classList.add("leaflet-bar-part");
button.id = "drawtools-color-picker-button"
button.textContent = " ";
button.style.background = window.plugin.drawTools.currentColor;
button.addEventListener("click", function(ev) {
ev.preventDefault();
if (isSmartphone()) {
ev.stopPropagation();
window.plugin.drawToolsTweaks.openPicker();
}
});
buttonContainer.appendChild(button);
container.appendChild(buttonContainer);
if (!isSmartphone()) {
$('#drawtools-color-picker-button').spectrum({
flat: false,
showInput: false,
showButtons: false,
showPalette: true,
showSelectionPalette: false,
palette: [
['#a24ac3','#514ac3','#4aa8c3','#51c34a'],
['#c1c34a','#c38a4a','#c34a4a','#c34a6f'],
['#000000','#666666','#bbbbbb','#ffffff']
],
change: function(color) {
window.plugin.drawTools.setDrawColor(color.toHexString());
document.querySelector("#drawtools-color-picker-button").style.background = window.plugin.drawTools.currentColor;
},
color: window.plugin.drawTools.currentColor
});
}
}
var setup = function() {
attachControls();
};
// 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);