-1

I have an evernote web url

https://www.evernote.com/shard/s5/client/snv?noteGuid=18fd15e2-9581-47db-8140-0b94dc3b9f96&noteKey=6846ea69a9afa4f5

I want to convert it with javascript to a desktop app url

evernote:///view/s5/18fd15e2-9581-47db-8140-0b94dc3b9f96/18fd15e2-9581-47db-8140-0b94dc3b9f96/

the question boils down to how can I get the id following noteGuid= and before &noteKey

EDIT

I found a neat way to parse out the noteGuid

var noteGuid = location.search.match(new RegExp("noteGuid" + "=(.*?)($|\&)", "i"))[1];
Justin Lin
  • 673
  • 1
  • 6
  • 15
  • There should be many existing questions on site about how to parse query parameters out of a url – Taplar Jan 15 '21 at 22:11

1 Answers1

0

Just use .substring() and indexOf()

var input = document.getElementsByTagName("input")[0];
function getParameter(startAt, endAt){
  var val = input.value;
  var id = val.substring(val.indexOf(startAt)+startAt.length+1, val.indexOf(endAt));
  var url = "evernote:///view/s5/"+id+"/";
  console.log(url);
}
<input value="https://www.evernote.com/shard/s5/client/snv?noteGuid=18fd15e2-9581-47db-8140-0b94dc3b9f95&noteKey=6846ea69a9afa4f5"><button onclick="getParameter('?noteGuid', '&noteKey')">Parse</button>

You can use window.location to retrieve the current URL.

Spectric
  • 30,714
  • 6
  • 20
  • 43