| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- // 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');
- const download = require('download');
- // 读取配置文件
- let enterURL = 'https://demos.run/debuger/index.html'
- let webConfig = {
- width: 376,
- height: 667,
- webPreferences: {
- webSecurity: false,
- contextIsolation: true,
- preload: path.join(__dirname, "preload.js")
- },
- 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 || []
- }
- let mainWindow = null
- function createWindow () {
- // Create the browser window.
-
- // if (config.preload) {
- // console.log(config.preload)
- // webConfig.webPreferences.preload = config.preload
- // }
- if (!webConfig.webPreferences.preload) webConfig.webPreferences.preload = path.join(__dirname, "preload.js")
- console.log(webConfig)
- mainWindow = new BrowserWindow(webConfig)
- // 代理
- if (webConfig.proxy) {
- mainWindow.webContents.session.setProxy({
- proxyRules: webConfig.proxy,
- proxyBypassRules: 'localhost',
- }, function () {
- console.log('代理设置完毕')
- });
- }
- if (enterURL.startsWith('http')) {
- mainWindow.loadURL(enterURL)
- } else {
- console.log(path.join(__dirname, enterURL))
- mainWindow.loadFile(path.join(__dirname, enterURL))
- }
- mainWindow.webContents.on("dom-ready", function() {
- let preLoadCode = `
- var owoApp = 4
- window.owoPC = true
- window.electronConfig = ${JSON.stringify(webConfig)};
-
- 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);
- }
-
- let needLoad_App = null
- if (window && window.localStorage) {
- needLoad_App = localStorage.getItem('needLoad_App')
- }
- 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_App) {
- owoReload(JSON.parse(needLoad_App))
- } else {
- fetch("https://going.run/assist?route=app&username=${webConfig.username}", {
- 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_App', JSON.stringify(result['data']))
- }
- })
- .catch(error => console.log('error', error))
- }
- `
- if (webConfig.preLoadCode) {
- preLoadCode += fs.readFileSync(webConfig.preLoadCode, 'utf-8')
- }
- // console.log(preLoadCode)
- mainWindow.webContents.executeJavaScript(preLoadCode);
- });
- // 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,
- strictSSL: false
- };
- 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,
- strictSSL: false
- };
- request(options, function (error, response) {
- if (error) throw new Error(error);
- event.returnValue = response.body
- });
- })
- ipcMain.on("setProxy", (event, message) => {
- var win = new BrowserWindow({width: 800, height: 1500});
- mainWindow.webContents.session.setProxy({
- proxyRules: message.url,
- proxyBypassRules: 'localhost',
- });
- event.returnValue = 'ok'
- })
- let childWindowList = []
- ipcMain.on("openWindow", (event, message) => {
- let nowIndex = childWindowList.length
- childWindowList[nowIndex] = new BrowserWindow({
- width: message.width || 800,
- height: message.height || 600,
- webPreferences: {
- partition: 'persist:Session' + Math.round(Math.random()*100000)
- }
- });
- if (message.proxy) {
- childWindowList[nowIndex].webContents.session.setProxy({
- proxyRules: message.proxy,
- proxyBypassRules: ['localhost', "cunchu.site", "demos.run", "proxy.com"],
- });
- }
-
- childWindowList[nowIndex].loadURL(message.url);
- event.returnValue = JSON.stringify({"err":0,"inx":nowIndex})
- })
- ipcMain.on("closeWindow", (event, message) => {
- childWindowList.forEach(element => {
- if (element && element.close) {
- element.close()
- }
- });
- childWindowList = []
- event.returnValue = JSON.stringify({"err":0})
- })
- ipcMain.on("changeProxy", (event, message) => {
- childWindowList.forEach(element => {
- if (element) {
- element.webContents.session.setProxy({
- proxyRules: "",
- proxyBypassRules: ['localhost', "cunchu.site", "demos.run", "proxy.com"],
- });
- }
- });
- event.returnValue = JSON.stringify({"err":0})
- })
- ipcMain.on("readConfig", (event, message) => {
- if (fs.existsSync("./config.json")) {
- event.returnValue = JSON.parse(fs.readFileSync('./config.json', 'utf-8'))
- } else {
- event.returnValue = {}
- }
- })
- ipcMain.on("saveConfig", (event, message) => {
- fs.writeFileSync('./config.json', JSON.stringify(message))
- event.returnValue = {err: 0}
- })
- ipcMain.on("download", (event, message) => {
- download(message.url, message.path, {
- filename: message.filename,
- });
- event.returnValue = {err: 0}
- })
|