I want to use a travel planner making full use of Firefox' Keyword Searches.
The keyword search basically just inputs a string somewhere in a predefined URL, e.g. google.com/search?q=%s
with cats and dogs
will go to https://www.google.com/search?hl=en&q=cats%20and%20dogs
.
Q1: However, the URL needs the (current) date, so this needs to be entered variably as well.
Because we need a starting location and final location we need to enter two search string, which is possible (explained here).
Q2: I would also like to be able to e.g. enter 'h' for my home address.
The URL format of the travel planner is as follows:
https://www.ns.nl/reisplanner/#/?vertrek=STARTLOCATION%20Centraal&vertrektype=treinstation&aankomst=ENDLOCATION&aankomsttype=treinstation&type=vertrek&tijd=2023-03-03T15:59&firstMileModality=PUBLIC_TRANSPORT&lastMileModality=PUBLIC_TRANSPORT&disabledTransportModalities=
I currently have:
javascript:var%C2%A0s='%s';
url='https://www.ns.nl/reisplanner/#/?vertrek=%s&vertrektype=treinstation&aankomst=%s&aankomsttype=treinstation&type=vertrek&tijd=currentDateInRightFormat&firstMileModality=PUBLIC_TRANSPORT&lastMileModality=PUBLIC_TRANSPORT&disabledTransportModalities=';
const h='My Home Street 1 My Home Town'
const w='My Work Street 1 Work City'
const currentDateInRightFormat = new Date(new Date().toString().split('GMT')[0]+' UTC').toISOString().split('.')[0].slice(0,16));
t='';
qc=0;
chunks=url.split('%s');
for(i=0; i<s.length; i++){
if(s.charAt(i)=='%22')qc=qc^1;
t+=((s.charAt(i)==' '&&qc)?'^':s.charAt(i));
}
args=t.split(/\s/);
nurl='';
for(i=0; i<chunks.length; i++){
nurl+=chunks[i];
if(args[i]!=undefined)%C2%A0{
args[i]=args[i].replace(/\^/g,' ');
nurl+=args[i];
}
}
location.replace(nurl,'< BR>');
So I would like to be able to:
- enter the currentDateInRightFormat in the URL
- use the string 'h' which then inputs my predefined home address, string 'w' for work, etc.
Given that I do not believe you are able to read the address bar content using Javascript the closest I came to doing what I think you are trying (?) to do was as follows:
When added to the Firefox bookmarklet doodah thingy it is then invoked by typing the
keyword
in the address bar and then supplying content when prompted -h
andw
can be used and will be substituted for the defined values ofhome
andwork
. The default values are already set ashome
andwork
for start/endNot speaking dutch or knowing locations to use I am not 100% sure that this is functioning as hoped