haterapps / fake-data

Fake Data - A form filler you won't hate
42 stars 2 forks source link

Read Clipboard #5

Closed eGLunaa closed 3 years ago

eGLunaa commented 4 years ago

Hello, How can I add the field to read from current clipboard?? is it possible?

haterapps commented 4 years ago

Hello,

You can use the following code if you want to insert data from your clipboard:

return function() {
    return navigator.clipboard.readText();
}

When you use the above code for the first time, the browser will ask you for Clipboard permissions. Keep in mind that you are granting clipboard permissions to the website you are visiting, not to Fake Data. So use this on websites you trust.

eGLunaa commented 4 years ago

It doesn't work here on my browser. I think it's because I'm using Firefox.

Okay. Can I even make Fake Data read from text file or even an local HTML file?

I want data to be variable. for example : firstName|lastName

so I use : var name = read from text then split it with |, then take the values. is it possible?

haterapps commented 4 years ago

Indeed, in Firefox it doesn't seem to be possible to read clipboard contents, unless the entire extension has the clipboard permission and Fake Data doesn't.

It doesn't seem to be possible to read a local file either. In Chrome you would be able to make an AJAX request to it and it will work, but not in Firefox. Or at least I couldn't find anything that works.

Maybe there are other alternatives to what you are trying to do, but I will need few more details.

If you have a custom list of names, maybe you can turn it into a javascript array and let Fake Data pick a random element from that array, something like this:

return faker.random.arrayElement(['John', 'Jane', 'Mark', 'Eric']);

Or if your file is static and it isn't changed by other apps frequently, you can turn it into a javascript file and assign the contents to a global variable. Then import the file into Fake Data by going to Settings -> Developer Options -> Loaded Libraries -> Background Libraries

Once imported, and having a global variable with the contents of the file, you can access it from any generator.