0

I am pretty new in Tampermonkey Javascript and inherited below script to create a button and hoping to select a file upon click.

However, the import data button is not showing in https://test.com/*. I have tested alert("hi"); code in https://test.com/* and it is working fine. Can somebody help me with the solution? What is wrong with the code? Or is it me since I'm noob :) Thank you very much in advance.

// ==UserScript==
// @name         Test Tampermonkey Script
// @version      0.1
// @description  Test
// @author       Me
// @match        https://test.com/*
// @grant        GM_xmlhttpRequest
// @grant        GM_info
// ==/UserScript==

(function() {
'use strict';

function importData() {
let input = document.createElement('input');
input.type = 'file';
input.onchange = _ => {
// you can use this method to get file and perform respective operations
        let files =   Array.from(input.files);
        console.log(files);
    };
input.click();

}
})();
JoeCastro
  • 59
  • 5
  • Does this answer your question? [Programmatically trigger "select file" dialog box](https://stackoverflow.com/questions/8595389/programmatically-trigger-select-file-dialog-box) – Konrad Jan 15 '23 at 11:33
  • [Yes, you can programmatically click the input element using jQuery/JavaScript, but only if you do it in an event handler belonging to an event THAT WAS STARTED BY THE USER!](https://stackoverflow.com/a/21583865) – Konrad Jan 15 '23 at 11:33
  • You also never call `inportData` – Konrad Jan 15 '23 at 11:33
  • Hi @Konrad, thank you for the link however, am i suppose to use this? input id="myInput" type="file" style="visibility:hidden" /> – JoeCastro Jan 15 '23 at 16:08

0 Answers0