Init repository

This commit is contained in:
clerie 2020-07-03 20:54:27 +02:00
commit f56ae7514e
4 changed files with 82 additions and 0 deletions

12
js/background.js Normal file
View File

@ -0,0 +1,12 @@
function replaceTileserver(request) {
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/*"
]
chrome.webRequest.onBeforeRequest.addListener(replaceTileserver, {urls: urls}, ["blocking"]);

26
manifest.json Normal file
View File

@ -0,0 +1,26 @@
{
"manifest_version": 2,
"name": "Custom OpenStreetMap Tile Server",
"version": "0.0.1",
"description": "Set a custom OpenStreetMap Tile Server, to speed up map loading.",
"homepage_url": "https://git.clerie.de/clerie/custom-openstreetmap-tile-server/",
"icons": {
"73": "media/icon-73.png",
"228": "media/icon-228.png"
},
"author": "https://clerie.de/",
"background": {
"scripts": ["js/background.js"]
},
"options_ui": {
"page": "settings/index.html"
},
"permissions": ["webRequest", "webRequestBlocking", "<all_urls>", "storage"]
}

21
settings/index.html Normal file
View File

@ -0,0 +1,21 @@
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<form>
<h2>Tileserver</h2>
<label>
<input type="text" id="tileserver">
</label>
<br>
<br>
<button type="submit">Save</button>
</form>
<script src="settings.js"></script>
</body>
</html>

23
settings/settings.js Normal file
View File

@ -0,0 +1,23 @@
function saveOptions(e) {
e.preventDefault();
browser.storage.local.set({
tileserver: document.querySelector("#tileserver").value
});
}
function restoreOptions() {
function setCurrentChoice(result) {
document.querySelector("#tileserver").value = result.tileserver;
}
function onError(error) {
console.log(`Error: ${error}`);
}
var getting = browser.storage.local.get("tileserver");
getting.then(setCurrentChoice, onError);
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);