add osm nav userscript to calculate co2 eq
This commit is contained in:
parent
c7117abc34
commit
8c3c479f88
@ -4,7 +4,7 @@
|
|||||||
// et lancer ce script dans la console js pour avoir à la fin un tableau de toutes les séquences.
|
// et lancer ce script dans la console js pour avoir à la fin un tableau de toutes les séquences.
|
||||||
|
|
||||||
// ouvrir le drawer de séquene key
|
// ouvrir le drawer de séquene key
|
||||||
function toggle_advanced_info () {
|
function toggle_advanced_info() {
|
||||||
let _dots = document.querySelector('.i2.three-dots')
|
let _dots = document.querySelector('.i2.three-dots')
|
||||||
_dots.click
|
_dots.click
|
||||||
}
|
}
|
||||||
@ -31,9 +31,13 @@ function click_block_number (num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function add_sequence_id () {
|
function add_sequence_id () {
|
||||||
|
check_annoying_modal()
|
||||||
let id_sequence_container = document.querySelector('.content > div:nth-child(1) > div:nth-child(2) > app-copy-field:nth-child(2) > div:nth-child(1) > div:nth-child(1)')
|
let id_sequence_container = document.querySelector('.content > div:nth-child(1) > div:nth-child(2) > app-copy-field:nth-child(2) > div:nth-child(1) > div:nth-child(1)')
|
||||||
id = id_sequence_container.innerText
|
id = id_sequence_container.innerText
|
||||||
|
|
||||||
|
if(sequences_list.indexOf(id) === -1){
|
||||||
|
console.log('déjà présent: ', id)
|
||||||
|
}
|
||||||
sequences_list.push(id)
|
sequences_list.push(id)
|
||||||
console.log('sequence id', id)
|
console.log('sequence id', id)
|
||||||
|
|
||||||
@ -44,8 +48,10 @@ function check_annoying_modal(){
|
|||||||
if (has_annoying_modal) {
|
if (has_annoying_modal) {
|
||||||
|
|
||||||
has_annoying_modal.click()
|
has_annoying_modal.click()
|
||||||
toggle_advanced_info()
|
let t = setTimeout(() => {
|
||||||
|
toggle_advanced_info()
|
||||||
|
clearInterval(t)
|
||||||
|
}, 100)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,9 +94,13 @@ function iterate_blocks (initial_block = 0, max_block, waiting = 400) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// toggle_advanced_info()
|
|
||||||
// on définit un max d'itérations à 20 pour tester, et 300 milisecondes entre chaque
|
|
||||||
iterate_blocks(0, 25, 600)
|
|
||||||
|
|
||||||
// compter
|
// compter
|
||||||
document.querySelectorAll('drawer-sequence-item')
|
document.querySelectorAll('drawer-sequence-item')
|
||||||
|
|
||||||
|
|
||||||
|
// toggle_advanced_info()
|
||||||
|
// on définit un max d'itérations à 20 pour tester, et 300 milisecondes entre chaque
|
||||||
|
// iterate_blocks(4, document.querySelectorAll('drawer-sequence-item').length + 4, 1000)
|
||||||
|
iterate_blocks(30, 60, 600)
|
||||||
|
// add_sequence_id()
|
||||||
|
filter_sequences_id()
|
||||||
|
64
osm-itineraire-userscript/index.html
Normal file
64
osm-itineraire-userscript/index.html
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Véhicule</th>
|
||||||
|
<th>CO2 kg eq.</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>Avion</td>
|
||||||
|
<td class="text-right">${emissionsByMode.avion.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Bus thermique</td>
|
||||||
|
<td class="text-right">${emissionsByMode.bus.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Moto</td>
|
||||||
|
<td class="text-right">${emissionsByMode.moto.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Scooter</td>
|
||||||
|
<td class="text-right">${emissionsByMode.scoot.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Voiture</td>
|
||||||
|
<td class="text-right">${emissionsByMode.voiture.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Voiture électrique ⚡</td>
|
||||||
|
<td class="text-right">${emissionsByMode.voiture_elec.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>🚴 Vélo Electrique ⚡</td>
|
||||||
|
<td class="text-right">${emissionsByMode.velo_elec.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>🚇 Métro</td>
|
||||||
|
<td class="text-right">${emissionsByMode.tgv.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>TGV</td>
|
||||||
|
<td class="text-right">${emissionsByMode.tgv.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>🚴 Vélo ou marche</td>
|
||||||
|
<td>0</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<div class="source-data">
|
||||||
|
<a href="https://agirpourlatransition.ademe.fr/particuliers/bureau/deplacements/calculer-emissions-carbone-trajets">
|
||||||
|
|
||||||
|
infos ADEME
|
||||||
|
</a>
|
||||||
|
<i>
|
||||||
|
Sont incluses les émissions directes, la construction des véhicules (fabrication, maintenance et fin de vie) et
|
||||||
|
la production et distribution de carburant et d'électricité. La construction des infrastructures (routes, rails,
|
||||||
|
aéroports...) n'est pas incluse.
|
||||||
|
</i>
|
||||||
|
<a href="https://raw.githubusercontent.com/incubateur-ademe/monimpacttransport/main/src/data/transportations.json">json</a>
|
||||||
|
</div>
|
183
osm-itineraire-userscript/index.js
Normal file
183
osm-itineraire-userscript/index.js
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
// ==UserScript==
|
||||||
|
// @name Comparatif carbone OSM itinéraire
|
||||||
|
// @version 1
|
||||||
|
// @grant none
|
||||||
|
// ==/UserScript==
|
||||||
|
|
||||||
|
/**
|
||||||
|
* comparatif des empreintes carbones sur un itinéraire fait sur OSM.org
|
||||||
|
* @type {{bus: number, voiture_elec: number, tgv: number, voiture: number, velo_elec: number, avion: number}}
|
||||||
|
*/
|
||||||
|
|
||||||
|
const coefficients = {
|
||||||
|
avion_condens: 0.285*3,
|
||||||
|
avion: 0.285,
|
||||||
|
voiture: 0.218,
|
||||||
|
scoot: 0.062,
|
||||||
|
moto: 0.191,
|
||||||
|
bus: 0.0352,
|
||||||
|
voiture_elec: 0.103,
|
||||||
|
velo_elec: 0.01,
|
||||||
|
metro: 0.004,
|
||||||
|
tgv: 0.003,
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDistanceFromElement () {
|
||||||
|
const sidebarContent = document.getElementById('sidebar_content')
|
||||||
|
if (!sidebarContent) {
|
||||||
|
console.warn('Impossible de trouver l’élément #sidebar_content.')
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const paragraphs = sidebarContent.querySelectorAll('p')
|
||||||
|
for (const para of paragraphs) {
|
||||||
|
if (para.innerText.includes('Distance')) {
|
||||||
|
const indexOfKm = para.innerText.indexOf('km')
|
||||||
|
let text = para.innerText
|
||||||
|
let boom = text.trim().split(' ')
|
||||||
|
|
||||||
|
console.log('para.innerText', para.innerText)
|
||||||
|
const distance = parseFloat(boom[1])
|
||||||
|
return distance
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.warn('Impossible de trouver la distance dans les paragraphes.')
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculateEmissionsAndDisplay (distance) {
|
||||||
|
if (!distance) {
|
||||||
|
console.warn('La distance est undefined ou null.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const emissionsByMode = {
|
||||||
|
avion_condens: distance * coefficients.avion_condens,
|
||||||
|
avion: distance * coefficients.avion,
|
||||||
|
bus: distance * coefficients.bus,
|
||||||
|
moto: distance * coefficients.moto,
|
||||||
|
scoot: distance * coefficients.scoot,
|
||||||
|
voiture: distance * coefficients.voiture,
|
||||||
|
voiture_elec: distance * coefficients.voiture_elec,
|
||||||
|
tgv: distance * coefficients.tgv,
|
||||||
|
velo_elec: distance * coefficients.velo_elec,
|
||||||
|
}
|
||||||
|
|
||||||
|
let textCompare = `<div class="impact-climat">
|
||||||
|
<style>
|
||||||
|
.impact-climat{
|
||||||
|
text-align: right;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<h3>Impact climatique:</h3>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Véhicule</th>
|
||||||
|
<th>CO2 kg eq.</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>Avion condensation inclue</td>
|
||||||
|
<td class="text-right">${emissionsByMode.avion_condens.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Avion</td>
|
||||||
|
<td class="text-right">${emissionsByMode.avion.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Bus thermique</td>
|
||||||
|
<td class="text-right">${emissionsByMode.bus.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Moto</td>
|
||||||
|
<td class="text-right">${emissionsByMode.moto.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Scooter</td>
|
||||||
|
<td class="text-right">${emissionsByMode.scoot.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Voiture</td>
|
||||||
|
<td class="text-right">${emissionsByMode.voiture.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Voiture électrique ⚡</td>
|
||||||
|
<td class="text-right">${emissionsByMode.voiture_elec.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>🚴 Vélo Electrique ⚡</td>
|
||||||
|
<td class="text-right">${emissionsByMode.velo_elec.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>🚇 Métro</td>
|
||||||
|
<td class="text-right">${emissionsByMode.tgv.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>TGV</td>
|
||||||
|
<td class="text-right">${emissionsByMode.tgv.toFixed(1)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>🚴 Vélo ou marche</td>
|
||||||
|
<td>0</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div class="source-data">
|
||||||
|
<a href="https://agirpourlatransition.ademe.fr/particuliers/bureau/deplacements/calculer-emissions-carbone-trajets">
|
||||||
|
|
||||||
|
infos ADEME
|
||||||
|
</a>
|
||||||
|
<i>
|
||||||
|
Émissions de gaz à effet de serre (GES) pour une personne sur cette distance, en équivalent CO2. Voyager à plusieurs divise les émissions de GES.<br>
|
||||||
|
Sont incluses les émissions directes, la construction des véhicules (fabrication, maintenance et fin de vie) et
|
||||||
|
la production et distribution de carburant et d'électricité. La construction des infrastructures (routes, rails,
|
||||||
|
aéroports...) n'est pas incluse.
|
||||||
|
</i>
|
||||||
|
<a href="https://raw.githubusercontent.com/incubateur-ademe/monimpacttransport/main/src/data/transportations.json">json</a>
|
||||||
|
</div>
|
||||||
|
</div>`
|
||||||
|
|
||||||
|
let comparison_container = document.querySelector('#comparison_container')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* on ajoute la div si elle manque
|
||||||
|
*/
|
||||||
|
if (!comparison_container) {
|
||||||
|
const comparisonContainerAdd = document.createElement('div')
|
||||||
|
comparisonContainerAdd.setAttribute('id', 'comparison_container')
|
||||||
|
|
||||||
|
const sidebarContainer = document.getElementById('sidebar_content')
|
||||||
|
sidebarContainer.insertBefore(comparisonContainerAdd, sidebarContainer.children[0]);
|
||||||
|
|
||||||
|
comparison_container = document.querySelector('#comparison_container')
|
||||||
|
|
||||||
|
}
|
||||||
|
// on remplit les infos actualisées
|
||||||
|
comparison_container.innerHTML = textCompare
|
||||||
|
console.log('comparison_container', comparison_container.innerText)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function main () {
|
||||||
|
const distance = getDistanceFromElement()
|
||||||
|
if (distance) {
|
||||||
|
calculateEmissionsAndDisplay(distance)
|
||||||
|
} else {
|
||||||
|
setTimeout(() => {
|
||||||
|
const distance = getDistanceFromElement()
|
||||||
|
if (distance) {
|
||||||
|
calculateEmissionsAndDisplay(distance)
|
||||||
|
}
|
||||||
|
}, 5000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('hashchange', () => main())
|
||||||
|
document.addEventListener('DOMContentLoaded', () => main())
|
||||||
|
document.addEventListener('mouseup', () => main())
|
||||||
|
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user