Problem statement: 1. I want to read a local file based on user selection 2. Display the file content on the Text field of the current active page

Manifest

{
  "manifest_version": 2,

  "name": "Click to execute",
  "description": "Testing read file",
  "version": "1.0",

  "icons": {
    "48": "icon.png"
  },

  "permissions": [
    "tabs","all_urls","activeTab"
  ],

  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },

  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  
  "content_scripts": [
    {
    "matches": [
        "http://*/*",
        "https://*/*"
        ],
    "js": ["content.js"],
  "run_at": "document_end"
    }
]
  
}

popup.js

 
  function openfile1(event) {
    var input = event.target;
     var reader = new FileReader();
    reader.onload = function(){
      var text = reader.result;
      console.log(reader.result.substring(0, 200));
   displayintext(text);
  // alert("File Content----"+reader.result.substring(0, 500));
    };
     reader.readAsText(input.files[0]);
};
 
function displayintext(finalvalue)
{
 var f1 = finalvalue;
 alert("finalvalue   "+ f1);
 //chrome.tabs.executeScript(null, {code: "var Sbonus= getTextInControl("AH_5fOTHER_5fBONUS_5fGRAND_5fTOTAL"); alert(Sbonus);"});   
}
  document.getElementById('opentest').addEventListener('change', openfile1, false);

Content.js

/*
var Sbonus= getTextInControl("AH_5fOTHER_5fBONUS_5fGRAND_5fTOTAL");  
var SpliAmt = Sbonus /4;  
console.log(Sbonus);
setTextInControl("AH_5fOFFER_5fOTHER_5fBONUS_5fAMT_5f1",SpliAmt); 
setTextInControl("AH_5fOFFER_5fOTHER_5fBONUS_5fAMT_5f2",SpliAmt); 
setTextInControl("AH_5fOFFER_5fOTHER_5fBONUS_5fAMT_5f3",SpliAmt); 
setTextInControl("AH_5fOFFER_5fOTHER_5fBONUS_5fAMT_5f4",SpliAmt); 
console.log(SpliAmt);

i am completely new to chrome extension development. i am unable to get the code to working. the extension is able to read the file and display the content on the alert.

Now, i want to execute the content script to read the value of a text field from the current active page which is in content.js and paste the value from the previous file content on one of the text field.

Any help is greatly appreciated.

0

There are 0 answers