269 lines
8.6 KiB
JavaScript
269 lines
8.6 KiB
JavaScript
function handleMessage(msg) {
|
|
console.log(msg)
|
|
if (msg.command == "STARTED") {
|
|
MapData = JSON.parse(msg.data);
|
|
console.log(MapData);
|
|
console.log("MapData loaded");
|
|
|
|
if (MapOn == false) {
|
|
MapOn = true;
|
|
// ico
|
|
// height: 26px;
|
|
// width: 26px;
|
|
// #343a40
|
|
// let navBarEl = document.getElementsByClassName("navbar-collapse")[1];
|
|
const titleDiv = document.getElementById("title");
|
|
let nextElement = titleDiv.nextElementSibling;
|
|
let navBarEl = nextElement.nextElementSibling;
|
|
|
|
let geoIcon = document.createElement("img");
|
|
geoIcon.src = chrome.runtime.getURL("icons/geoportal.png");
|
|
geoIcon.width = "26";
|
|
geoIcon.height = "26";
|
|
geoButton.style.border = "none";
|
|
geoButton.style.background = "none";
|
|
geoButton.appendChild(geoIcon);
|
|
navBarEl.insertBefore(geoButton, navBarEl.children[0]);
|
|
geoButton.onclick = geoportalButtonClick;
|
|
|
|
let googleIcon = document.createElement("img");
|
|
googleIcon.src = chrome.runtime.getURL("icons/google.png");
|
|
googleIcon.width = "26";
|
|
googleIcon.height = "26";
|
|
googleButton.style.border = "none";
|
|
googleButton.style.background = "none";
|
|
googleButton.appendChild(googleIcon);
|
|
navBarEl.insertBefore(googleButton, navBarEl.children[0]);
|
|
googleButton.onclick = googleButtonClick;
|
|
|
|
let isokIcon = document.createElement("img");
|
|
isokIcon.src = chrome.runtime.getURL("icons/isok.png");
|
|
isokIcon.width = "26";
|
|
isokIcon.height = "26";
|
|
isokButton.style.border = "none";
|
|
isokButton.style.background = "none";
|
|
isokButton.appendChild(isokIcon);
|
|
navBarEl.insertBefore(isokButton, navBarEl.children[0]);
|
|
isokButton.onclick = isokButtonClick;
|
|
|
|
let sopoIcon = document.createElement("img");
|
|
sopoIcon.src = chrome.runtime.getURL("icons/sopo.png");
|
|
sopoIcon.width = "26";
|
|
sopoIcon.height = "26";
|
|
sopoButton.style.border = "none";
|
|
sopoButton.style.background = "none";
|
|
sopoButton.appendChild(sopoIcon);
|
|
navBarEl.insertBefore(sopoButton, navBarEl.children[0]);
|
|
sopoButton.onclick = sopoButtonClick;
|
|
|
|
let gdosIcon = document.createElement("img");
|
|
gdosIcon.src = chrome.runtime.getURL("icons/gdos.png");
|
|
gdosIcon.width = "26";
|
|
gdosIcon.height = "26";
|
|
gdosButton.style.border = "none";
|
|
gdosButton.style.background = "none";
|
|
gdosButton.appendChild(gdosIcon);
|
|
navBarEl.insertBefore(gdosButton, navBarEl.children[0]);
|
|
gdosButton.onclick = gdosButtonClick;
|
|
|
|
let drogiIcon = document.createElement("img");
|
|
drogiIcon.src = chrome.runtime.getURL("icons/lpp.png");
|
|
drogiIcon.width = "26";
|
|
drogiIcon.height = "26";
|
|
drogiButton.style.border = "none";
|
|
drogiButton.style.background = "none";
|
|
drogiButton.appendChild(drogiIcon);
|
|
navBarEl.insertBefore(drogiButton, navBarEl.children[0]);
|
|
drogiButton.onclick = drogiButtonClick;
|
|
|
|
|
|
|
|
// dzialkiIcon.src = chrome.runtime.getURL("icons/dzialki1.png");
|
|
// dzialkiIcon.width = "26";
|
|
// dzialkiIcon.height = "26";
|
|
// dzialkiButton.style.border = "none";
|
|
// dzialkiButton.style.background = "none";
|
|
// dzialkiButton.appendChild(dzialkiIcon);
|
|
// navBarEl.insertBefore(dzialkiButton, navBarEl.children[0]);
|
|
// dzialkiButton.onclick = dzialkiButtonClick;
|
|
|
|
|
|
// dzialki2Icon.src = chrome.runtime.getURL("icons/dzialki2.png");
|
|
// dzialki2Icon.width = "26";
|
|
// dzialki2Icon.height = "26";
|
|
// dzialki2Button.style.border = "none";
|
|
// dzialki2Button.style.background = "none";
|
|
// dzialki2Button.appendChild(dzialki2Icon);
|
|
// navBarEl.insertBefore(dzialki2Button, navBarEl.children[0]);
|
|
// dzialki2Button.onclick = dzialki2ButtonClick;
|
|
|
|
// mpzpIcon.src = chrome.runtime.getURL("icons/mpzp.png");
|
|
// mpzpIcon.width = "26";
|
|
// mpzpIcon.height = "26";
|
|
// mpzpButton.style.border = "none";
|
|
// mpzpButton.style.background = "none";
|
|
// mpzpButton.appendChild(mpzpIcon);
|
|
|
|
// navBarEl.insertBefore(mpzpButton, navBarEl.children[0]);
|
|
// mpzpButton.onclick = mpzpButtonClick;
|
|
|
|
// osuwiskaButton.appendChild(document.createTextNode("SOPO"));
|
|
// navBarEl.insertBefore(osuwiskaButton, navBarEl.children[0]);
|
|
// osuwiskaButton.onclick = osuwiskaButtonClick;
|
|
|
|
// navBarEl.insertBefore(
|
|
// document.createElement("DIV"),
|
|
// navBarEl.children[0]
|
|
// );
|
|
// navBarEl.firstChild.style.height = "2rem";
|
|
// navBarEl.firstChild.style.background = "gray";
|
|
// navBarEl.firstChild.style.padding = "1px";
|
|
// navBarEl.firstChild.style.margin = "6px";
|
|
|
|
// fetch(chrome.extension.getURL("page.html"))
|
|
// .then((response) => response.text())
|
|
// .then((text) => {
|
|
// dropdownButton.innerHTML = text;
|
|
// navBarEl.insertBefore(dropdownButton, navBarEl.children[0]);
|
|
// let button = document.getElementById("dropdown-button");
|
|
// let buttonIcon = document.createElement("img");
|
|
// buttonIcon.src = chrome.runtime.getURL("icons/slice.png");
|
|
// buttonIcon.width = "26";
|
|
// buttonIcon.height = "26";
|
|
// button.style.border = "none";
|
|
// button.style.background = "none";
|
|
// button.appendChild(buttonIcon);
|
|
|
|
// let content = document.getElementById("dropdown-content");
|
|
|
|
// let sectionDownloadIcon = document.createElement("img");
|
|
// sectionDownloadIcon.src = chrome.runtime.getURL("icons/save.png");
|
|
// sectionDownloadIcon.width = "26";
|
|
// sectionDownloadIcon.height = "26";
|
|
// sectionDownload.style.border = "none";
|
|
// sectionDownload.style.background = "none";
|
|
// sectionDownload.appendChild(sectionDownloadIcon);
|
|
// content.insertBefore(sectionDownload, content.children[0]);
|
|
// sectionDownload.onclick = sectionDownloadClick;
|
|
|
|
|
|
// let sectionIcon = document.createElement("img");
|
|
// sectionIcon.src = chrome.runtime.getURL("icons/pen.png");
|
|
// sectionIcon.width = "26";
|
|
// sectionIcon.height = "26";
|
|
// sectionDraw.style.border = "none";
|
|
// sectionDraw.style.background = "none";
|
|
// sectionDraw.appendChild(sectionIcon);
|
|
// content.insertBefore(sectionDraw, content.children[0]);
|
|
// sectionDraw.onclick = sectionDrawClick;
|
|
|
|
|
|
// button.onclick = abc;
|
|
|
|
// function abc(){
|
|
// if(dropdownState == 0) {
|
|
// content.style.display = "flex"
|
|
// dropdownState = 1;
|
|
// }else{
|
|
// content.style.display = "none"
|
|
// dropdownState = 0;
|
|
// }
|
|
// }
|
|
// });
|
|
|
|
// // sectionDraw.appendChild(document.createTextNode("Prz"));
|
|
// // navBarEl.insertBefore(sectionDraw, navBarEl.children[0]);
|
|
// // sectionDraw.onclick = sectionDrawClick;
|
|
|
|
// // sectionDownload.appendChild(document.createTextNode("Pb"));
|
|
// // navBarEl.insertBefore(sectionDownload, navBarEl.children[0]);
|
|
// // sectionDownload.onclick = sectionDownloadClick;
|
|
|
|
// posIcon.src = chrome.runtime.getURL("icons/position.png");
|
|
// posIcon.width = "26";
|
|
// posIcon.height = "26";
|
|
// posButton.style.border = "none";
|
|
// posButton.style.background = "none";
|
|
// posButton.appendChild(posIcon);
|
|
|
|
// navBarEl.insertBefore(posButton, navBarEl.children[0]);
|
|
// posButton.onclick = getPos;
|
|
|
|
// lineButton.appendChild(document.createTextNode("Linia"));
|
|
// navBarEl.insertBefore(lineButton, navBarEl.children[0]);
|
|
// lineButton.onclick = getLines;
|
|
}
|
|
}
|
|
// if (msg.command == "linesResult") {
|
|
// drawLines(msg.result);
|
|
// }
|
|
// if (msg.command == "gotLine") {
|
|
// let attr = document.getElementById("attribute");
|
|
// if (attr == null) {
|
|
// setTimeout(function () {
|
|
// purgeLineTable(attr);
|
|
// drawCalcButton(attr);
|
|
// }, 500);
|
|
// } else {
|
|
// purgeLineTable(attr);
|
|
// drawCalcButton(attr);
|
|
// }
|
|
|
|
// cell1.innerHTML = txt1;
|
|
// cell2.innerHTML = txt2;
|
|
// }
|
|
if (msg.command == "gotStacja") {
|
|
if (stacjaReq != 1) {
|
|
let attr = document.getElementById("attribute");
|
|
if (attr == null) {
|
|
setTimeout(function () {
|
|
attr = document.getElementById("attribute");
|
|
purgeTable(attr);
|
|
drawButton(attr);
|
|
}, 500);
|
|
} else {
|
|
purgeTable(attr);
|
|
drawButton(attr);
|
|
}
|
|
}
|
|
}
|
|
if (msg.command == "stacjaResult") {
|
|
stacjaReq = 0;
|
|
data = msg.result;
|
|
|
|
let attr = document.getElementById("attribute");
|
|
|
|
const dataNames = [
|
|
"Rok budowy",
|
|
"Rok modernizacji",
|
|
"Moc stacji",
|
|
"Typ żerdz.",
|
|
"Czy niebezp.",
|
|
"Data oględzin",
|
|
"Zamk. rozdz. sn (?)",
|
|
"Zasila oświetlenie",
|
|
];
|
|
let d = data[0];
|
|
const dataData = [
|
|
d["ROK_BUD"],
|
|
d["ROK_MODERN"],
|
|
d["MAX_MOC_STAC"],
|
|
d["TYP_ZERDZ"],
|
|
d["CZY_NIEBEZP"],
|
|
d["DATA_OGLEDZ"],
|
|
d["ZAMK_ROZDZ_SN"],
|
|
d["CZY_ZAS_OSW"],
|
|
];
|
|
|
|
insertRows(attr, dataNames, dataData);
|
|
}
|
|
if (msg.command == "getToken") {
|
|
data = sessionStorage.getItem("PDSEtoken");
|
|
port.postMessage({ response: data });
|
|
}
|
|
if (msg.command == "gminaResult") {
|
|
const URL = msg.result;
|
|
window.open(URL, "_blank");
|
|
}
|
|
}
|