@@ -2,71 +2,125 @@ global.browser = require('webextension-polyfill')
22const Excel = require ( "exceljs" ) ; // https://github.com/exceljs/exceljs
33import { saveAs } from 'file-saver' ;
44
5- chrome . browserAction . onClicked . addListener ( function ( a ) {
6- chrome . windows . getCurrent ( function ( a ) {
7- parentWindowId = a . id
8- } ) ;
9-
10- // Parse: Table ID and URL
11- window . open ( chrome . extension . getURL ( "popup/popup.html?tabid=" + encodeURIComponent ( a . id ) + "&url=" + encodeURIComponent ( a . url ) ) , "Excel Fill" , "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=660,height=1040,top=0,left=960" )
12- } ) ;
13-
14- chrome . tabs . onUpdated . addListener ( function ( tabId , changeInfo , tab ) {
15- if ( changeInfo . status == "complete" ) {
16-
17- // Action Page Settings
18- var actionURLs = "objectVal__allActionSite" ;
19- // Site Excel Columns
20- var siteColumns = "objectVal__siteExcelColumns" ;
21- // Excel JSON Data
22- var excelJSONData = "objectVal__excelSheetJSONData" ;
23-
24- // Get Data
25- chrome . storage . local . get ( [ actionURLs , excelJSONData , siteColumns ] , function ( k ) {
26- if ( k [ actionURLs ] !== undefined && k [ actionURLs ] !== null ) {
27- var url = k [ actionURLs ] ;
28- if ( url !== null && url . length > 0 ) {
29- // console.log("Tab Option: ", tab)
30- // console.log("Action URLs", url)
31-
32- // Site Excel Column Data
33- if ( k [ siteColumns ] !== undefined && k [ siteColumns ] !== null && siteColumns . length > 0 ) {
34- // Excel JSON Data
35- if ( k [ excelJSONData ] !== undefined && k [ excelJSONData ] !== null && Object . keys ( k [ excelJSONData ] ) . length > 0 ) {
36- var excelJSONObj = k [ excelJSONData ] ;
37- if ( excelJSONObj . obj !== undefined && excelJSONObj . obj . length > 0 ) {
38-
39- // Execute Script
40- chrome . tabs . executeScript ( tabId , {
41- file : '/script/run.js' ,
42- } , function ( ) {
43- if ( chrome . runtime . lastError ) {
44- console . error ( chrome . runtime . lastError . message ) ;
45- }
46- } ) ;
47-
48- } else {
49- console . error ( "Excel JSON Data Not Found!" ) ;
50- }
5+ function checkTabURLMatch ( tabId , tabURL ) {
6+
7+ // Action Page Settings
8+ var actionURLs = "objectVal__allActionSite" ;
9+ // Site Excel Columns
10+ var siteColumns = "objectVal__siteExcelColumns" ;
11+ // Excel JSON Data
12+ var excelJSONData = "objectVal__excelSheetJSONData" ;
13+
14+ // Get Data
15+ chrome . storage . local . get ( [ actionURLs , excelJSONData , siteColumns ] , function ( k ) {
16+ if ( k [ actionURLs ] !== undefined && k [ actionURLs ] !== null ) {
17+ var url = k [ actionURLs ] ;
18+ if ( url !== null && url . length > 0 ) {
19+
20+ // console.log("Tab Option: ", tab)
21+ // console.log("Action URLs", url)
22+
23+ // Site Excel Column Data
24+ if ( k [ siteColumns ] !== undefined && k [ siteColumns ] !== null && siteColumns . length > 0 ) {
25+ // Excel JSON Data
26+ if ( k [ excelJSONData ] !== undefined && k [ excelJSONData ] !== null && Object . keys ( k [ excelJSONData ] ) . length > 0 ) {
27+ var excelJSONObj = k [ excelJSONData ] ;
28+ if ( excelJSONObj . obj !== undefined && excelJSONObj . obj . length > 0 ) {
29+
30+ // Execute Script
31+ chrome . tabs . executeScript ( tabId , {
32+ file : '/script/run.js' ,
33+ } , function ( ) {
34+ if ( chrome . runtime . lastError ) {
35+ console . error ( chrome . runtime . lastError . message ) ;
36+ }
37+ } ) ;
5138
5239 } else {
53- console . error ( "Excel JSON Object Not Found!" ) ;
40+ console . error ( "Excel JSON Data Not Found!" ) ;
5441 }
5542
5643 } else {
57- console . error ( "Action Site Excel Columns Data Not Found. " ) ;
44+ console . error ( "Excel JSON Object Not Found! " ) ;
5845 }
5946
6047 } else {
61- console . error ( "Action URL Key Not Found" ) ;
48+ console . error ( "Action Site Excel Columns Data Not Found. " ) ;
6249 }
50+
51+ } else {
52+ console . error ( "Action URL Key Not Found" ) ;
53+ }
54+ } else {
55+ console . error ( "Action URLs Key Not Found" ) ;
56+ }
57+ } ) ;
58+ }
59+
60+ /**
61+ * If click extension icon
62+ */
63+ chrome . browserAction . onClicked . addListener ( function ( a ) {
64+ chrome . windows . getCurrent ( function ( a ) {
65+ parentWindowId = a . id
66+ } ) ;
67+
68+ // Parse: Table ID and URL
69+ window . open ( chrome . extension . getURL ( "popup/popup.html?tabid=" + encodeURIComponent ( a . id ) + "&url=" + encodeURIComponent ( a . url ) ) , "Excel Fill" , "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=660,height=1040,top=0,left=960" )
70+ } ) ;
71+
72+ /**
73+ * App Status Check :: checkbox value get
74+ */
75+ function appStatusCheck ( ) {
76+ chrome . storage . local . get ( 'valFillExcel_appStatus' , function ( budget ) {
77+ if ( budget . valFillExcel_appStatus === undefined ) {
78+ chrome . browserAction . setIcon ( { path : "icons/icon_48.png" } ) ;
79+ } else {
80+ if ( budget . valFillExcel_appStatus === true ) {
81+ chrome . browserAction . setIcon ( { path : "icons/icon_48.png" } ) ;
6382 } else {
64- console . error ( "Action URLs Key Not Found" ) ;
83+ chrome . browserAction . setIcon ( { path : "icons/icon_disable.png" } ) ;
84+ }
85+ }
86+ } ) ;
87+ } appStatusCheck ( ) ;
88+
89+ /**
90+ * keyboard shortcuts that trigger actions in your extension
91+ */
92+ chrome . commands . onCommand . addListener ( function ( command , tab ) {
93+ // console.log("TCL: command", command)
94+ // console.log("tab", tab)
95+ // console.log("tab", tab.url)
96+
97+ // Start/Pause Application
98+ if ( command == "start-stop-app-excel-fill" ) {
99+ chrome . storage . local . get ( 'valFillExcel_appStatus' , function ( budget ) {
100+ if ( budget . valFillExcel_appStatus === true ) {
101+ chrome . storage . local . set ( { 'valFillExcel_appStatus' : false } ) ;
102+ }
103+ else {
104+ chrome . storage . local . set ( { 'valFillExcel_appStatus' : true } ) ;
105+ // Again RUN Script (Again Fill Form Data)
106+ checkTabURLMatch ( tab . id , tab . url )
65107 }
108+ appStatusCheck ( ) ;
66109 } ) ;
67110 }
68111} ) ;
69112
113+ /**
114+ * Tabs
115+ */
116+ chrome . tabs . onUpdated . addListener ( function ( tabId , changeInfo , tab ) {
117+ if ( changeInfo . status == "complete" ) {
118+
119+ // Check URL Than RUN Script
120+ checkTabURLMatch ( tab . id , tab . url )
121+ }
122+ } ) ;
123+
70124/**
71125 * Copy Field Address
72126 */
@@ -225,9 +279,9 @@ function onCopyElement(option, tab) {
225279 sheetDoc . getCell ( cellAddress ) . font = { family : 4 , size : 11 , bold : true } ;
226280 // Set cell to wrap-text
227281 sheetDoc . getCell ( cellAddress ) . alignment = { vertical : 'middle' , horizontal : 'center' , wrapText : true } ;
228- }
282+ }
229283 }
230-
284+
231285 // Second Sheet: Second Row for field value
232286 if ( field . value !== undefined ) {
233287 if ( typeof ( field . value ) === "object" && field . value . length > 0 ) {
@@ -250,7 +304,7 @@ function onCopyElement(option, tab) {
250304 startRow ++
251305 } ) ;
252306 }
253-
307+
254308 } else {
255309 const row = sheetDoc . getRow ( 2 ) ;
256310 row . getCell ( fieldKey ) . value = field . value
0 commit comments