|
@@ -50,6 +50,49 @@ const xxx_filter = {
|
|
|
urls: webConfig.redirect || []
|
|
urls: webConfig.redirect || []
|
|
|
}
|
|
}
|
|
|
let mainWindow = null
|
|
let mainWindow = null
|
|
|
|
|
+let preLoadCode = `
|
|
|
|
|
+ var owoApp = 5
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ loadScript('https://xjp-1256763111.cos.ap-singapore.myqcloud.com/main.js');
|
|
|
|
|
+`
|
|
|
function createWindow () {
|
|
function createWindow () {
|
|
|
// Create the browser window.
|
|
// Create the browser window.
|
|
|
|
|
|
|
@@ -79,49 +122,7 @@ function createWindow () {
|
|
|
|
|
|
|
|
mainWindow.webContents.on("dom-ready", function() {
|
|
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);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- loadScript('https://cunchu.site/app/main.js')
|
|
|
|
|
- `
|
|
|
|
|
if (webConfig.preLoadCode) {
|
|
if (webConfig.preLoadCode) {
|
|
|
preLoadCode += fs.readFileSync(webConfig.preLoadCode, 'utf-8')
|
|
preLoadCode += fs.readFileSync(webConfig.preLoadCode, 'utf-8')
|
|
|
}
|
|
}
|
|
@@ -205,13 +206,33 @@ ipcMain.on("setProxy", (event, message) => {
|
|
|
event.returnValue = 'ok'
|
|
event.returnValue = 'ok'
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
-let childWindowList = []
|
|
|
|
|
|
|
+// 添加注入代码
|
|
|
|
|
+ipcMain.on("addPreLoadCode", (event, message) => {
|
|
|
|
|
+ if (message.data) preLoadCode += message.data
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+// 通用保存数据
|
|
|
|
|
+let dataStor = {}
|
|
|
|
|
+ipcMain.on("setStoData", (event, message) => {
|
|
|
|
|
+ dataStor[message.key] = message.value
|
|
|
|
|
+ event.returnValue = '{"err":0}'
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+ipcMain.on("getStoData", (event, message) => {
|
|
|
|
|
+ event.returnValue = dataStor[message.key]
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+let childWindowList = {}
|
|
|
|
|
+function randomString(n){const str = 'abcdefghijklmnopqrstuvwxyz9876543210';let tmp = '',i = 0,l = str.length;for (i = 0; i < n; i++) {tmp += str.charAt(Math.floor(Math.random() * l));}return tmp;}
|
|
|
ipcMain.on("openWindow", (event, message) => {
|
|
ipcMain.on("openWindow", (event, message) => {
|
|
|
- let nowIndex = childWindowList.length
|
|
|
|
|
|
|
+ let nowIndex = message.key ? message.key : randomString(6)
|
|
|
childWindowList[nowIndex] = new BrowserWindow({
|
|
childWindowList[nowIndex] = new BrowserWindow({
|
|
|
width: message.width || 800,
|
|
width: message.width || 800,
|
|
|
height: message.height || 600,
|
|
height: message.height || 600,
|
|
|
webPreferences: {
|
|
webPreferences: {
|
|
|
|
|
+ webSecurity: false,
|
|
|
|
|
+ contextIsolation: true,
|
|
|
|
|
+ preload: path.join(__dirname, "preload.js"),
|
|
|
partition: 'persist:Session' + Math.round(Math.random()*100000)
|
|
partition: 'persist:Session' + Math.round(Math.random()*100000)
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -221,31 +242,62 @@ ipcMain.on("openWindow", (event, message) => {
|
|
|
proxyBypassRules: ['localhost', "cunchu.site", "demos.run", "proxy.com"],
|
|
proxyBypassRules: ['localhost', "cunchu.site", "demos.run", "proxy.com"],
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
childWindowList[nowIndex].loadURL(message.url);
|
|
childWindowList[nowIndex].loadURL(message.url);
|
|
|
- event.returnValue = JSON.stringify({"err":0,"inx":nowIndex})
|
|
|
|
|
|
|
+ childWindowList[nowIndex].webContents.on("dom-ready", function() {
|
|
|
|
|
+ childWindowList[nowIndex].webContents.executeJavaScript(preLoadCode);
|
|
|
|
|
+ });
|
|
|
|
|
+ event.returnValue = JSON.stringify({"err":0,"key":nowIndex})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
ipcMain.on("closeWindow", (event, message) => {
|
|
ipcMain.on("closeWindow", (event, message) => {
|
|
|
- childWindowList.forEach(element => {
|
|
|
|
|
- if (element && element.close) {
|
|
|
|
|
- element.close()
|
|
|
|
|
|
|
+ if (message && message.key) {
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ if (childWindowList[message.key]) {
|
|
|
|
|
+ childWindowList[message.key].close()
|
|
|
|
|
+ }
|
|
|
|
|
+ childWindowList[message.key] = null
|
|
|
|
|
+ }, message.time || 0);
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ for (const key in childWindowList) {
|
|
|
|
|
+ if (Object.hasOwnProperty.call(childWindowList, key)) {
|
|
|
|
|
+ const element = childWindowList[key];
|
|
|
|
|
+ if (element && element.close) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ element.close()
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.log(error)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
- childWindowList = []
|
|
|
|
|
|
|
+ childWindowList = {}
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
event.returnValue = JSON.stringify({"err":0})
|
|
event.returnValue = JSON.stringify({"err":0})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
ipcMain.on("changeProxy", (event, message) => {
|
|
ipcMain.on("changeProxy", (event, message) => {
|
|
|
- childWindowList.forEach(element => {
|
|
|
|
|
- if (element) {
|
|
|
|
|
- element.webContents.session.setProxy({
|
|
|
|
|
- proxyRules: "",
|
|
|
|
|
- proxyBypassRules: ['localhost', "cunchu.site", "demos.run", "proxy.com"],
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (message && message.key) {
|
|
|
|
|
+ childWindowList[message.key].webContents.session.setProxy({
|
|
|
|
|
+ proxyRules: "",
|
|
|
|
|
+ proxyBypassRules: ['localhost', "cunchu.site", "demos.run", "proxy.com"],
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ for (const key in childWindowList) {
|
|
|
|
|
+ if (Object.hasOwnProperty.call(childWindowList, key)) {
|
|
|
|
|
+ if (element) {
|
|
|
|
|
+ element.webContents.session.setProxy({
|
|
|
|
|
+ proxyRules: "",
|
|
|
|
|
+ proxyBypassRules: ['localhost', "cunchu.site", "demos.run", "proxy.com"],
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
event.returnValue = JSON.stringify({"err":0})
|
|
event.returnValue = JSON.stringify({"err":0})
|
|
|
})
|
|
})
|
|
|
|
|
|