Compare commits

...

5 Commits

Author SHA1 Message Date
626e5f932e Better log msg 2020-07-03 21:37:27 +02:00
77383bad6f Use tileserver config 2020-07-03 21:29:19 +02:00
d72e904a20 Add log function 2020-07-03 21:22:22 +02:00
2a0c333b9d Make urls const 2020-07-03 21:12:25 +02:00
232d1e5b30 Fix undefined settings 2020-07-03 21:08:10 +02:00
2 changed files with 35 additions and 8 deletions

View File

@ -1,12 +1,39 @@
function replaceTileserver(request) { const urls = [
var url = request.url.replace("tile.openstreetmap.org", "tiles.demostat.de");
console.log("custom-openstreetmap-tile-server: " + request.url + " -> " + url);
return {redirectUrl: url};
}
urls = [
"*://*.tile.openstreetmap.org/*" "*://*.tile.openstreetmap.org/*"
] ]
var tileserver_url = "";
function log(msg) {
console.log("custom-openstreetmap-tile-server: " + msg)
}
function setTileserver(storage) {
tileserver_url = storage.tileserver;
log("set tileserver_url to " + tileserver_url);
}
function onError(error) {
log(`Error: ${error}`);
}
function updateTileserverUrl() {
var getting = browser.storage.local.get("tileserver");
getting.then(setTileserver, onError);
}
function replaceTileserver(request) {
updateTileserverUrl();
if (tileserver_url == "") {
log(request.url + " -> no tileserver_url");
return {}
}
var url = request.url.replace("tile.openstreetmap.org", tileserver_url);
log(request.url + " -> " + url);
return {redirectUrl: url};
}
chrome.webRequest.onBeforeRequest.addListener(replaceTileserver, {urls: urls}, ["blocking"]); chrome.webRequest.onBeforeRequest.addListener(replaceTileserver, {urls: urls}, ["blocking"]);

View File

@ -8,7 +8,7 @@ function saveOptions(e) {
function restoreOptions() { function restoreOptions() {
function setCurrentChoice(result) { function setCurrentChoice(result) {
document.querySelector("#tileserver").value = result.tileserver; document.querySelector("#tileserver").value = result.tileserver || "";
} }
function onError(error) { function onError(error) {