// Modules to control application life and create native browser window const {app, ipcMain, BrowserWindow, session} = require('electron') const path = require('path') const fs = require('fs') const request = require('request'); // 读取配置文件 let enterURL = 'http://cunchu.site/work/debug/index.html' let webConfig = { width: 376, height: 667, webPreferences: { webSecurity: false, nodeIntegration: true, nativeWindowOpen: false, contextIsolation: false }, autoHideMenuBar: true // 无边框 // frame: false, // 全屏 // fullscreen: true } // 判断是否有特殊配置文件 console.log(__dirname + "\\config.json") if (fs.existsSync("./config.json")) { webConfig = JSON.parse(fs.readFileSync('./config.json', 'utf-8')) enterURL = webConfig.enterURL } const codeMap = {"fc":"[re]","ep":"[Af]","rj":"[M_]","sp":"[sW]","ws":"[Pj]","mb":"[^~]","ww":"[Dp]","wh":"[ZH]","ph":"[b+]","hk":"[3b]","mc":"[%)]","fm":"[$4]","nm":"[T!]","ei":"[J3]","pd":"[(A]","ef":"[%t]","xf":"[n_]","na":"[W6]","mr":"[dn]","km":"[b*]","aw":"[#*]","sj":"[~6]","ry":"[t#]","sd":"[$R]","eh":"[!!]","wp":"[TE]","fy":"[s6]","ex":"[EE]","ce":"[PS]","xr":"[~z]","cj":"[xh]","am":"[(G]","kw":"[Nr]","hj":"[p@]","ia":"[jO]","mp":"[75]","py":"[6C]","hc":"[46]","sk":"[(8]","hp":"[SB]","my":"[pq]","wk":"[Xd]","bk":"[Q^]","ak":"[)J]","cw":"[ai]","ym":"[Te]","yh":"[Cd]","xb":"[R5]","yy":"[#H]","nt":"[4)]","bc":"[#J]","fe":"[2+]","ni":"[f@]","bb":"[!k]","jc":"[$Q]","an":"[m$]","ee":"[RH]","nn":"[n$]","jr":"[5F]","pp":"[JQ]","fx":"[86]","2":"[)h]","3":"[iL]","4":"[r2]","5":"[Ys]","6":"[7p]","7":"[!5]","8":"[@A]","A":"[_W]","B":"[Kt]","C":"[m#]","D":"[A!]","E":"[M!]","F":"[xG]","G":"[k@]","H":"[_!]","J":"[rP]","K":"[z#]","M":"[r$]","N":"[rN]","P":"[t$]","Q":"[3(]","R":"[fF]","S":"[H)]","T":"[J@]","W":"[83]","X":"[t5]","Y":"[T_]","Z":"[CT]","a":"[Jt]","b":"[Ks]","c":"[yn]","d":"[2r]","e":"[#2]","f":"[yM]","h":"[)m]","i":"[mx]","j":"[YV]","k":"[$j]","m":"[Xy]","n":"[Bk]","p":"[5$]","r":"[EH]","s":"[Pw]","t":"[j(]","w":"[p7]","x":"[a+]","y":"[B2]","z":"[4n]","~":"[~C]","!":"[iw]","@":"[SK]","#":"[Pf]","$":"[de]","%":"[3t]","^":"[H_]","&":"[WA]","*":"[!A]","(":"[z*]",")":"[)n]","_":"[&k]","+":"[*F]"} function owoReplaceAll(str, s1, s2) { while (str.indexOf(s1) >= 0) { str = str.replace(s1, s2) } return str } function owoDecode(itemStr) { for (let item in codeMap) { itemStr = owoReplaceAll(itemStr, codeMap[item], item) } while (itemStr.indexOf(']') >= 0) { itemStr = owoDecode(itemStr) } return itemStr } const xxx_filter = { urls: webConfig.redirect || [] } function createWindow () { // Create the browser window. // if (config.preload) { // console.log(config.preload) // webConfig.webPreferences.preload = config.preload // } console.log(webConfig) const mainWindow = new BrowserWindow(webConfig) // and load the index.html of the app. // mainWindow.loadFile('./resources/01.html') // mainWindow.webContents.userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Mobile/15E148 Safari/604.1 electron' // mainWindow.webContents.openDevTools() mainWindow.loadURL(enterURL) mainWindow.webContents.on("dom-ready", function() { // 代理 if (webConfig.proxy) { mainWindow.webContents.session.setProxy({ proxyRules: webConfig.proxy, proxyBypassRules: 'localhost', }, function () { console.log('代理设置完毕') }); } mainWindow.webContents.executeJavaScript(` var owoApp = 4 window.owoPC = true function loadScript(url, callback) { var script = document.createElement("script") script.type = "text/javascript"; if (script.readyState) { //IE script.onreadystatechange = function () { if (script.readyState == "loaded" || script.readyState == "complete") { script.onreadystatechange = null; if (callback) callback(); } }; } else { //Others script.onload = function () { if (callback) callback(); }; } script.src = url; var head = document.head || document.getElementsByTagName('head')[0]; head.appendChild(script); } function loadJsCode(code){ var script = document.createElement('script'); script.type = 'text/javascript'; //for Chrome Firefox Opera Safari script.appendChild(document.createTextNode(code)); //for IE //script.text = code; document.body.appendChild(script); } function loadCSS (url) { var link = document.createElement("link"); link.rel = "stylesheet"; link.type = "text/css"; link.href = url; document.getElementsByTagName("head")[0].appendChild(link); } // 拦截请求 loadScript('//cunchu.site/work/assist/ajaxhook.min.js') let needLoad = localStorage.getItem('needLoad') needLoad = null function owoReload (data) { data.forEach(element => { if (element.type == 'app') { let scriptList = element.script if (typeof scriptList == 'string') { scriptList = JSON.parse(scriptList) } if (typeof element.style == 'string') { element.style = JSON.parse(element.style) } scriptList.forEach(scriptItem => { loadScript(scriptItem) }); element.style.forEach(styleItem => { loadCSS(styleItem) }); if (element.data) loadJsCode(element.data) } }); } if (needLoad) { owoReload(JSON.parse(needLoad)) } else { fetch("https://going.run/assist?route=app", { method: 'POST', headers: { "Content-Type": "application/json" }, body: JSON.stringify({ "url": location.href, "edition": 1 }), redirect: 'follow' }).then(response => response.json()) .then(result => { if (result['err'] == 0) { owoReload(result['data']) localStorage.setItem('needLoad', JSON.stringify(result['data'])) } }) .catch(error => console.log('error', error)) } `); }); // Open the DevTools. } // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.whenReady().then(() => { session.defaultSession.webRequest.onBeforeRequest(xxx_filter, (details, callback) => { callback({ redirectURL: webConfig.redirectURL}); }) // 判断是否无缓存 if (webConfig.noCache) { console.log('无缓存模式!') if (!webConfig.webPreferences) webConfig.webPreferences = {} webConfig.webPreferences.partition = 'persist:Session' + Math.round(Math.random()*100000) } createWindow() app.on('activate', function () { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (BrowserWindow.getAllWindows().length === 0) createWindow() }) }) // Quit when all windows are closed, except on macOS. There, it's common // for applications and their menu bar to stay active until the user quits // explicitly with Cmd + Q. app.on('window-all-closed', function () { if (process.platform !== 'darwin') app.quit() }) // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and require them here. ipcMain.on("getData", (event, message) => { // 控制台打印一下知道来了 console.log(message); var options = { 'method': 'GET', 'url': owoDecode(message.url), 'headers': message.headers }; request(options, function (error, response) { if (error) throw new Error(error); event.returnValue = response.body }); }) ipcMain.on("postData", (event, message) => { // 控制台打印一下知道来了 console.log(message); var options = { 'method': 'POST', 'url': owoDecode(message.url), 'headers': message.headers, 'body': message.body }; request(options, function (error, response) { if (error) throw new Error(error); event.returnValue = response.body }); })