(function(){ const ele = require('electron'); const app = ele.app; const brw = ele.BrowserWindow; const ipm = ele.ipcMain; const dia = ele.dialog; var wins = brw.getAllWindows(); var bwi = wins[0]; var mwi = wins[1]; var bwc = bwi.webContents; var bse = bwc.session; var mwc = mwi.webContents; var mse = mwc.session; var info = null; /* object containing the dealer info and inventory */ var eba = null; /* ebay account */ var ebp = null; /* ebay password */ var item = null; /* the selected car */ var sitem = null; var times = 0; var ql = null; /* to determine if they are using the quick listing tool or not */ /* clear both caches just in case */ bse.clearCache(function(){ console.log('bcc'); }); mse.clearCache(function(){ console.log('mcc'); }); /* object to return */ var ebs = new Object(); /* ebay script */ ebs.start = function(sentInfo, sentItem){ info = sentInfo; item = sentItem; sitem = JSON.stringify(item); sitem = JSON.stringify(item); mwi.loadURL('https://signin.ebay.com/ws/eBayISAPI.dll?SellItem'); var etitle; /*ebay title*/ mwc.once('did-finish-load', function(){ etitle = mwc.getTitle().toLowerCase(); if (etitle.includes('sign in')){ login(); /* fills user and pass, clicks sign in */ } else { /*dia.showErrorBox('navigation error', 'please restart the program');*/ /* need to do a custom menu item at some point */ }; }); mwc.on('did-finish-load', function(){ etitle = mwc.getTitle().toLowerCase(); }); mwc.on('did-finish-load', function(){ etitle = mwc.getTitle().toLowerCase(); console.log(etitle); console.log(times); times++; if(etitle == 'sell on ebay'){ ql = true; qlRoutine(); } else if (etitle.includes('select a category')){ category(); /* all this has to do is fill title */ } else if (etitle.includes('tell us what')){ fillVIN(); /* fills vin, clicks get started */ /* will possibly need to check for div id 'ymmteLyr' this is a trim picking form */ } else if (etitle.includes('electronics')){ mwi.loadURL('http://cgi5.ebay.com/ws/eBayISAPI.dll?aidZ153=&MfcISAPICommand=SellHub3'); } else if (etitle.includes('market and format')){ auction(); /* needs to pick auction or fixed price */ } else if (etitle.includes('title and description')){ description(); /* must transfer html template */ } else if (etitle.includes('pictures and details')){ pictures(); } else if (etitle.includes('payment and shipping')){ payment(); } else if (etitle.includes('review and submit')){ review(); } else if (etitle.includes('ebay motors - sell')){ finalPage(); } else { /*dia.showErrorBox('navigation error', 'please restart the program');*/ /* need to do a custom menu item at some point */ }; }); }; function login(){ console.log('from log in fn'); eba = JSON.parse(info.parameters.accounts)[0].login; ebp = JSON.parse(info.parameters.accounts)[0].password; /* string of code to be executed */ var str = "console.log('from the string of login fn');" +"document.getElementById('userid').value = '" + eba + "';" + "document.getElementById('pass').value = '" + ebp + "';" + "document.getElementById('sgnBt').click();"; mwc.executeJavaScript(str); mwc.once('did-finish-load', function(){ console.log('from login did finish load'); if(mwc.getTitle().toLowerCase().includes('sign in')){ console.log('from if'); dia.showErrorBox('ebay credentials incorrect', 'you must fix this to procede'); } else { console.log('from else'); mwi.loadURL('http://cgi5.ebay.com/ws/eBayISAPI.dll?aidZ153=&MfcISAPICommand=SellHub3'); }; }); }; function qlRoutine(){ console.log('qlRoutine'); var adTitle = item.year + ' ' + item.make + ' ' + item.model + ' ' + item.trim; var str = "console.log('from teh qlRoutine str');" + "try {" + "if(document.getElementById('keywords') !== null){" + "document.getElementById('keywords').value = '" + adTitle + "';" + "} else {" + "console.log('from before try');" + "try{" + "var item = " + sitem + ";" /*+ "item = JSON.parse(item);"*/ + "document.getElementById('lnkRTESwitch').click();" + "document.getElementById('description').value = item.ebayAd.toString();" /*+ "document.getElementById('lnkRTESwitch').click();"*/ + "} catch(e) {" + "console.log(e);" + "}" +"}" + "} catch(e) {" + "console.log(e);" + "}"; mwc.executeJavaScript(str); } function fillVIN(){ console.log('from fillVIN'); var VIN = item.vin; var str = "console.log('from fill vin str');" + "document.getElementById('keywordst').value = '" + VIN + "';"; /*+ "document.getElementById('aidZ4').click();";*/ mwc.executeJavaScript(str); } function category(){ console.log('from the category fn'); var adTitle = item.year + ' ' + item.make + ' ' + item.model + ' ' + item.trim; var str = "document.getElementById('keywords').value = '" + adTitle + "';"; mwc.executeJavaScript(str); }; function auction(){ console.log('on auction page'); }; function description(){ console.log('from description fn'); var adTitle = item.year + ' ' + item.make + ' ' + item.model + ' ' + item.trim; var str = "console.log('from the description str');" + "setTimeout(function(){" + "var item = " + sitem + ";" + "if(document.getElementById('htmlMode') !== null){" + "console.log('its there');" + "document.getElementById('htmlMode').click();" + "if(item.ebayAd !== undefined){" + "console.log('ebayAd is there');" + " } else { " + "console.log('something is wrong with the item'); }" + "} else { console.log('not there');}" + "var thisFrame = document.getElementById('rte').contentWindow.document.body;" + "thisFrame.innerText = item.ebayAd.toString();" +"}, 2000);"; mwc.executeJavaScript(str); mwc.on('did-navigate-in-page', function(){ console.log('did-navigate-in-page'); }); }; function pictures(){ console.log('on pics page'); }; function payment(){ console.log('on payment page'); } function review(){ console.log('on review page'); }; function finalPage(){ console.log('on fiinal page'); }; return ebs; })();