-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosm_map_mod.user.js
207 lines (186 loc) · 7.36 KB
/
osm_map_mod.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// ==UserScript==
// @name OSM map mod
// @version 1.0
// @description Just a few tweaks with CSS-Filters
// @author arnesetzer
// @match https://www.openstreetmap.org/
// @grant GM_addStyle
// ==/UserScript==
let options;
if (localStorage.getItem("advCmOptions") == null) {
options = {};
options.invert = 0;
options.gray = 0;
options.brightness = 1.0;
options.contrast = 1.0;
options.saturate = 1.0;
options.sepia = 0;
}
else {
options = JSON.parse(localStorage.getItem("advCmOptions"));
}
//Create carrier div
let div = document.createElement('div');
div.id = "advCmOptions";
div.classList.add("leaflet-control", "leaflet-control-custom");
div.style.visibility = "hidden";
document.getElementsByClassName('leaflet-bottom leaflet-left')[6].appendChild(div);
//Open&Close-Btn
let a = document.createElement('a');
a.id = "advCmBtn";
a.classList.add("leaflet-bar", "leaflet-control", "leaflet-control-custom");
a.style.backgroundColor = "white";
a.style.width="26px";
a.style.height="26px";
a.style.display="flex";
a.style.alignItems="center";
a.style.justifyContent="center";
a.onclick = function () { toggleVisibility(); }
let span = document.createElement('span');
span.classList.add("glyphicon", "glyphicon-th-list");
a.appendChild(span);
document.getElementsByClassName('leaflet-bottom leaflet-left')[6].appendChild(a);
//Invert slider
let sliderInvert = document.createElement('input');
sliderInvert.type = 'range';
sliderInvert.min = 0;
sliderInvert.max = 1;
sliderInvert.step = 0.2;
sliderInvert.value = options.invert;
sliderInvert.id = 'advCmInvert';
let labelInvert = document.createElement('span');
labelInvert.innerText="Invertieren";
labelInvert.classList.add("bg-primary")
div.appendChild(labelInvert);
div.appendChild(sliderInvert);
//Gray slider
let sliderGray = document.createElement('input');
sliderGray.type = 'range';
sliderGray.min = 0;
sliderGray.max = 1;
sliderGray.step = 0.1;
sliderGray.value = options.gray;
sliderGray.id = 'advCmGray';
let labelGray = document.createElement('span');
labelGray.innerText="Graustufen";
labelGray.classList.add("bg-primary")
div.appendChild(labelGray);
div.appendChild(sliderGray)
//Brightness slider
let sliderBrightness = document.createElement('input');
sliderBrightness.type = 'range';
sliderBrightness.min = 0.1;
sliderBrightness.max = 2;
sliderBrightness.step = 0.1;
sliderBrightness.value = options.brightness;
sliderBrightness.id = 'advCmBrightness';
let labelBrightness = document.createElement('span');
labelBrightness.innerText="Helligkeit";
labelBrightness.classList.add("bg-primary")
div.appendChild(labelBrightness);
div.appendChild(sliderBrightness);
//Contrast slider
let sliderContrast = document.createElement('input');
sliderContrast.type = 'range';
sliderContrast.min = 0.1;
sliderContrast.max = 2;
sliderContrast.step = 0.1;
sliderContrast.value = options.contrast;
sliderContrast.id = 'advCmContrast';
let labelContrast = document.createElement('span');
labelContrast.innerText="Kontrast";
labelContrast.classList.add("bg-primary")
div.appendChild(labelContrast);
div.appendChild(sliderContrast);
//Saturate slider
let sliderSaturate = document.createElement('input');
sliderSaturate.type = 'range';
sliderSaturate.min = 0;
sliderSaturate.max = 2;
sliderSaturate.step = 0.1;
sliderSaturate.value = options.saturate;
sliderSaturate.id = 'advCmSaturate';
let labelSaturate = document.createElement('span');
labelSaturate.innerText="Sättigung";
labelSaturate.classList.add("bg-primary")
div.appendChild(labelSaturate);
div.appendChild(sliderSaturate);
//Sepia slider
let sliderSepia = document.createElement('input');
sliderSepia.type = 'range';
sliderSepia.min = 0;
sliderSepia.max = 1;
sliderSepia.step = 0.1;
sliderSepia.value = options.sepia;
sliderSepia.id = 'advCmSepia';
let labelSepia = document.createElement('span');
labelSepia.innerText="Sepia";
labelSepia.classList.add("bg-primary")
div.appendChild(labelSepia);
div.appendChild(sliderSepia);
//Initial load of saved data from local storage
changeCSS();
//Close&ResetBtn
let resetBtn = document.createElement('button');
resetBtn.addEventListener('click', resetMap);
resetBtn.classList.add('btn', 'btn-danger');
resetBtn.innerText ="Zurücksetzen";
let closeBtn = document.createElement('button');
closeBtn.addEventListener('click', toggleVisibility);
closeBtn.classList.add('btn', 'btn-info');
closeBtn.innerText ="Schließen";
div.appendChild(resetBtn);
div.appendChild(closeBtn);
//Create EL
sliderInvert.addEventListener('input', changeCSS);
sliderGray.addEventListener('input', changeCSS);
sliderBrightness.addEventListener('input', changeCSS);
sliderContrast.addEventListener('input', changeCSS);
sliderSaturate.addEventListener('input', changeCSS);
sliderSepia.addEventListener('input', changeCSS);
function changeCSS() {
saveSettings();
let invert = document.getElementById('advCmInvert').value;
let gray = document.getElementById('advCmGray').value;
let brightness = document.getElementById('advCmBrightness').value;
let contrast = document.getElementById('advCmContrast').value;
let saturate = document.getElementById('advCmSaturate').value;
let sepia = document.getElementById('advCmSepia').value;
GM_addStyle(`
#map {
filter: invert(` + invert + `) grayscale(` + gray + `) brightness(` + brightness + `) contrast(` + contrast + `) saturate(` + saturate + `) sepia(` + sepia + `);
-webkit-filter: invert(` + invert + `) grayscale(` + gray + `) brightness(` + brightness + `) contrast(` + contrast + `) saturate(` + saturate + `) sepia(` + sepia + `);
`);
}
function saveSettings() {
options.invert = document.getElementById('advCmInvert').value;
options.gray = document.getElementById('advCmGray').value;
options.brightness = document.getElementById('advCmBrightness').value;
options.contrast = document.getElementById('advCmContrast').value;
options.saturate = document.getElementById('advCmSaturate').value;
options.sepia = document.getElementById('advCmSepia').value;
localStorage.setItem("advCmOptions", JSON.stringify(options));
}
function toggleVisibility() {
if (document.getElementById("advCmOptions").style.visibility == "hidden") {
document.getElementById("advCmOptions").style.visibility = "visible";
document.getElementById("advCmBtn").style.visibility = "hidden";
}
else {
document.getElementById("advCmBtn").style.visibility = "visible";
document.getElementById("advCmOptions").style.visibility = "hidden"
}
}
function resetMap() {
let invert = document.getElementById('advCmInvert').value=options.invert = 0;
let gray = document.getElementById('advCmGray').value= options.gray = 0;
let brightness = document.getElementById('advCmBrightness').value = options.brightness = 1.0;
let contrast = document.getElementById('advCmContrast').value= options.contrast = 1.0;
let saturate = document.getElementById('advCmSaturate').value= options.saturate = 1.0;
let sepia = document.getElementById('advCmSepia').value= options.sepia = 0;
GM_addStyle(`
#map {
filter: invert(` + invert + `) grayscale(` + gray + `) brightness(` + brightness + `) contrast(` + contrast + `) saturate(` + saturate + `) sepia(` + sepia + `);
-webkit-filter: invert(` + invert + `) grayscale(` + gray + `) brightness(` + brightness + `) contrast(` + contrast + `) saturate(` + saturate + `) sepia(` + sepia + `);
`);
}