diff --git a/.github/workflows/publish_dev.yml b/.github/workflows/publish_dev.yml index 80b3fc14..85e8be3f 100644 --- a/.github/workflows/publish_dev.yml +++ b/.github/workflows/publish_dev.yml @@ -1,6 +1,7 @@ name: Publish Dev Preview to Chrome Store on: - push: + workflow_run: + workflows: [Publish Dev] branches: - 'master-dev' jobs: @@ -27,4 +28,4 @@ jobs: client-secret: ${{ secrets.CHROMESTORE_CLIENT_SECRET }} refresh-token: ${{ secrets.CHROMESTORE_REFRESH_TOKEN }} publish: true - glob: true \ No newline at end of file + glob: true diff --git a/package-lock.json b/package-lock.json index c0b10ef7..2a983bc6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,14 +29,17 @@ "leaflet": "^1.9.4", "leaflet-easybutton": "^2.4.0", "leaflet-fullscreen": "git+https://github.com/Leaflet/Leaflet.fullscreen.git", + "leaflet-geosearch": "^4.2.2", "leaflet-minimap": "^3.6.1", "leaflet-routing-machine": "^3.2.12", "leaflet-svg-shape-markers": "^1.3.0", + "leaflet.measure": "^1.0.0", + "leaflet.polylinemeasure": "^3.0.0", "leaflet.vectorgrid": "^1.3.0", - "lrm-graphhopper": "git+https://github.com/NSWSESMembers/lrm-graphhopper.git", "markerwithlabel": "^2.0.2", "moment": "^2.29.1", "nunjucks": "^3.2.4", + "remove": "^0.1.5", "stopwords": "0.0.5", "xmldom": "^0.6.0" }, @@ -1998,6 +2001,12 @@ "node": ">=6" } }, + "node_modules/@googlemaps/js-api-loader": { + "version": "1.16.10", + "resolved": "https://registry.npmjs.org/@googlemaps/js-api-loader/-/js-api-loader-1.16.10.tgz", + "integrity": "sha512-c2erv2k7P2ilYzMmtYcMgAR21AULosQuUHJbStnrvRk2dG93k5cqptDrh9A8p+ZNlyhiqEOgHW7N9PAizdUM7Q==", + "optional": true + }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.10", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.10.tgz", @@ -3628,12 +3637,6 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" }, - "node_modules/corslite": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/corslite/-/corslite-0.0.6.tgz", - "integrity": "sha512-CqrvLTZk8IhahX7RHYxBPbTuKlpNDAnS3cYJTidbZ5yl69J20c0RojeAFQ+r6tnpuHtl2+LU4yK6Taw44SANDg==", - "deprecated": "This module is now under the @mapbox namespace: install @mapbox/corslite instead" - }, "node_modules/crc-32": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz", @@ -5093,6 +5096,17 @@ "node": ">=4" } }, + "node_modules/hashish": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/hashish/-/hashish-0.0.4.tgz", + "integrity": "sha512-xyD4XgslstNAs72ENaoFvgMwtv8xhiDtC2AtzCG+8yF7W/Knxxm9BX+e2s25mm+HxMKh0rBmXVOEGF3zNImXvA==", + "dependencies": { + "traverse": ">=0.2.4" + }, + "engines": { + "node": "*" + } + }, "node_modules/human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", @@ -5650,6 +5664,15 @@ "resolved": "git+ssh://git@github.com/Leaflet/Leaflet.fullscreen.git#91c9745c712981942499f14f7a347c80fab41096", "license": "ISC" }, + "node_modules/leaflet-geosearch": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/leaflet-geosearch/-/leaflet-geosearch-4.2.2.tgz", + "integrity": "sha512-847zdoX0SJcDCwPmbjO0C8ngPby14bYl7vfY4fLAKLi+AlIa2kWX2FXChu+kwzSQp45IF3buluS4YwbYITGkwA==", + "optionalDependencies": { + "@googlemaps/js-api-loader": "^1.16.6", + "leaflet": "^1.6.0" + } + }, "node_modules/leaflet-minimap": { "version": "3.6.1", "resolved": "https://registry.npmjs.org/leaflet-minimap/-/leaflet-minimap-3.6.1.tgz", @@ -5670,6 +5693,16 @@ "resolved": "https://registry.npmjs.org/leaflet-svg-shape-markers/-/leaflet-svg-shape-markers-1.4.0.tgz", "integrity": "sha512-vUBwso51+4ZVGcLZbhdBGxz+xrbul5jDYxool2yTKbIjAC6rvOMLjr8YBTQbLaa1LBRBQIaWUbmCafdXm17pxw==" }, + "node_modules/leaflet.measure": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/leaflet.measure/-/leaflet.measure-1.0.0.tgz", + "integrity": "sha512-bMjwxovMLo6kBCgS0XN+wALEzqjeuI/SzXF+X9/Th+FkO0av/tNcyNkqaOYPqOWZf+LdAqGjTEYr71V60NBLNw==" + }, + "node_modules/leaflet.polylinemeasure": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/leaflet.polylinemeasure/-/leaflet.polylinemeasure-3.0.0.tgz", + "integrity": "sha512-PTTHz7NBJiWmNFetH8hb3leQNM15qoM9Xe7VDKh1Hyat/M+USqFYeoa0A0LAecsqsjUqA63Rzux4SivoyrSFkA==" + }, "node_modules/leaflet.vectorgrid": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/leaflet.vectorgrid/-/leaflet.vectorgrid-1.3.0.tgz", @@ -6103,15 +6136,6 @@ "node": ">=8" } }, - "node_modules/lrm-graphhopper": { - "version": "1.3.0", - "resolved": "git+ssh://git@github.com/NSWSESMembers/lrm-graphhopper.git#eac8a99207cba06f45bf0f3098575493d20b6fa5", - "license": "ISC", - "dependencies": { - "corslite": "0.0.6", - "polyline": "0.0.3" - } - }, "node_modules/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -6649,15 +6673,6 @@ "integrity": "sha512-tXK8bY2l3/CPkyO7+UbOWbVjCpKoYY4t6uY3AYYy4Bagd4Z942gLeQOgtHICwBwgPf8dI6fw4VqKwzSNgvlw4A==", "deprecated": "This module has moved: please install @mapbox/point-geometry instead" }, - "node_modules/polyline": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/polyline/-/polyline-0.0.3.tgz", - "integrity": "sha512-kM9l6Zi5m8GxNH4VF2amQm64gP+RcdQZN7DzwqeYZT6ILyFRhjibRAgTnV9jsckzApRByPiVOtwna1/6fOLGYg==", - "deprecated": "This module is now under the @mapbox namespace: install @mapbox/polyline instead", - "engines": { - "node": "*" - } - }, "node_modules/popper.js": { "version": "1.16.1", "resolved": "https://registry.npmjs.org/popper.js/-/popper.js-1.16.1.tgz", @@ -6995,6 +7010,14 @@ "jsesc": "bin/jsesc" } }, + "node_modules/remove": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/remove/-/remove-0.1.5.tgz", + "integrity": "sha512-AJMA9oWvJzdTjwIGwSQZsjGQiRx73YTmiOWmfCp1fpLa/D4n7jKcpoA+CZiVLJqKcEKUuh1Suq80c5wF+L/qVQ==", + "dependencies": { + "seq": ">= 0.3.5" + } + }, "node_modules/require-from-string": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", @@ -7317,6 +7340,29 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true }, + "node_modules/seq": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/seq/-/seq-0.3.5.tgz", + "integrity": "sha512-sisY2Ln1fj43KBkRtXkesnRHYNdswIkIibvNe/0UKm2GZxjMbqmccpiatoKr/k2qX5VKiLU8xm+tz/74LAho4g==", + "dependencies": { + "chainsaw": ">=0.0.7 <0.1", + "hashish": ">=0.0.2 <0.1" + }, + "engines": { + "node": "*" + } + }, + "node_modules/seq/node_modules/chainsaw": { + "version": "0.0.9", + "resolved": "https://registry.npmjs.org/chainsaw/-/chainsaw-0.0.9.tgz", + "integrity": "sha512-nG8PYH+/4xB+8zkV4G844EtfvZ5tTiLFoX3dZ4nhF4t3OCKIb9UvaFyNmeZO2zOSmRWzBoTD+napN6hiL+EgcA==", + "dependencies": { + "traverse": ">=0.3.0 <0.4" + }, + "engines": { + "node": "*" + } + }, "node_modules/serialize-javascript": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.2.tgz", diff --git a/package.json b/package.json index 9e764ee5..5f89a5e8 100644 --- a/package.json +++ b/package.json @@ -53,14 +53,17 @@ "leaflet": "^1.9.4", "leaflet-easybutton": "^2.4.0", "leaflet-fullscreen": "git+https://github.com/Leaflet/Leaflet.fullscreen.git", + "leaflet-geosearch": "^4.2.2", "leaflet-minimap": "^3.6.1", "leaflet-routing-machine": "^3.2.12", "leaflet-svg-shape-markers": "^1.3.0", + "leaflet.measure": "^1.0.0", + "leaflet.polylinemeasure": "^3.0.0", "leaflet.vectorgrid": "^1.3.0", - "lrm-graphhopper": "git+https://github.com/NSWSESMembers/lrm-graphhopper.git", "markerwithlabel": "^2.0.2", "moment": "^2.29.1", "nunjucks": "^3.2.4", + "remove": "^0.1.5", "stopwords": "0.0.5", "xmldom": "^0.6.0" }, diff --git a/src/background.js b/src/background.js index d00ac3da..089b750e 100644 --- a/src/background.js +++ b/src/background.js @@ -91,20 +91,7 @@ chrome.webNavigation.onHistoryStateUpdated.addListener((details) => { chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { - if (request.type === 'asbestos') { - checkAsbestosRegister( - request.address, - function (result, colour, bool, url) { - sendResponse({ - result: result, - colour: colour, - resultbool: bool, - requrl: url, - }); - }, - ); - return true; - } else if (request.type === 'API_TOKEN_UPDATE') { + if (request.type === 'API_TOKEN_UPDATE') { let key = 'beaconAPIToken-' + request.host; chrome.storage.local .set({ key: JSON.stringify(request.token) }) @@ -728,212 +715,4 @@ function fetchEssentialEnergyOutages(callback) { }; callback(response); }); -} - -function checkAsbestosRegister(inAddressObject, cb) { - var AddressParts = /^(.+)\s(.+)$/.exec(inAddressObject.Street); - if (!inAddressObject.Flat) inAddressObject.Flat = ''; - var formAddress = - 'https://www.fairtrading.nsw.gov.au/loose-fill-asbestos-insulation-register?' + - 'unit=' + - encodeURI(inAddressObject.Flat) + - '&' + - 'number=' + - encodeURI(inAddressObject.StreetNumber) + - '&' + - 'street=' + - encodeURI(AddressParts[1]) + - '&' + - 'suburb=' + - encodeURI(inAddressObject.Locality) + - '&' + - 'type=' + - encodeURI(AddressParts[2]) + - '&'; - - console.log('loading cache'); - chrome.storage.local.get(['lighthouseFTCache']).then((ftCache) => { - console.log(ftCache); - - var needToWriteChange = false; - if (ftCache.length) { - //walk the cache and clean it up first - - var foundinCache = false; - ftCache.forEach(function (item) { - if (item.url == formAddress) { - console.log('found url in the cache'); - foundinCache = true; - console.log( - 'cache is ' + - (new Date().getTime() - new Date(item.timestamp).getTime()) / - 1000 / - 60 + - 'mins old', - ); - if ( - (new Date().getTime() - new Date(item.timestamp).getTime()) / - 1000 / - 60 < - 4320 - ) { - //3 days - //its in the cache - console.log('using it'); - processResult(item.result); - } else { - //oooooold - console.log('cached item is stale. fetching new result'); - ftCache.splice(ftCache.indexOf(item), 1); //remove this item from the cache - needToWriteChange = true; - pullFTRegister(function (result) { - if (result != 0) { - //dont cache error results - var cacheItem = {}; - cacheItem.url = formAddress; - cacheItem.timestamp = new Date().toString(); - cacheItem.result = result; - ftCache.push(cacheItem); - needToWriteChange = true; - } - //return result - processResult(result); - }); - } - } else { - if ( - (new Date().getTime() - new Date(item.timestamp).getTime()) / - 1000 / - 60 > - 4320 - ) { - //3 days - console.log( - 'cleaning stale cache item ' + - item.url + - ' age:' + - (new Date().getTime() - new Date(item.timestamp).getTime()) / - 1000 / - 60 + - 'mins old', - ); - ftCache.splice(ftCache.indexOf(item), 1); //remove this item from the cache - needToWriteChange = true; - } - } - }); - - if (foundinCache == false) { - console.log('did not find url in the cache'); - pullFTRegister(function (result) { - if (result != 0) { - //dont cache error results - var cacheItem = {}; - cacheItem.url = formAddress; - cacheItem.timestamp = new Date().toString(); - cacheItem.result = result; - ftCache.push(cacheItem); - needToWriteChange = true; - } - //return result - processResult(result); - }); - } - } else { - //there is no cache so make one - console.log('no cache object. creating a new one'); - ftCache = []; - pullFTRegister(function (result) { - if (result != 0) { - //dont cache error results - var cacheItem = {}; - cacheItem.url = formAddress; - cacheItem.timestamp = new Date().toString(); - cacheItem.result = result; - ftCache.push(cacheItem); - needToWriteChange = true; - } - //return result - processResult(result); - }); - } - - //if we never call processResult we should write the changes out here. - if (needToWriteChange) { - console.log('writing out lighthouseFTCache'); - localStorage.setItem('lighthouseFTCache', JSON.stringify(ftCache)); - } - - function processResult(result) { - switch (result) { - case 0: //error - console.log('Error searching'); - cb( - "Error Searching The Asbestos Register", - '', - false, - formAddress, - ); - break; - case 1: //positive/found - console.log('On the Register'); - cb( - inAddressObject.PrettyAddress + - " was FOUND on the loose fill insulation asbestos register", - 'red', - true, - formAddress, - ); - break; - case 2: //negative/not found - console.log('Not the Register'); - cb( - inAddressObject.PrettyAddress + ' was not found on any register.', - '', - false, - formAddress, - ); - break; - } - if (needToWriteChange) { - needToWriteChange = false; - console.log('writing out lighthouseFTCache'); - chrome.storage.local - .set({ lighthouseFTCache: JSON.stringify(ftCache) }) - .then(() => { - console.log('lighthouseFTCache is set'); - }); - } - } - - function pullFTRegister(cb) { - cb(2) //error out until FT fix their register - // fetch(formAddress) - // .then((resp) => { - // if (resp.ok) { - // resp.text().then((txt) => { - // if ( - // !/No\sMatch\sFound/.test(txt) && - // !/Confirmed\sMatch/.test(txt) - // ) { - // cb(0); //error - // } - // if (/Confirmed\sMatch/.test(txt)) { - // cb(1); //found - // } - // if (/No\sMatch\sFound/.test(txt)) { - // cb(2); //not found - // } - // }); - // } else { - // cb(0); //error - // } - // }) - // .catch(() => { - // cb(0); //fetch error - // }); - } - - - }); -} +} \ No newline at end of file diff --git a/src/contentscripts/jobs/create.js b/src/contentscripts/jobs/create.js index d6a99ff0..3b17a497 100644 --- a/src/contentscripts/jobs/create.js +++ b/src/contentscripts/jobs/create.js @@ -23,22 +23,7 @@ window.addEventListener("message", function(event) { } } - if (event.data.type && (event.data.type == "FROM_PAGE_FTASBESTOS_SEARCH")) { - chrome.runtime.sendMessage({type: "asbestos", address: event.data.address}, function(response) { - if (response.resultbool == false) - { - response.requrl = '' - } else { - window.postMessage({ type: "FROM_LH_ASBESTOS", result: true }, "*"); - } - asbestosBoxColor(response.result,response.colour,response.requrl) - }); - } else if (event.data.type && (event.data.type == "FROM_PAGE_SESASBESTOS_RESULT")) { - window.postMessage({ type: "FROM_LH_ASBESTOS", result: true }, "*"); - asbestosBoxColor(event.data.address.PrettyAddress+" was FOUND on the SES asbestos register.",'red','') - - - } else if (event.data.type && (event.data.type == "FROM_PAGE_LHQ_DISTANCE")) { + if (event.data.type && (event.data.type == "FROM_PAGE_LHQ_DISTANCE")) { if (distanceDebounceTimeout) { clearTimeout(distanceDebounceTimeout); } @@ -143,10 +128,33 @@ window.addEventListener("message", function(event) { //handle the drive rescue distances as an array of promises due to ajax calls to resolve them all for (let i = 0; i < 9; i++) { if (typeof _sortedRescueDistances[i] != "undefined") { + let from = [ + Number(_sortedRescueDistances[i].properties.POINT_X), + Number(_sortedRescueDistances[i].properties.POINT_Y) + ]; + let to = [ + Number(event.data.lng), + Number(event.data.lat) + ]; + let body = JSON.stringify({ + coordinates: [from, to], + travelMode: "Car" + }); + let promise = new Promise((resolve, reject) => { - $.getJSON(`https://graphhopper.lighthouse-extension.com/route?point=${_sortedRescueDistances[i].properties.POINT_Y},${_sortedRescueDistances[i].properties.POINT_X}&point=${event.data.lat},${event.data.lng}&instructions=false&type=json&key=lighthouse&ch.disable=true`, function (data) { - resolve({ unit: _sortedRescueDistances[i], distance: data.paths[0].distance / 1000 }); - }).fail((error) => reject(error)); + $.ajax({ + url: "https://lambda.lighthouse-extension.com/lad/route", + method: "POST", + contentType: "application/json", + data: body, + dataType: "json", + success: function(data) { + resolve({ unit: _sortedRescueDistances[i], distance: data?.[0]?.Summary?.Distance / 1000}); + }, + error: function(xhr, status, error) { + reject(error); + } + }); }); promises.push(promise); @@ -209,22 +217,6 @@ window.addEventListener("message", function(event) { } }, false); -function asbestosBoxColor(text, color, url) { - $('#asbestos-register-text').html(text); - if (url != '') - { - console.log("got url") - $('#asbestos-register-box').css('cursor','pointer'); - $('#asbestos-register-box').click(function(){ - window.open(url) - }) - } - if (color != "") { - $('#asbestos-register-box')[0].style.color = "white" - $('#asbestos-register-box').css({'background' :'linear-gradient(transparent 8px, '+color+' -10px','margin-left':'17px'}); - } -} - let myAvailability = (