Use tileserver config

This commit is contained in:
clerie 2020-07-03 21:29:19 +02:00
parent d72e904a20
commit 77383bad6f

View File

@ -2,15 +2,38 @@ const urls = [
"*://*.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) {
var url = request.url.replace("tile.openstreetmap.org", "tiles.demostat.de");
console.log("custom-openstreetmap-tile-server: " + request.url + " -> " + url);
updateTileserverUrl();
if (tileserver_url == "") {
log("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"]);