0

I'll apologize in advance for being a newb, I'm pretty new to the world of programming so show some mercy XD

I'm trying to make a script that will copy only the account name from the top browser URL but I've hit a brick wall on this part.

const regex = /account\/(.*)\/#photos/gm;
const str = `https://internal.DUMMYSITE.com/compliance/account/ACCOUNTNAME/#photos`;
let m = regex.exec(str);

var dummy = document.createElement(m),
    text = window.location.href;

document.body.appendChild(dummy);
dummy.value = text;
dummy.select();
document.execCommand('copy');
document.body.removeChild(dummy);

So it works fine for the most part, in my actual code I've used a random URL that follows the format and the "ACCOUNTNAME" part is actually a real account name. Every time I run the code it copies the text that I've added on the account name.

What am I doing wrong?

I'll thank everyone in advance, cheers!

mesnapie
  • 11
  • 2
  • Are you asking how to just get the ACCOUNTNAME text? If so its in `m[1]`. Note you pass `m` to `createElement()` but that won't work as neither `m` nor `m[1]` is a valid element name. – Alex K. Feb 01 '21 at 15:33
  • Yes I'm asking exactly that, I only need the text, I simply add [1] to createElement? or did I understand that incorrectly? – mesnapie Feb 01 '21 at 15:49
  • I would use an existing solution, E.g.: https://stackoverflow.com/a/33928558/246342 – Alex K. Feb 01 '21 at 15:54
  • Thanks for providing the post but which code exactly, like I said I'm a newb and I would very much appreciate it if you could paste the one here xD – mesnapie Feb 01 '21 at 16:02
  • https://jsfiddle.net/Lacytqfm/1/ – Alex K. Feb 01 '21 at 16:07
  • Massive thanks! – mesnapie Feb 01 '21 at 16:07
  • Aight so it would appear that I have the same problem, I added all the code but it copies the same account name that is present in the URL. To give you some context. I'm supposed to review accounts, I copy the account name from the URL in chrome and paste it to my system. The URL will change very often so I need a script that will copy the account name. Hope we can find a solution, cheers! – mesnapie Feb 01 '21 at 16:19
  • I must also add that I'm using AutoControl and I've added a shortcut hotkey to the code, so per se, I'll be pressing CTRL+E to instantly copy the accountname – mesnapie Feb 01 '21 at 16:22

0 Answers0