Comparing version 1.0.9 to 1.0.10
1346
index.js
@@ -1,745 +0,821 @@ | ||
String.prototype.test = function matchRuleShort(reg) { | ||
return new RegExp(reg).test(this); | ||
function escape(s) { | ||
if (!s) { | ||
return ''; | ||
} | ||
if (typeof s !== 'string') { | ||
s = s.toString(); | ||
} | ||
return s.replace(/[\/\\^$*+?.()\[\]{}]/g, '\\$&'); | ||
} | ||
String.prototype.like = function matchRuleShort(rule) { | ||
rule = rule.replace('.', '\.') | ||
return new RegExp("^" + rule.split("*").join(".*") + "$", "gium").test(this); | ||
if (!String.prototype.test) { | ||
Object.defineProperty(String.prototype, 'test', { | ||
value: function (reg, flag = 'gium') { | ||
try { | ||
return new RegExp(reg, flag).test(this); | ||
} catch (error) { | ||
return false; | ||
} | ||
}, | ||
}); | ||
} | ||
String.prototype.contains = function (name) { | ||
return this.like('*' + name + '*') | ||
if (!String.prototype.like) { | ||
Object.defineProperty(String.prototype, 'like', { | ||
value: function (name) { | ||
if (!name) { | ||
return false; | ||
} | ||
name = name.split('*'); | ||
name.forEach((n, i) => { | ||
name[i] = escape(n); | ||
}); | ||
name = name.join('.*'); | ||
return this.test('^' + name + '$', 'gium'); | ||
}, | ||
}); | ||
} | ||
if (!String.prototype.contains) { | ||
Object.defineProperty(String.prototype, 'contains', { | ||
value: function (name) { | ||
if (!name) { | ||
return false; | ||
} | ||
return this.test('^.*' + escape(name) + '.*$', 'gium'); | ||
}, | ||
}); | ||
} | ||
const browser = {} | ||
const browser = {}; | ||
module.exports = function (op) { | ||
console.log('new ibrowser ...................................'); | ||
if (browser.ready) { | ||
// console.log('IBrowser Ready Back ...') | ||
return browser; | ||
} else { | ||
browser.ready = true; | ||
} | ||
if (browser.ready) { | ||
// console.log('IBrowser Ready Back ...') | ||
return browser | ||
} else { | ||
browser.ready = true | ||
} | ||
browser.op = op || { | ||
is_social: false, | ||
is_window: false, | ||
is_main: false, | ||
is_render: false, | ||
}; | ||
browser.op = op || { | ||
is_social: false, | ||
is_window: false, | ||
is_main: false, | ||
is_render: false | ||
} | ||
if (browser.op.message) { | ||
console.log(browser.op.message); | ||
} | ||
if (browser.op.message) { | ||
console.log(browser.op.message) | ||
} | ||
if (browser.op.is_render) { | ||
// console.log('ibrowser From Render Process') | ||
} else { | ||
console.log('ibrowser From Main Process'); | ||
} | ||
if (browser.op.is_render) { | ||
// console.log('ibrowser From Render Process') | ||
} else { | ||
console.log('ibrowser From Main Process') | ||
} | ||
browser.require = function (name) { | ||
require(name)(browser); | ||
}; | ||
browser.require = function (name) { | ||
require(name)(browser) | ||
} | ||
if (!browser.electron) { | ||
browser.electron = browser.op.electron || require('electron'); | ||
} | ||
if (!browser.electron) { | ||
browser.electron = browser.op.electron || require('electron') | ||
} | ||
browser.url = require('url'); | ||
browser.fs = require('fs'); | ||
browser.path = require('path'); | ||
browser.md5 = require('md5'); | ||
browser.os = require('os'); | ||
browser.child_process = require('child_process'); | ||
browser.url = require('url') | ||
browser.fs = require('fs') | ||
browser.path = require('path') | ||
browser.md5 = require('md5') | ||
browser.run = function (file) { | ||
browser.spawn(process.argv[0], file); | ||
}; | ||
require(__dirname + '/lib/file.js')(browser) | ||
require(__dirname + '/lib/fn.js')(browser) | ||
browser.spawn = function (program, file) { | ||
console.log(`child process started ...`); | ||
console.log(file); | ||
let child_process = browser.child_process.spawn(program, file); | ||
child_process.stdout.on('data', function (data) { | ||
console.log(data.toString()); | ||
}); | ||
browser.dir = process.resourcesPath + '/app.asar' | ||
if (!browser.fs.existsSync(browser.dir)) { | ||
browser.dir = process.cwd() | ||
} | ||
child_process.stderr.on('data', (data) => { | ||
console.error(data.toString()); | ||
}); | ||
child_process.on('close', (code) => { | ||
console.log(`child process exited with code ${code}`); | ||
console.log(file); | ||
}); | ||
browser.is_render = browser.op.is_render | ||
browser.is_social = browser.op.is_social | ||
browser.files_dir = browser.dir + '/browser_files' | ||
browser.var = {} | ||
browser.default_var = {} | ||
child_process.on('message', (msg) => { | ||
console.log(msg); | ||
}); | ||
return child_process; | ||
}; | ||
if (browser.op.is_main) { | ||
console.log(browser.electron.app.getPath('home')) | ||
require(__dirname + '/lib/file.js')(browser); | ||
require(__dirname + '/lib/fn.js')(browser); | ||
browser.data_dir = browser.electron.app.getPath('home') || browser.electron.app.getPath('userData') | ||
if (!browser.data_dir) { | ||
browser.data_dir = browser.path.join(process.cwd(), '/../social-data') | ||
} | ||
if (process.cwd().like('*portal')) { | ||
browser.data_dir = browser.path.join(process.cwd(), '/social-data') | ||
} | ||
browser.electron.app.setPath('userData', browser.path.join(browser.data_dir, 'default')) | ||
browser.mkdirSync(browser.data_dir) | ||
browser.mkdirSync(browser.path.join(browser.data_dir, 'default')) | ||
browser.mkdirSync(browser.path.join(browser.data_dir, 'json')) | ||
browser.mkdirSync(browser.path.join(browser.data_dir, 'logs')) | ||
browser.mkdirSync(browser.path.join(browser.data_dir, 'favicons')) | ||
} else { | ||
browser.data_dir = browser.path.dirname(browser.electron.remote.app.getPath('userData')) | ||
} | ||
browser.dir = process.resourcesPath + '/app.asar'; | ||
if (!browser.fs.existsSync(browser.dir)) { | ||
browser.dir = process.cwd(); | ||
} | ||
browser.is_render = browser.op.is_render; | ||
browser.is_social = browser.op.is_social; | ||
browser.files_dir = browser.dir + '/browser_files'; | ||
browser.var = {}; | ||
browser.default_var = {}; | ||
browser.content_list = []; | ||
if (browser.op.is_main) { | ||
require(__dirname + '/lib/ipc.js')(browser); | ||
require(__dirname + '/lib/session.js')(browser); | ||
browser.force_update = false | ||
browser.get_var = function (name) { | ||
let path = browser.path.join(browser.data_dir, 'json', name + '.json') | ||
let default_path = browser.path.join(browser.dir, 'browser_files', 'json', name + '.json') | ||
if (browser.op.is_main && (browser.force_update || !browser.fs.existsSync(path))) { | ||
console.log(`\n Updating var ${name} \n `) | ||
let handle = false | ||
if (browser.fs.existsSync(path)) { | ||
handle = true | ||
} | ||
if (name == "user_data_input") { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || [] | ||
let data = browser.parseJson(browser.readFileSync(path)) || [] | ||
browser.data_dir = browser.electron.app.getPath('home') || browser.electron.app.getPath('userData'); | ||
if (!browser.data_dir) { | ||
browser.data_dir = browser.path.join(process.cwd(), '/../social-data'); | ||
} else { | ||
browser.data_dir += '/social-data'; | ||
} | ||
if (process.cwd().like('*portal')) { | ||
browser.data_dir = browser.path.join(process.cwd(), '/social-data'); | ||
} | ||
browser.electron.app.setPath('userData', browser.path.join(browser.data_dir, 'default')); | ||
browser.electron.app.setPath('crashDumps', browser.path.join(browser.data_dir, 'crashes')); | ||
default_data.forEach(d => { | ||
let exists = false | ||
data.forEach(d2 => { | ||
if (d.id == d2.id) { | ||
d2 = d | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.push(d) | ||
} | ||
}) | ||
browser.var[name] = data | ||
browser.set_var(name, browser.var[name]) | ||
} else { | ||
let content = browser.readFileSync(default_path) | ||
browser.var[name] = content ? browser.parseJson(content) : {} | ||
browser.set_var(name, browser.var[name]) | ||
} | ||
} else if (name == "user_data") { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || [] | ||
let data = browser.parseJson(browser.readFileSync(path)) || [] | ||
browser.electron.crashReporter.start({ | ||
compress: true, | ||
submitURL: 'https://your-domain.com/url-to-submit', | ||
}); | ||
default_data.forEach(d => { | ||
let exists = false | ||
data.forEach(d2 => { | ||
if (d.id == d2.id) { | ||
d2 = d | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.push(d) | ||
} | ||
}) | ||
browser.var[name] = data | ||
browser.set_var(name, browser.var[name]) | ||
} else { | ||
let content = browser.readFileSync(default_path) | ||
browser.var[name] = content ? browser.parseJson(content) : {} | ||
browser.set_var(name, browser.var[name]) | ||
} | ||
} else if (name == "urls") { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || [] | ||
let data = browser.parseJson(browser.readFileSync(path)) || [] | ||
browser.mkdirSync(browser.data_dir); | ||
browser.mkdirSync(browser.path.join(browser.data_dir, 'default')); | ||
browser.mkdirSync(browser.path.join(browser.data_dir, 'crashes')); | ||
browser.mkdirSync(browser.path.join(browser.data_dir, 'json')); | ||
browser.mkdirSync(browser.path.join(browser.data_dir, 'logs')); | ||
browser.mkdirSync(browser.path.join(browser.data_dir, 'favicons')); | ||
browser.mkdirSync(browser.path.join(browser.data_dir, 'pdf')); | ||
} else { | ||
browser.data_dir = browser.path.dirname(browser.electron.remote.app.getPath('userData')); | ||
} | ||
default_data.forEach(d => { | ||
let exists = false | ||
data.forEach(d2 => { | ||
if (d.url == d2.url) { | ||
d2 = d | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.push(d) | ||
} | ||
}) | ||
browser.var[name] = data | ||
browser.set_var(name, browser.var[name]) | ||
} else { | ||
let content = browser.readFileSync(default_path) | ||
browser.var[name] = content ? browser.parseJson(content) : {} | ||
browser.set_var(name, browser.var[name]) | ||
} | ||
} else if (name == "download_list") { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || [] | ||
let data = browser.parseJson(browser.readFileSync(path)) || [] | ||
browser.force_update = false; | ||
browser.get_var = function (name) { | ||
let path = browser.path.join(browser.data_dir, 'json', name + '.json'); | ||
let default_path = browser.path.join(browser.dir, 'browser_files', 'json', name + '.json'); | ||
default_data.forEach(d => { | ||
let exists = false | ||
data.forEach(d2 => { | ||
if (d.url == d2.url) { | ||
d2 = d | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.push(d) | ||
} | ||
}) | ||
browser.var[name] = data | ||
browser.set_var(name, browser.var[name]) | ||
} else { | ||
let content = browser.readFileSync(default_path) | ||
browser.var[name] = content ? browser.parseJson(content) : {} | ||
browser.set_var(name, browser.var[name]) | ||
} | ||
} else if (name == "black_list") { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || [] | ||
let data = browser.parseJson(browser.readFileSync(path)) || [] | ||
if (browser.op.is_main && (browser.force_update || !browser.fs.existsSync(path))) { | ||
console.log(`\n Updating var ${name} \n `); | ||
let handle = false; | ||
if (browser.fs.existsSync(path)) { | ||
handle = true; | ||
} | ||
default_data.forEach(d => { | ||
let exists = false | ||
data.forEach(d2 => { | ||
if (d.url == d2.url) { | ||
d2 = d | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.push(d) | ||
} | ||
}) | ||
browser.var[name] = data | ||
browser.set_var(name, browser.var[name]) | ||
} else { | ||
let content = browser.readFileSync(default_path) | ||
browser.var[name] = content ? browser.parseJson(content) : {} | ||
browser.set_var(name, browser.var[name]) | ||
} | ||
} else if (name == "white_list") { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || [] | ||
let data = browser.parseJson(browser.readFileSync(path)) || [] | ||
if (name == 'user_data_input') { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || []; | ||
let data = browser.parseJson(browser.readFileSync(path)) || []; | ||
default_data.forEach(d => { | ||
let exists = false | ||
data.forEach(d2 => { | ||
if (d.url == d2.url) { | ||
d2 = d | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.push(d) | ||
} | ||
}) | ||
browser.var[name] = data | ||
browser.set_var(name, browser.var[name]) | ||
} else { | ||
let content = browser.readFileSync(default_path) | ||
browser.var[name] = content ? browser.parseJson(content) : {} | ||
browser.set_var(name, browser.var[name]) | ||
} | ||
} else if (name == "proxy_list") { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || [] | ||
let data = browser.parseJson(browser.readFileSync(path)) || [] | ||
default_data.forEach((d) => { | ||
let exists = false; | ||
data.forEach((d2) => { | ||
if (d.id == d2.id) { | ||
d2 = d; | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.push(d); | ||
} | ||
}); | ||
browser.var[name] = data; | ||
browser.set_var(name, browser.var[name]); | ||
} else { | ||
let content = browser.readFileSync(default_path); | ||
browser.var[name] = content ? browser.parseJson(content) : {}; | ||
browser.set_var(name, browser.var[name]); | ||
} | ||
} else if (name == 'user_data') { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || []; | ||
let data = browser.parseJson(browser.readFileSync(path)) || []; | ||
default_data.forEach(d => { | ||
let exists = false | ||
data.forEach(d2 => { | ||
if (d.url == d2.url) { | ||
d2 = d | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.push(d) | ||
} | ||
}) | ||
browser.var[name] = data | ||
browser.set_var(name, browser.var[name]) | ||
} else { | ||
let content = browser.readFileSync(default_path) | ||
browser.var[name] = content ? browser.parseJson(content) : {} | ||
browser.set_var(name, browser.var[name]) | ||
} | ||
} else if (name == "login") { | ||
if (handle) { | ||
let content = browser.readFileSync(path) | ||
browser.var[name] = content ? browser.parseJson(content) : {} | ||
} else { | ||
let content = browser.readFileSync(default_path) | ||
browser.var[name] = content ? browser.parseJson(content) : {} | ||
browser.set_var(name, browser.var[name]) | ||
} | ||
} else if (name == "open_list") { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || [] | ||
let data = browser.parseJson(browser.readFileSync(path)) || [] | ||
default_data.forEach((d) => { | ||
let exists = false; | ||
data.forEach((d2) => { | ||
if (d.id == d2.id) { | ||
d2 = d; | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.push(d); | ||
} | ||
}); | ||
browser.var[name] = data; | ||
browser.set_var(name, browser.var[name]); | ||
} else { | ||
let content = browser.readFileSync(default_path); | ||
browser.var[name] = content ? browser.parseJson(content) : {}; | ||
browser.set_var(name, browser.var[name]); | ||
} | ||
} else if (name == 'urls') { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || []; | ||
let data = browser.parseJson(browser.readFileSync(path)) || []; | ||
default_data.forEach(d => { | ||
let exists = false | ||
data.forEach(d2 => { | ||
if (d.url == d2.url) { | ||
d2 = d | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.push(d) | ||
} | ||
}) | ||
browser.var[name] = data | ||
browser.set_var(name, browser.var[name]) | ||
} else { | ||
let content = browser.readFileSync(default_path) | ||
browser.var[name] = content ? browser.parseJson(content) : {} | ||
browser.set_var(name, browser.var[name]) | ||
} | ||
} else if (name == "youtube") { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || [] | ||
let data = browser.parseJson(browser.readFileSync(path)) || [] | ||
default_data.forEach((d) => { | ||
let exists = false; | ||
data.forEach((d2) => { | ||
if (d.url == d2.url) { | ||
d2 = d; | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.push(d); | ||
} | ||
}); | ||
browser.var[name] = data; | ||
browser.set_var(name, browser.var[name]); | ||
} else { | ||
let content = browser.readFileSync(default_path); | ||
browser.var[name] = content ? browser.parseJson(content) : {}; | ||
browser.set_var(name, browser.var[name]); | ||
} | ||
} else if (name == 'download_list') { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || []; | ||
let data = browser.parseJson(browser.readFileSync(path)) || []; | ||
default_data.blocking.selector.forEach(d => { | ||
let exists = false | ||
data.blocking.selector.forEach(d2 => { | ||
if (d == d2) { | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.blocking.selector.push(d) | ||
} | ||
}) | ||
default_data.forEach((d) => { | ||
let exists = false; | ||
data.forEach((d2) => { | ||
if (d.url == d2.url) { | ||
d2 = d; | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.push(d); | ||
} | ||
}); | ||
browser.var[name] = data; | ||
browser.set_var(name, browser.var[name]); | ||
} else { | ||
let content = browser.readFileSync(default_path); | ||
browser.var[name] = content ? browser.parseJson(content) : {}; | ||
browser.set_var(name, browser.var[name]); | ||
} | ||
} else if (name == 'black_list') { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || []; | ||
let data = browser.parseJson(browser.readFileSync(path)) || []; | ||
default_data.forEach((d) => { | ||
let exists = false; | ||
data.forEach((d2) => { | ||
if (d.url == d2.url) { | ||
d2 = d; | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.push(d); | ||
} | ||
}); | ||
browser.var[name] = data; | ||
browser.set_var(name, browser.var[name]); | ||
} else { | ||
let content = browser.readFileSync(default_path); | ||
browser.var[name] = content ? browser.parseJson(content) : {}; | ||
browser.set_var(name, browser.var[name]); | ||
} | ||
} else if (name == 'white_list') { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || []; | ||
let data = browser.parseJson(browser.readFileSync(path)) || []; | ||
default_data.blocking.words.forEach(d => { | ||
let exists = false | ||
data.blocking.words.forEach(d2 => { | ||
if (d.text == d2.text) { | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.blocking.words.push(d) | ||
} | ||
}) | ||
default_data.forEach((d) => { | ||
let exists = false; | ||
data.forEach((d2) => { | ||
if (d.url == d2.url) { | ||
d2 = d; | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.push(d); | ||
} | ||
}); | ||
browser.var[name] = data; | ||
browser.set_var(name, browser.var[name]); | ||
} else { | ||
let content = browser.readFileSync(default_path); | ||
browser.var[name] = content ? browser.parseJson(content) : {}; | ||
browser.set_var(name, browser.var[name]); | ||
} | ||
} else if (name == 'proxy_list') { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || []; | ||
let data = browser.parseJson(browser.readFileSync(path)) || []; | ||
browser.var[name] = data | ||
browser.set_var(name, browser.var[name]) | ||
} else { | ||
let content = browser.readFileSync(default_path) | ||
browser.var[name] = content ? browser.parseJson(content) : {} | ||
browser.set_var(name, browser.var[name]) | ||
} | ||
} else if (name == "session_list") { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || [] | ||
let data = browser.parseJson(browser.readFileSync(path)) || [] | ||
default_data.forEach((d) => { | ||
let exists = false; | ||
data.forEach((d2) => { | ||
if (d.url == d2.url) { | ||
d2 = d; | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.push(d); | ||
} | ||
}); | ||
browser.var[name] = data; | ||
browser.set_var(name, browser.var[name]); | ||
} else { | ||
let content = browser.readFileSync(default_path); | ||
browser.var[name] = content ? browser.parseJson(content) : {}; | ||
browser.set_var(name, browser.var[name]); | ||
} | ||
} else if (name == 'bookmarks') { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || []; | ||
let data = browser.parseJson(browser.readFileSync(path)) || []; | ||
default_data.forEach(d => { | ||
let exists = false | ||
data.forEach(d2 => { | ||
if (d.name == d2.name) { | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.push(d) | ||
} | ||
}) | ||
default_data.forEach((d) => { | ||
let exists = false; | ||
data.forEach((d2) => { | ||
if (d.url == d2.url) { | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.push(d); | ||
} | ||
}); | ||
browser.var[name] = data; | ||
browser.set_var(name, browser.var[name]); | ||
} else { | ||
let content = browser.readFileSync(default_path); | ||
browser.var[name] = content ? browser.parseJson(content) : {}; | ||
browser.set_var(name, browser.var[name]); | ||
} | ||
} else if (name == 'login') { | ||
if (handle) { | ||
let content = browser.readFileSync(path); | ||
browser.var[name] = content ? browser.parseJson(content) : {}; | ||
} else { | ||
let content = browser.readFileSync(default_path); | ||
browser.var[name] = content ? browser.parseJson(content) : {}; | ||
browser.set_var(name, browser.var[name]); | ||
} | ||
} else if (name == 'open_list') { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || []; | ||
let data = browser.parseJson(browser.readFileSync(path)) || []; | ||
browser.var[name] = data | ||
browser.set_var(name, browser.var[name]) | ||
} else { | ||
let content = browser.readFileSync(default_path) | ||
browser.var[name] = content ? browser.parseJson(content) : {} | ||
browser.set_var(name, browser.var[name]) | ||
} | ||
} else if (name == "blocking") { | ||
if (handle) { | ||
console.log('updateing blocking.json') | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || [] | ||
let data = browser.parseJson(browser.readFileSync(path)) || [] | ||
data.javascript = data.javascript || default_data.javascript | ||
data.privacy = data.privacy || default_data.privacy | ||
if (typeof data.allow_safty_mode == "undefined") { | ||
data.allow_safty_mode = default_data.allow_safty_mode | ||
} | ||
if (typeof data.block_ads == "undefined") { | ||
data.block_ads = default_data.block_ads | ||
} | ||
if (typeof data.block_empty_iframe == "undefined") { | ||
data.block_empty_iframe = default_data.block_empty_iframe | ||
} | ||
if (typeof data.remove_external_iframe == "undefined") { | ||
data.remove_external_iframe = default_data.remove_external_iframe | ||
} | ||
if (typeof data.block_html_tags == "undefined") { | ||
data.block_html_tags = default_data.block_html_tags | ||
} | ||
if (typeof data.skip_video_ads == "undefined") { | ||
data.skip_video_ads = default_data.skip_video_ads | ||
} | ||
data.html_tags_selector_list = data.html_tags_selector_list || [] | ||
default_data.html_tags_selector_list.forEach(d => { | ||
let exists = false | ||
data.html_tags_selector_list.forEach(d2 => { | ||
if (d.url == d2.url && d.ex_url == d2.ex_url && d.select == d2.select) { | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.html_tags_selector_list.push(d) | ||
} | ||
}) | ||
data.ad_list = data.ad_list || [] | ||
default_data.ad_list.forEach(d => { | ||
let exists = false | ||
data.ad_list.forEach(d2 => { | ||
if (d.url == d2.url) { | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.ad_list.push(d) | ||
} | ||
}) | ||
data.un_safe_list = data.un_safe_list || [] | ||
default_data.un_safe_list.forEach(d => { | ||
let exists = false | ||
data.un_safe_list.forEach(d2 => { | ||
if (d.url == d2.url) { | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.un_safe_list.push(d) | ||
} | ||
}) | ||
data.un_safe_words_list = data.un_safe_words_list || [] | ||
default_data.un_safe_words_list.forEach(d => { | ||
let exists = false | ||
data.un_safe_words_list.forEach(d2 => { | ||
if (d.text == d2.text) { | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.un_safe_words_list.push(d) | ||
} | ||
}) | ||
data.popup = data.popup || {} | ||
data.popup.white_list = data.popup.white_list || [] | ||
default_data.popup.white_list.forEach(d => { | ||
let exists = false | ||
data.popup.white_list.forEach(d2 => { | ||
if (d.url == d2.url) { | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.popup.white_list.push(d) | ||
} | ||
}) | ||
data.youtube = data.youtube || {} | ||
data.youtube.safty_mode = data.youtube.safty_mode || {} | ||
data.youtube.safty_mode.selector_list = data.youtube.safty_mode.selector_list || [] | ||
if (typeof data.youtube.skip_ads == "undefined") { | ||
data.youtube.skip_ads = default_data.youtube.skip_ads | ||
} | ||
if (typeof data.youtube.allow_safty_mode == "undefined") { | ||
data.youtube.allow_safty_mode = default_data.youtube.allow_safty_mode | ||
} | ||
default_data.youtube.safty_mode.selector_list.forEach(d => { | ||
let exists = false | ||
data.youtube.safty_mode.selector_list.forEach(d2 => { | ||
if (d == d2) { | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.youtube.safty_mode.selector_list.push(d) | ||
} | ||
}) | ||
data.youtube.safty_mode.words_list = data.youtube.safty_mode.words_list || [] | ||
default_data.youtube.safty_mode.words_list.forEach(d => { | ||
let exists = false | ||
data.youtube.safty_mode.words_list.forEach(d2 => { | ||
if (d.text == d2.text) { | ||
exists = true | ||
} | ||
}) | ||
if (!exists) { | ||
data.youtube.safty_mode.words_list.push(d) | ||
} | ||
}) | ||
browser.var[name] = data | ||
browser.set_var(name, browser.var[name]) | ||
} else { | ||
let content = browser.readFileSync(default_path) | ||
browser.var[name] = content ? browser.parseJson(content) : {} | ||
browser.set_var(name, browser.var[name]) | ||
} | ||
} else { | ||
let content = browser.readFileSync(default_path) | ||
browser.var[name] = content ? browser.parseJson(content) : {} | ||
browser.set_var(name, browser.var[name]) | ||
default_data.forEach((d) => { | ||
let exists = false; | ||
data.forEach((d2) => { | ||
if (d.url == d2.url) { | ||
d2 = d; | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.push(d); | ||
} | ||
} else if (!browser.fs.existsSync(path)) { | ||
console.log(path) | ||
let content = browser.readFileSync(default_path) | ||
browser.var[name] = content ? browser.parseJson(content) : {} | ||
}); | ||
browser.var[name] = data; | ||
browser.set_var(name, browser.var[name]); | ||
} else { | ||
let content = browser.readFileSync(path) | ||
browser.var[name] = content ? browser.parseJson(content) : {} | ||
let content = browser.readFileSync(default_path); | ||
browser.var[name] = content ? browser.parseJson(content) : {}; | ||
browser.set_var(name, browser.var[name]); | ||
} | ||
} else if (name == 'youtube') { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || []; | ||
let data = browser.parseJson(browser.readFileSync(path)) || []; | ||
if (browser.op.is_main && name == 'core') { | ||
let old_core = browser.parseJson(browser.readFileSync(browser.path.join(browser.dir, 'browser_files', 'json', name + '.json'))) | ||
if (browser.var.core.version !== old_core.version) { | ||
browser.force_update = true | ||
browser.var.core.version = old_core.version | ||
browser.set_var('core', browser.var.core) | ||
default_data.blocking.selector.forEach((d) => { | ||
let exists = false; | ||
data.blocking.selector.forEach((d2) => { | ||
if (d == d2) { | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.blocking.selector.push(d); | ||
} | ||
}); | ||
if (!browser.var.core.id) { | ||
browser.var.id = browser.browser.op.package.version + '_' + browser.md5(new Date().getTime() + '_' + Math.random()) | ||
browser.var.core.id = browser.var.id | ||
browser.var.core.started_date = Date.now() | ||
browser.set_var('core', browser.var.core) | ||
} else { | ||
browser.var.id = browser.var.core.id | ||
default_data.blocking.words.forEach((d) => { | ||
let exists = false; | ||
data.blocking.words.forEach((d2) => { | ||
if (d.text == d2.text) { | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.blocking.words.push(d); | ||
} | ||
}); | ||
browser.var[name] = data; | ||
browser.set_var(name, browser.var[name]); | ||
} else { | ||
let content = browser.readFileSync(default_path); | ||
browser.var[name] = content ? browser.parseJson(content) : {}; | ||
browser.set_var(name, browser.var[name]); | ||
} | ||
} else if (name == 'session_list') { | ||
if (handle) { | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || []; | ||
let data = browser.parseJson(browser.readFileSync(path)) || []; | ||
if (!browser.var.core.user_agent && process.platform === 'win32') { | ||
browser.var.core.user_agent = browser.var.core.windows_user_agent | ||
browser.set_var('core', browser.var.core) | ||
} else if (!browser.var.core.user_agent) { | ||
browser.var.core.user_agent = browser.var.core.linux_user_agent | ||
browser.set_var('core', browser.var.core) | ||
default_data.forEach((d) => { | ||
let exists = false; | ||
data.forEach((d2) => { | ||
if (d.name == d2.name) { | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.push(d); | ||
} | ||
}); | ||
browser.electron.app.userAgentFallback = browser.var.core.user_agent | ||
browser.var[name] = data; | ||
browser.set_var(name, browser.var[name]); | ||
} else { | ||
let content = browser.readFileSync(default_path); | ||
browser.var[name] = content ? browser.parseJson(content) : {}; | ||
browser.set_var(name, browser.var[name]); | ||
} | ||
} else if (name == 'blocking') { | ||
if (handle) { | ||
console.log('updateing blocking.json'); | ||
let default_data = browser.parseJson(browser.readFileSync(default_path)) || []; | ||
let data = browser.parseJson(browser.readFileSync(path)) || []; | ||
data.javascript = data.javascript || default_data.javascript; | ||
data.privacy = data.privacy || default_data.privacy; | ||
if (browser.op.is_main && name == 'session_list' && browser.var.core.session == null) { | ||
browser.var.core.session = browser.var.session_list[0] | ||
} | ||
if (typeof data.allow_safty_mode == 'undefined') { | ||
data.allow_safty_mode = default_data.allow_safty_mode; | ||
} | ||
if (typeof data.block_ads == 'undefined') { | ||
data.block_ads = default_data.block_ads; | ||
} | ||
if (typeof data.block_empty_iframe == 'undefined') { | ||
data.block_empty_iframe = default_data.block_empty_iframe; | ||
} | ||
if (typeof data.remove_external_iframe == 'undefined') { | ||
data.remove_external_iframe = default_data.remove_external_iframe; | ||
} | ||
if (typeof data.block_html_tags == 'undefined') { | ||
data.block_html_tags = default_data.block_html_tags; | ||
} | ||
if (typeof data.skip_video_ads == 'undefined') { | ||
data.skip_video_ads = default_data.skip_video_ads; | ||
} | ||
data.html_tags_selector_list = data.html_tags_selector_list || []; | ||
default_data.html_tags_selector_list.forEach((d) => { | ||
let exists = false; | ||
data.html_tags_selector_list.forEach((d2) => { | ||
if (d.url == d2.url && d.ex_url == d2.ex_url && d.select == d2.select) { | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.html_tags_selector_list.push(d); | ||
} | ||
}); | ||
return browser.var[name] | ||
data.ad_list = data.ad_list || []; | ||
default_data.ad_list.forEach((d) => { | ||
let exists = false; | ||
data.ad_list.forEach((d2) => { | ||
if (d.url == d2.url) { | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.ad_list.push(d); | ||
} | ||
}); | ||
} | ||
data.un_safe_list = data.un_safe_list || []; | ||
default_data.un_safe_list.forEach((d) => { | ||
let exists = false; | ||
data.un_safe_list.forEach((d2) => { | ||
if (d.url == d2.url) { | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.un_safe_list.push(d); | ||
} | ||
}); | ||
browser.set_var = function (name, data) { | ||
data.un_safe_words_list = data.un_safe_words_list || []; | ||
default_data.un_safe_words_list.forEach((d) => { | ||
let exists = false; | ||
data.un_safe_words_list.forEach((d2) => { | ||
if (d.text == d2.text) { | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.un_safe_words_list.push(d); | ||
} | ||
}); | ||
try { | ||
data.popup = data.popup || {}; | ||
data.popup.white_list = data.popup.white_list || []; | ||
data.popup.allow_external = default_data.popup.allow_external; | ||
data.popup.allow_internal = default_data.popup.allow_internal; | ||
if (browser.op.is_render || !browser.op.is_main || name.indexOf('$') == 0) { | ||
return | ||
default_data.popup.white_list.forEach((d) => { | ||
let exists = false; | ||
data.popup.white_list.forEach((d2) => { | ||
if (d.url == d2.url) { | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.popup.white_list.push(d); | ||
} | ||
}); | ||
console.log(browser.to_dateX() + ' set_var() :: ' + name) | ||
data.youtube = data.youtube || {}; | ||
data.youtube.safty_mode = data.youtube.safty_mode || {}; | ||
data.youtube.safty_mode.selector_list = data.youtube.safty_mode.selector_list || []; | ||
if (data) { | ||
browser.var[name] = data | ||
browser.call('var.' + name, { | ||
data: data | ||
}) | ||
if(name == "proxy"){ | ||
browser.handleSessions() | ||
} | ||
if (typeof data.youtube.skip_ads == 'undefined') { | ||
data.youtube.skip_ads = default_data.youtube.skip_ads; | ||
} | ||
if (typeof data.youtube.allow_safty_mode == 'undefined') { | ||
data.youtube.allow_safty_mode = default_data.youtube.allow_safty_mode; | ||
} | ||
default_data.youtube.safty_mode.selector_list.forEach((d) => { | ||
let exists = false; | ||
data.youtube.safty_mode.selector_list.forEach((d2) => { | ||
if (d == d2) { | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.youtube.safty_mode.selector_list.push(d); | ||
} | ||
}); | ||
let path = browser.path.join(browser.data_dir, 'json', name + '.json') | ||
let content = JSON.stringify(data) | ||
browser.writeFileSync(path, content) | ||
} else { | ||
console.log('set_var Error : no data') | ||
data.youtube.safty_mode.words_list = data.youtube.safty_mode.words_list || []; | ||
default_data.youtube.safty_mode.words_list.forEach((d) => { | ||
let exists = false; | ||
data.youtube.safty_mode.words_list.forEach((d2) => { | ||
if (d.text == d2.text) { | ||
exists = true; | ||
} | ||
}); | ||
if (!exists) { | ||
data.youtube.safty_mode.words_list.push(d); | ||
} | ||
}); | ||
} catch (error) { | ||
console.log(error) | ||
browser.var[name] = data; | ||
browser.set_var(name, browser.var[name]); | ||
} else { | ||
let content = browser.readFileSync(default_path); | ||
browser.var[name] = content ? browser.parseJson(content) : {}; | ||
browser.set_var(name, browser.var[name]); | ||
} | ||
} else { | ||
let content = browser.readFileSync(default_path); | ||
browser.var[name] = content ? browser.parseJson(content) : {}; | ||
browser.set_var(name, browser.var[name]); | ||
} | ||
} else if (!browser.fs.existsSync(path)) { | ||
let content = browser.readFileSync(default_path); | ||
browser.var[name] = content ? browser.parseJson(content) : {}; | ||
} else { | ||
let content = browser.readFileSync(path); | ||
browser.var[name] = content ? browser.parseJson(content) || {} : {}; | ||
} | ||
if (browser.op.is_main && name == 'core') { | ||
let default_core = browser.parseJson(browser.readFileSync(browser.path.join(browser.dir, 'browser_files', 'json', name + '.json'))); | ||
if (default_core && browser.var.core.version !== default_core.version) { | ||
browser.force_update = true; | ||
browser.var.core.version = default_core.version; | ||
browser.set_var('core', browser.var.core); | ||
} | ||
browser.get_var('core') | ||
if (!browser.var.core.id) { | ||
browser.var.id = process.platform + '_' + browser.op.package.version + '_' + browser.md5(new Date().getTime() + '_' + Math.random()); | ||
browser.var.core.id = browser.var.id; | ||
browser.var.core.started_date = Date.now(); | ||
browser.set_var('core', browser.var.core); | ||
} else { | ||
browser.var.id = browser.var.core.id; | ||
} | ||
browser.get_var('session_list') | ||
if (!browser.var.core.user_agent && process.platform === 'win32') { | ||
browser.var.core.user_agent = browser.var.core.windows_user_agent; | ||
browser.set_var('core', browser.var.core); | ||
} else if (!browser.var.core.user_agent) { | ||
browser.var.core.user_agent = browser.var.core.linux_user_agent; | ||
browser.set_var('core', browser.var.core); | ||
} | ||
if (browser.var.core.user_agent) { | ||
browser.electron.app.userAgentFallback = browser.var.core.user_agent; | ||
} | ||
} | ||
browser.get_var('proxy') | ||
browser.get_var('proxy_list') | ||
if (browser.op.is_main && name == 'session_list' && browser.var.core.session == null) { | ||
browser.var.core.session = browser.var.session_list[0]; | ||
} | ||
browser.get_var('white_list') | ||
browser.get_var('black_list') | ||
return browser.var[name]; | ||
}; | ||
browser.get_var('open_list') | ||
browser.get_var('context_menu') | ||
browser.set_var = function (name, data) { | ||
try { | ||
if (browser.op.is_render || !browser.op.is_main || name.indexOf('$') == 0) { | ||
return; | ||
} | ||
browser.get_var('downloader') | ||
browser.get_var('facebook') | ||
browser.get_var('twitter') | ||
console.log(browser.to_dateX() + ' set_var() :: ' + name); | ||
browser.get_var('internet_speed') | ||
browser.get_var('login') | ||
browser.get_var('user_agent_list') | ||
browser.get_var('bookmarks') | ||
browser.get_var('vip') | ||
browser.get_var('sites') | ||
browser.get_var('blocking') | ||
browser.var['package'] = require(browser.dir + '/package.json') | ||
// if call from render mode only | ||
if (browser.op.is_render) { | ||
browser.ipcRenderer = browser.electron.ipcRenderer | ||
browser.remote = browser.electron.remote | ||
browser.call = function (channel, value) { | ||
browser.electron.ipcRenderer.send(channel, value) | ||
if (data) { | ||
browser.var[name] = data; | ||
if (name == 'core') { | ||
if (browser.var.core.user_agent) { | ||
browser.electron.app.userAgentFallback = browser.var.core.user_agent; | ||
console.log('userAgentFallback', browser.electron.app.userAgentFallback); | ||
} | ||
} | ||
browser.callSync = function (channel, value) { | ||
return browser.electron.ipcRenderer.sendSync(channel, value) | ||
browser.call('var.' + name, { | ||
data: data, | ||
}); | ||
if (name == 'proxy' || name == 'session_list') { | ||
if (browser.handleSessions) { | ||
browser.handleSessions(); | ||
} | ||
} | ||
browser.on = function (name, callback) { | ||
browser.electron.ipcRenderer.on(name, callback) | ||
} | ||
if (browser.op.is_window && !browser.op.is_social) { | ||
browser.get_var('user_data_input') | ||
browser.get_var('user_data') | ||
} | ||
return browser | ||
let path = browser.path.join(browser.data_dir, 'json', name + '.json'); | ||
let content = JSON.stringify(data); | ||
browser.writeFile(path, content); | ||
} else { | ||
console.log('set_var Error : no data'); | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
browser.var['package'] = require(browser.dir + '/package.json'); | ||
browser.get_var('overwrite') | ||
browser.get_var('data_list') | ||
// if call from render mode only | ||
if (browser.op.is_render) { | ||
browser.ipcRenderer = browser.electron.ipcRenderer; | ||
browser.remote = browser.electron.remote; | ||
browser.get_var('download_list') | ||
browser.get_var('user_data_input') | ||
browser.get_var('user_data') | ||
browser.get_var('urls') | ||
browser.call = function (channel, value) { | ||
browser.electron.ipcRenderer.send(channel, value); | ||
}; | ||
browser.callSync = function (channel, value) { | ||
return browser.electron.ipcRenderer.sendSync(channel, value); | ||
}; | ||
browser.on = function (name, callback) { | ||
browser.electron.ipcRenderer.on(name, callback); | ||
}; | ||
return browser; | ||
} | ||
if (!browser.electron) { | ||
browser.electron = browser.op.electron || require('electron') | ||
} | ||
if (!browser.electron) { | ||
browser.electron = browser.op.electron || require('electron'); | ||
} | ||
browser.ipcRenderer = browser.electron.ipcRenderer | ||
browser.session = browser.electron.session | ||
browser.clipboard = browser.electron.clipboard | ||
browser.remote = browser.electron.remote | ||
browser.shell = browser.electron.shell | ||
browser.dialog = browser.electron.dialog | ||
browser.ipcRenderer = browser.electron.ipcRenderer; | ||
browser.session = browser.electron.session; | ||
browser.clipboard = browser.electron.clipboard; | ||
browser.remote = browser.electron.remote; | ||
browser.shell = browser.electron.shell; | ||
browser.dialog = browser.electron.dialog; | ||
browser.addURL = function (nitm) { | ||
browser.addURL = function (nitm) { | ||
setTimeout(() => { | ||
let exists = false; | ||
setTimeout(() => { | ||
if (!nitm.url) { | ||
return; | ||
} | ||
browser.var.urls.forEach((itm) => { | ||
if (itm.url === nitm.url) { | ||
exists = true; | ||
if (!nitm.ignore) { | ||
itm.count++; | ||
} | ||
let exists = false | ||
itm.title = nitm.title || itm.title; | ||
itm.logo = nitm.logo || itm.logo; | ||
if (!nitm.url) { | ||
return | ||
} | ||
itm.last_visit = new Date().getTime(); | ||
} | ||
}); | ||
if (!exists) { | ||
browser.var.urls.push({ | ||
url: nitm.url, | ||
logo: nitm.logo, | ||
title: nitm.title || nitm.url, | ||
count: 1, | ||
first_visit: new Date().getTime(), | ||
last_visit: new Date().getTime(), | ||
}); | ||
} | ||
browser.var.urls.forEach(itm => { | ||
if (itm.url === nitm.url) { | ||
exists = true | ||
itm.count++ | ||
itm.title = nitm.title || itm.title | ||
itm.logo = nitm.logo || itm.logo | ||
browser.var.urls.sort((a, b) => { | ||
return b.count - a.count; | ||
}); | ||
itm.last_visit = new Date().getTime() | ||
} | ||
}) | ||
browser.var.$urls = true; | ||
if (!exists) { | ||
browser.var.urls.push({ | ||
url: nitm.url, | ||
logo: nitm.logo, | ||
title: nitm.title || nitm.url, | ||
count: 1, | ||
first_visit: new Date().getTime(), | ||
last_visit: new Date().getTime() | ||
}) | ||
} | ||
browser.call('var.urls', { | ||
data: browser.var.urls, | ||
}); | ||
}, 100); | ||
}; | ||
browser.var.urls.sort((a, b) => { | ||
return b.count - a.count | ||
}) | ||
browser.defaultSession = function () { | ||
if (browser.var.core.session === null) { | ||
return browser.session.defaultSession; | ||
} else { | ||
return browser.session.fromPartition(browser.var.core.session.name); | ||
} | ||
}; | ||
browser.var.$urls = true | ||
browser.request = require('request'); | ||
require(__dirname + '/lib/cookie.js')(browser); | ||
require(__dirname + '/lib/events.js')(browser); | ||
require(__dirname + '/lib/download.js')(browser); | ||
require(__dirname + '/lib/windows.js')(browser); | ||
require(__dirname + '/lib/plugins.js')(browser); | ||
}, 100); | ||
browser.get_var('core'); | ||
browser.get_var('session_list'); | ||
} | ||
browser.get_var('proxy'); | ||
browser.get_var('proxy_list'); | ||
browser.defaultSession = function () { | ||
if (browser.var.core.session === null) { | ||
return browser.session.defaultSession | ||
} else { | ||
return browser.session.fromPartition(browser.var.core.session.name) | ||
} | ||
} | ||
browser.get_var('white_list'); | ||
browser.get_var('black_list'); | ||
browser.get_var('open_list'); | ||
browser.get_var('context_menu'); | ||
browser.request = require("request") | ||
browser.get_var('downloader'); | ||
browser.get_var('facebook'); | ||
browser.get_var('twitter'); | ||
browser.get_var('internet_speed'); | ||
browser.get_var('login'); | ||
browser.get_var('user_agent_list'); | ||
browser.get_var('bookmarks'); | ||
require(__dirname + '/lib/cookie.js')(browser) | ||
browser.get_var('vip'); | ||
browser.get_var('sites'); | ||
require(__dirname + '/lib/ipc.js')(browser) | ||
require(__dirname + '/lib/events.js')(browser) | ||
browser.get_var('blocking'); | ||
browser.get_var('overwrite'); | ||
browser.get_var('data_list'); | ||
require(__dirname + '/lib/download.js')(browser) | ||
require(__dirname + '/lib/windows.js')(browser) | ||
require(__dirname + '/lib/plugins.js')(browser) | ||
require(__dirname + '/lib/session.js')(browser) | ||
browser.get_var('download_list'); | ||
browser.get_var('user_data_input'); | ||
browser.get_var('user_data'); | ||
browser.get_var('urls'); | ||
browser.get_var('user_data_input'); | ||
browser.get_var('user_data'); | ||
return browser | ||
} | ||
browser.startTime = new Date().getTime(); | ||
return browser; | ||
}; |
1426
lib/events.js
module.exports = function (browser) { | ||
const { BrowserWindow, ipcMain } = browser.electron; | ||
const { | ||
BrowserWindow, | ||
ipcMain | ||
} = browser.electron | ||
browser.views = [] | ||
browser.current_view = { | ||
id: 0 | ||
browser.views = []; | ||
browser.current_view = { | ||
id: 0, | ||
}; | ||
browser.getView = function (id) { | ||
for (let i = 0; i < browser.views.length; i++) { | ||
if (browser.views[i].id == id) { | ||
return browser.views[i]; | ||
} | ||
} | ||
browser.getView = function (id) { | ||
for (let i = 0; i < browser.views.length; i++) { | ||
if (browser.views[i].id == id) { | ||
return browser.views[i] | ||
} | ||
return browser.current_view; | ||
}; | ||
browser.showYoutubeWindows = function () { | ||
browser.window_list.forEach((v) => { | ||
if (v.is_youtube) { | ||
let win = BrowserWindow.fromId(v.id); | ||
if (win && !win.isMinimized()) { | ||
win.setAlwaysOnTop(true); | ||
win.showInactive(); | ||
} | ||
return browser.current_view | ||
} | ||
browser.showYoutubeWindows = function () { | ||
browser.window_list.forEach(v => { | ||
if (v.is_youtube) { | ||
let win = BrowserWindow.fromId(v.id) | ||
if (win && !win.isMinimized()) { | ||
win.setAlwaysOnTop(true) | ||
win.showInactive() | ||
} | ||
} | ||
}) | ||
} | ||
browser.hideOthersViews = function () { | ||
browser.views.forEach(v => { | ||
if (browser.current_view.id != v.id) { | ||
let win = BrowserWindow.fromId(v.id) | ||
if (win) { | ||
win.hide() | ||
} | ||
} | ||
}) | ||
} | ||
}); | ||
}; | ||
browser.hideOthersViews = function () { | ||
browser.views.forEach((v) => { | ||
if (browser.current_view.id != v.id) { | ||
let win = BrowserWindow.fromId(v.id); | ||
if (win) { | ||
win.hide(); | ||
} | ||
} | ||
}); | ||
}; | ||
browser.backAllViews = function () { | ||
browser.views.forEach((v) => { | ||
let win = browser.electron.BrowserWindow.fromId(v.id); | ||
if (win) { | ||
win.setAlwaysOnTop(false); | ||
} | ||
}); | ||
}; | ||
} | ||
browser.backAllViews = function () { | ||
browser.views.forEach(v => { | ||
let win = browser.electron.BrowserWindow.fromId(v.id) | ||
if (win) { | ||
win.setAlwaysOnTop(false) | ||
} | ||
}) | ||
} | ||
if (ipcMain) { | ||
ipcMain.handle('get_var', async (event, info) => { | ||
if (info.name == '*') { | ||
return browser.var; | ||
} else { | ||
let arr = info.name.split(','); | ||
let obj = {}; | ||
arr.forEach((k) => { | ||
if ((k == 'user_data' || k == 'user_data_input') && info.host) { | ||
obj[k] = []; | ||
browser.var[k].forEach((dd) => { | ||
dd.host = dd.host || ''; | ||
dd.url = dd.url || ''; | ||
if (dd.host == info.host) { | ||
obj[k].push(dd); | ||
} | ||
}); | ||
} else { | ||
obj[k] = browser.var[k]; | ||
} | ||
}); | ||
return arr.length == 1 ? obj[info.name] : obj; | ||
} | ||
return null; | ||
}); | ||
if (ipcMain) { | ||
ipcMain.on('online-status', (event, info) => { | ||
browser.online = info.status; | ||
console.log('Internet Status ' + browser.online); | ||
}); | ||
ipcMain.on('get_var', (event, info) => { | ||
console.log('get_var', info); | ||
ipcMain.on('get_var', (event, info) => { | ||
if (info.name == '*') { | ||
event.returnValue = browser.var | ||
} else { | ||
event.returnValue = browser.var[info.name] | ||
} | ||
}) | ||
ipcMain.on('set_var', (event, info) => { | ||
browser.set_var(info.name, info.data) | ||
event.returnValue = browser.var[info.name] | ||
}) | ||
ipcMain.on('get_browser', (event, info) => { | ||
event.returnValue = browser[info.name] | ||
}) | ||
ipcMain.on('set_browser', (event, info) => { | ||
browser[info.name] = info.data | ||
event.returnValue = browser[info.name] | ||
}) | ||
if (info.name == '*') { | ||
event.returnValue = browser.var; | ||
} else { | ||
let arr = info.name.split(','); | ||
let obj = {}; | ||
arr.forEach((k) => { | ||
if ((k == 'user_data' || k == 'user_data_input') && info.host) { | ||
obj[k] = []; | ||
browser.var[k].forEach((dd) => { | ||
dd.host = dd.host || ''; | ||
dd.url = dd.url || ''; | ||
if (dd.host == info.host) { | ||
obj[k].push(dd); | ||
} | ||
}); | ||
} else { | ||
obj[k] = browser.var[k]; | ||
} | ||
}); | ||
event.returnValue = arr.length == 1 ? obj[info.name] : obj; | ||
} | ||
}); | ||
ipcMain.on('set_var', (event, info) => { | ||
browser.set_var(info.name, info.data); | ||
event.returnValue = browser.var[info.name]; | ||
}); | ||
ipcMain.on('get_browser', (event, info) => { | ||
event.returnValue = browser[info.name]; | ||
}); | ||
ipcMain.on('set_browser', (event, info) => { | ||
browser[info.name] = info.data; | ||
event.returnValue = browser[info.name]; | ||
}); | ||
ipcMain.on('get_data', (event, info) => { | ||
let exists = false | ||
browser.var.data_list.forEach(d => { | ||
if (exists) { | ||
return | ||
} | ||
if (d.id == info.id) { | ||
exists = true | ||
event.returnValue = d | ||
} | ||
}) | ||
if (!exists) { | ||
event.returnValue = {} | ||
} | ||
}) | ||
ipcMain.on('set_data', (event, info) => { | ||
ipcMain.on('get_data', (event, info) => { | ||
let exists = false; | ||
browser.var.data_list.forEach((d) => { | ||
if (exists) { | ||
return; | ||
} | ||
if (d.id == info.id) { | ||
exists = true; | ||
event.returnValue = d; | ||
} | ||
}); | ||
if (!exists) { | ||
event.returnValue = {}; | ||
} | ||
}); | ||
ipcMain.on('set_data', (event, info) => { | ||
let exists = false; | ||
browser.var.data_list.forEach((d, i) => { | ||
if (exists) { | ||
return; | ||
} | ||
if (d.id == info.id) { | ||
exists = true; | ||
browser.var.data_list[i] = info; | ||
} | ||
}); | ||
if (!exists) { | ||
browser.var.data_list.push(info); | ||
} | ||
browser.var.$data_list = true; | ||
event.returnValue = info; | ||
}); | ||
let exists = false | ||
browser.var.data_list.forEach((d, i) => { | ||
if (exists) { | ||
return | ||
} | ||
if (d.id == info.id) { | ||
exists = true | ||
browser.var.data_list[i] = info | ||
} | ||
}) | ||
if (!exists) { | ||
browser.var.data_list.push(info) | ||
ipcMain.on('render_message', (event, info) => { | ||
if (info.name == 'open new tab') { | ||
console.log('event new tab fire'); | ||
console.log(info); | ||
info.win_id = info.win_id || browser.current_view.id; | ||
if (info.source == 'session') { | ||
info.partition = info.partition || browser.var.core.session.name; | ||
info.user_name = info.user_name || browser.var.core.session.display; | ||
} else { | ||
info.partition = info.partition || browser.current_view.partition; | ||
info.user_name = info.user_name || browser.current_view.user_name; | ||
} | ||
} else if (info.name == 'show-pdf-reader') { | ||
return browser.newPrinterViewer(); | ||
} else if (info.name == 'add_to_bookmark') { | ||
info.win_id = info.win_id || browser.current_view.id; | ||
let win = BrowserWindow.fromId(info.win_id); | ||
if (win) { | ||
let exists = false; | ||
browser.var.bookmarks.forEach((b) => { | ||
if (b.url == win.getURL()) { | ||
b.title == win.getTitle(); | ||
exists = true; | ||
} | ||
browser.var.$data_list = true | ||
event.returnValue = info | ||
}) | ||
}); | ||
if (!exists) { | ||
browser.var.bookmarks.push({ | ||
title: win.getTitle(), | ||
url: win.getURL(), | ||
favicon: browser.current_view.favicon_path, | ||
}); | ||
} | ||
browser.set_var('bookmarks', browser.var.bookmarks); | ||
} | ||
} else if (info.name == 'add_all_to_bookmark') { | ||
browser.views.forEach((v) => { | ||
let win = BrowserWindow.fromId(v.id); | ||
if (win) { | ||
let exists = false; | ||
browser.var.bookmarks.forEach((b) => { | ||
if (b.title == win.getTitle() && b.url == win.getURL()) { | ||
exists = true; | ||
} | ||
}); | ||
if (exists) { | ||
return; | ||
} | ||
browser.var.bookmarks.push({ | ||
title: win.getTitle(), | ||
url: win.getURL(), | ||
favicon: v.favicon_path, | ||
}); | ||
browser.set_var('bookmarks', browser.var.bookmarks); | ||
} | ||
}); | ||
} else if (info.name == 'set_var') { | ||
browser.set_var(info.key, info.value); | ||
} else if (info.name == 'facebook-share-link') { | ||
info.partition = info.partition || browser.current_view.partition; | ||
info.user_name = info.user_name || browser.current_view.user_name; | ||
info.referrer = info.referrer || browser.current_view.referrer; | ||
info.url = 'https://facebook.com'; | ||
let win = browser.newWindow(info); | ||
// win.openDevTools() | ||
win.webContents.on('dom-ready', (e) => { | ||
// setTimeout(() => { | ||
// win.webContents.sendInputEvent({ | ||
// type: 'keyDown', | ||
// keyCode: '\u0013' | ||
// }) | ||
// }, 7000); | ||
ipcMain.on('render_message', (event, info) => { | ||
let css = browser.readFileSync(browser.files_dir + '/css/facebook.css'); | ||
let js = browser.readFileSync(browser.files_dir + '/js/facebook.js'); | ||
win.webContents.insertCSS(css); | ||
win.webContents.executeJavaScript(js); | ||
}); | ||
event.returnValue = win; | ||
return win; | ||
} else if (info.name == 'saveAsPdf') { | ||
info.win_id = info.win_id || browser.current_view.id; | ||
let win = BrowserWindow.fromId(info.win_id); | ||
if (win) { | ||
browser.backAllViews(); | ||
if (info.name == 'open new tab') { | ||
console.log('event new tab fire') | ||
console.log(info) | ||
info.win_id = info.win_id || browser.current_view.id | ||
if (info.source == 'session') { | ||
info.partition = info.partition || browser.var.core.session.name | ||
info.user_name = info.user_name || browser.var.core.session.display | ||
} else { | ||
info.partition = info.partition || browser.current_view.partition | ||
info.user_name = info.user_name || browser.current_view.user_name | ||
} | ||
} else if (info.name == 'add_to_bookmark') { | ||
info.win_id = info.win_id || browser.current_view.id | ||
let win = BrowserWindow.fromId(info.win_id) | ||
if (win) { | ||
let exists = false | ||
browser.var.bookmarks.forEach(b => { | ||
if (b.url == win.getURL()) { | ||
b.title == win.getTitle() | ||
exists = true | ||
browser.dialog | ||
.showSaveDialog({ | ||
defaultPath: win.webContents.title, | ||
title: 'Save Downloading URL As PDF', | ||
properties: ['openFile', 'createDirectory'], | ||
}) | ||
.then((result) => { | ||
if (result.canceled) { | ||
return; | ||
} | ||
win.webContents.printToPDF({}).then((data) => { | ||
browser.fs.writeFile(result.filePath, data, function (error) { | ||
if (!error) { | ||
browser.backAllViews(); | ||
browser.dialog | ||
.showMessageBox({ | ||
title: 'Download Complete', | ||
type: 'info', | ||
buttons: ['Open File', 'Open Folder', 'Close'], | ||
message: `Save Page As PDF \n To \n ${result.filePath} `, | ||
}) | ||
.then((result3) => { | ||
browser.shell.beep(); | ||
if (result3.response == 1) { | ||
browser.shell.showItemInFolder(result.filePath); | ||
} | ||
}) | ||
if (!exists) { | ||
browser.var.bookmarks.push({ | ||
title: win.getTitle(), | ||
url: win.getURL(), | ||
favicon: browser.current_view.favicon_path | ||
}) | ||
} | ||
browser.set_var('bookmarks', browser.var.bookmarks) | ||
} | ||
} else if (info.name == 'add_all_to_bookmark') { | ||
browser.views.forEach(v => { | ||
let win = BrowserWindow.fromId(v.id) | ||
if (win) { | ||
let exists = false | ||
browser.var.bookmarks.forEach(b => { | ||
if (b.title == win.getTitle() && b.url == win.getURL()) { | ||
exists = true | ||
} | ||
}) | ||
if (exists) { | ||
return | ||
if (result3.response == 0) { | ||
browser.shell.openItem(result.filePath); | ||
} | ||
browser.var.bookmarks.push({ | ||
title: win.getTitle(), | ||
url: win.getURL(), | ||
favicon: v.favicon_path | ||
}) | ||
browser.set_var('bookmarks', browser.var.bookmarks) | ||
browser.call('bookmarks', { | ||
list: browser.var.bookmarks | ||
}) | ||
} | ||
}) | ||
}); | ||
} else { | ||
console.log(error); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
} else if (info.name == 'print') { | ||
info.win_id = info.win_id || browser.current_view.id; | ||
let win = BrowserWindow.fromId(info.win_id); | ||
if (win) { | ||
browser.backAllViews(); | ||
try { | ||
let id = new Date().getTime(); | ||
browser.content_list.push({ | ||
id: id, | ||
data: info.html, | ||
type: 'html', | ||
origin: info.origin, | ||
url: info.href, | ||
}); | ||
// browser.run([browser.dir + '/printing/index.js']); | ||
let w = browser.newWindow({ | ||
show: false, | ||
title: 'Print Viewer', | ||
icon: browser.dir + '/browser_files/images/logo.ico', | ||
width: 850, | ||
height: 720, | ||
alwaysOnTop: false, | ||
webPreferences: { | ||
preload: browser.dir + '/printing/preload.js', | ||
javascript: true, | ||
enableRemoteModule: true, | ||
contextIsolation: false, | ||
nativeWindowOpen: false, | ||
nodeIntegration: false, | ||
nodeIntegrationInSubFrames: false, | ||
nodeIntegrationInWorker: false, | ||
experimentalFeatures: true, | ||
webSecurity: false, | ||
allowRunningInsecureContent: true, | ||
plugins: true, | ||
}, | ||
}); | ||
} else if (info.name == 'set_var') { | ||
w.setMenuBarVisibility(false); | ||
w.loadURL('http://127.0.0.1:60080/data-content/last'); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} | ||
} else if (info.name == 'get_pdf') { | ||
info.win_id = info.win_id || browser.current_view.id; | ||
browser.set_var(info.key, info.value) | ||
let win = BrowserWindow.fromId(info.win_id); | ||
if (win) { | ||
// info.options = Object.assign({ | ||
// silent: false, | ||
// deviceName: null, | ||
// color: true, | ||
// landscape: false, | ||
// scaleFactor: 70, | ||
// pageSize: 'A4' | ||
// }, info.options || {}) | ||
} else if (info.name == 'facebook-share-link') { | ||
console.log(info); | ||
info.partition = info.partition || browser.current_view.partition | ||
info.user_name = info.user_name || browser.current_view.user_name | ||
info.referrer = info.referrer || browser.current_view.referrer | ||
info.url = 'https://facebook.com' | ||
let win = browser.newWindow(info) | ||
// win.openDevTools() | ||
win.webContents.on("dom-ready", e => { | ||
win.webContents | ||
.printToPDF(info.options) | ||
.then((data) => { | ||
let id = new Date().getTime(); | ||
browser.content_list.push({ | ||
id: id, | ||
data: data, | ||
options: info.options, | ||
type: 'pdf', | ||
}); | ||
// setTimeout(() => { | ||
// win.webContents.sendInputEvent({ | ||
// type: 'keyDown', | ||
// keyCode: '\u0013' | ||
// }) | ||
// }, 7000); | ||
let css = browser.readFileSync(browser.files_dir + '/css/facebook.css') | ||
let js = browser.readFileSync(browser.files_dir + '/js/facebook.js') | ||
win.webContents.insertCSS(css) | ||
win.webContents.executeJavaScript(js) | ||
}) | ||
event.returnValue = win | ||
return win | ||
} else if (info.name == 'saveAsPdf') { | ||
info.win_id = info.win_id || browser.current_view.id | ||
let win = BrowserWindow.fromId(info.win_id) | ||
if (win) { | ||
browser.backAllViews() | ||
browser.dialog.showSaveDialog({ | ||
defaultPath: win.webContents.title, | ||
title: "Save Downloading URL As PDF", | ||
properties: ["openFile", "createDirectory"] | ||
}).then(result => { | ||
if (result.canceled) { | ||
return | ||
} | ||
win.webContents.printToPDF({}).then(data => { | ||
browser.fs.writeFile(result.filePath, data, function (error) { | ||
if (!error) { | ||
browser.backAllViews() | ||
browser.dialog.showMessageBox({ | ||
title: "Download Complete", | ||
type: "info", | ||
buttons: ["Open File", "Open Folder", "Close"], | ||
message: `Save Page As PDF \n To \n ${result.filePath} ` | ||
}).then(result3 => { | ||
browser.shell.beep() | ||
if (result3.response == 1) { | ||
browser.shell.showItemInFolder(result.filePath) | ||
} | ||
if (result3.response == 0) { | ||
browser.shell.openItem(result.filePath) | ||
} | ||
}) | ||
} else { | ||
console.log(error) | ||
} | ||
}) | ||
}) | ||
}) | ||
} | ||
} else if (info.name == 'full_screen') { | ||
info.win_id = info.win_id || browser.current_view.id | ||
let win = BrowserWindow.fromId(info.win_id) | ||
if (win) { | ||
browser.mainWindow.setFullScreen(true); | ||
win.setFullScreen(true); | ||
} | ||
} else if (info.name == '!full_screen') { | ||
info.win_id = info.win_id || browser.current_view.id | ||
let win = BrowserWindow.fromId(info.win_id) | ||
if (win) { | ||
browser.mainWindow.setFullScreen(false); | ||
win.setFullScreen(false); | ||
} | ||
} else if (info.name == 'escape') { | ||
browser.hideAddressbar() | ||
info.win_id = info.win_id || browser.current_view.id | ||
let win = BrowserWindow.fromId(info.win_id) | ||
if (win) { | ||
browser.mainWindow.setFullScreen(false); | ||
win.setFullScreen(false); | ||
} | ||
} else if (info.name == 'audio') { | ||
info.win_id = info.win_id || browser.current_view.id | ||
let win = BrowserWindow.fromId(info.win_id) | ||
if (win) { | ||
win.webContents.setAudioMuted(!win.webContents.audioMuted) | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-audio', | ||
tab_id: browser.current_view._id, | ||
muted: win.webContents.audioMuted | ||
}); | ||
} | ||
} else if (info.name == 'zoom') { | ||
info.win_id = info.win_id || browser.current_view.id | ||
let win = BrowserWindow.fromId(info.win_id) | ||
if (win) { | ||
let view = browser.getView(win.id) | ||
view.zoom = 1 | ||
win.webContents.zoomFactor = 1 | ||
} | ||
} else if (info.name == 'zoom+') { | ||
info.win_id = info.win_id || browser.current_view.id | ||
let win = BrowserWindow.fromId(info.win_id) | ||
if (win) { | ||
let factor = win.webContents.zoomFactor | ||
let view = browser.getView(win.id) | ||
view.zoom = factor + 0.2 | ||
win.webContents.zoomFactor = view.zoom | ||
} | ||
} else if (info.name == 'zoom-') { | ||
info.win_id = info.win_id || browser.current_view.id | ||
let win = BrowserWindow.fromId(info.win_id) | ||
if (win) { | ||
let factor = win.webContents.zoomFactor | ||
if (factor > 0.2) { | ||
let view = browser.getView(win.id) | ||
view.zoom = factor - 0.2 | ||
win.webContents.zoomFactor = view.zoom | ||
} | ||
} | ||
} else if (info.name == 'edit-page') { | ||
info.win_id = info.win_id || browser.current_view.id | ||
let win = BrowserWindow.fromId(info.win_id) | ||
if (win) { | ||
win.webContents.executeJavaScript(` | ||
browser.backAllViews(); | ||
browser.run([browser.dir + '/printing/index.js']); | ||
}) | ||
.catch((error) => { | ||
console.log(error); | ||
}); | ||
return; | ||
let id = new Date().getTime(); | ||
let win2 = browser.newWindow({ | ||
show: true, | ||
title: 'PDF Reader', | ||
url: 'http://127.0.0.1:60080/pdf-viewer', | ||
webPreferences: {}, | ||
}); | ||
// win2.openDevTools() | ||
info.options = info.options || { | ||
deviceName: null, | ||
silent: false, | ||
printBackground: true, | ||
color: false, | ||
margin: { | ||
marginType: 'printableArea', | ||
}, | ||
marginsType: 1, | ||
pageSize: 'Tabloid', | ||
landscape: false, | ||
pagesPerSheet: null, | ||
collate: false, | ||
copies: null, | ||
header: null, | ||
footer: null, | ||
}; | ||
win2.webContents.on('dom-ready', (e) => { | ||
win.webContents | ||
.printToPDF(info.options) | ||
.then((data) => { | ||
browser.content_list.push({ | ||
id: id, | ||
data: data, | ||
}); | ||
console.log('pdf-ready'); | ||
win2.send('pdf-ready', { | ||
win_id: win2.id, | ||
url: 'http://127.0.0.1:60080/pdf/' + id, | ||
}); | ||
// let base64data = data.toString('base64') | ||
//console.log('Image converted to base 64 is:\n\n' + base64data); | ||
// browser.newWindow({url : 'data:application/pdf;base64,' + base64data }).openDevTools() | ||
}) | ||
.catch((error) => { | ||
console.log(error); | ||
}); | ||
}); | ||
} | ||
return; | ||
} else if (info.name == 'full_screen') { | ||
info.win_id = info.win_id || browser.current_view.id; | ||
let win = BrowserWindow.fromId(info.win_id); | ||
if (win) { | ||
browser.mainWindow.setFullScreen(true); | ||
win.setFullScreen(true); | ||
} | ||
} else if (info.name == '!full_screen') { | ||
info.win_id = info.win_id || browser.current_view.id; | ||
let win = BrowserWindow.fromId(info.win_id); | ||
if (win) { | ||
browser.mainWindow.setFullScreen(false); | ||
win.setFullScreen(false); | ||
} | ||
} else if (info.name == 'escape') { | ||
browser.hideAddressbar(); | ||
info.win_id = info.win_id || browser.current_view.id; | ||
let win = BrowserWindow.fromId(info.win_id); | ||
if (win) { | ||
browser.mainWindow.setFullScreen(false); | ||
win.setFullScreen(false); | ||
} | ||
} else if (info.name == 'audio') { | ||
info.win_id = info.win_id || browser.current_view.id; | ||
let win = BrowserWindow.fromId(info.win_id); | ||
if (win) { | ||
win.webContents.setAudioMuted(!win.webContents.audioMuted); | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-audio', | ||
tab_id: browser.current_view._id, | ||
muted: win.webContents.audioMuted, | ||
}); | ||
} | ||
} else if (info.name == 'zoom') { | ||
info.win_id = info.win_id || browser.current_view.id; | ||
let win = BrowserWindow.fromId(info.win_id); | ||
if (win) { | ||
let view = browser.getView(win.id); | ||
view.zoom = 1; | ||
win.webContents.zoomFactor = 1; | ||
} | ||
} else if (info.name == 'zoom+') { | ||
info.win_id = info.win_id || browser.current_view.id; | ||
let win = BrowserWindow.fromId(info.win_id); | ||
if (win) { | ||
let factor = win.webContents.zoomFactor; | ||
let view = browser.getView(win.id); | ||
view.zoom = factor + 0.2; | ||
win.webContents.zoomFactor = view.zoom; | ||
} | ||
} else if (info.name == 'zoom-') { | ||
info.win_id = info.win_id || browser.current_view.id; | ||
let win = BrowserWindow.fromId(info.win_id); | ||
if (win) { | ||
let factor = win.webContents.zoomFactor; | ||
if (factor > 0.2) { | ||
let view = browser.getView(win.id); | ||
view.zoom = factor - 0.2; | ||
win.webContents.zoomFactor = view.zoom; | ||
} | ||
} | ||
} else if (info.name == 'edit-page') { | ||
info.win_id = info.win_id || browser.current_view.id; | ||
let win = BrowserWindow.fromId(info.win_id); | ||
if (win) { | ||
win.webContents.executeJavaScript( | ||
` | ||
(function(){ | ||
@@ -320,388 +474,374 @@ let b = document.querySelector('html'); | ||
})() | ||
`, false) | ||
} | ||
} else if (info.name == 'Developer Tools') { | ||
info.win_id = info.win_id || browser.current_view.id | ||
let win = BrowserWindow.fromId(info.win_id) | ||
if (win) { | ||
win.webContents.openDevTools() | ||
} | ||
} else if (info.name == 'reload') { | ||
info.win_id = info.win_id || browser.current_view.id | ||
let win = BrowserWindow.fromId(info.win_id) | ||
if (win) { | ||
win.webContents.reload() | ||
} | ||
} else if (info.name == 'force reload') { | ||
info.win_id = info.win_id || browser.current_view.id | ||
let win = BrowserWindow.fromId(info.win_id) | ||
if (win && info.origin) { | ||
info.origin = info.origin === 'null' ? win.webContents.getURL() : info.origin | ||
info.storages = info.storages || ['appcache', 'filesystem', 'indexdb', 'localstorage', 'shadercache', 'websql', 'serviceworkers', 'cachestorage'] | ||
info.quotas = info.quotas || ['temporary', 'persistent', 'syncable'] | ||
if (info.origin.replace('://', '').indexOf(':') == -1) { | ||
info.origin = info.origin + ':80' | ||
} | ||
`, | ||
false, | ||
); | ||
} | ||
} else if (info.name == 'Developer Tools') { | ||
info.win_id = info.win_id || browser.current_view.id; | ||
let win = BrowserWindow.fromId(info.win_id); | ||
if (win) { | ||
win.webContents.openDevTools(); | ||
} | ||
} else if (info.name == 'reload') { | ||
info.win_id = info.win_id || browser.current_view.id; | ||
let win = BrowserWindow.fromId(info.win_id); | ||
if (win) { | ||
win.webContents.reload(); | ||
} | ||
} else if (info.name == 'force reload') { | ||
info.win_id = info.win_id || browser.current_view.id; | ||
let win = BrowserWindow.fromId(info.win_id); | ||
if (win && info.origin) { | ||
info.origin = info.origin === 'null' ? win.webContents.getURL() : info.origin; | ||
info.storages = info.storages || ['appcache', 'filesystem', 'indexdb', 'localstorage', 'shadercache', 'websql', 'serviceworkers', 'cachestorage']; | ||
info.quotas = info.quotas || ['temporary', 'persistent', 'syncable']; | ||
if (info.origin.replace('://', '').indexOf(':') == -1) { | ||
info.origin = info.origin + ':80'; | ||
} | ||
if (info.storages[0] == 'cookies') { | ||
browser.session.fromPartition(browser.current_view.partition).clearStorageData({ | ||
origin: info.origin, | ||
storages: info.storages, | ||
quotas: info.quotas | ||
}).then(() => { | ||
win.webContents.reload(true) | ||
}) | ||
} else { | ||
browser.session.fromPartition(browser.current_view.partition).clearCache().then(() => { | ||
browser.session.fromPartition(browser.current_view.partition).clearStorageData({ | ||
origin: info.origin, | ||
storages: info.storages, | ||
quotas: info.quotas | ||
}).then(() => { | ||
win.webContents.reload(true) | ||
}) | ||
}) | ||
} | ||
if (info.storages[0] == 'cookies') { | ||
browser.session | ||
.fromPartition(browser.current_view.partition) | ||
.clearStorageData({ | ||
origin: info.origin, | ||
storages: info.storages, | ||
quotas: info.quotas, | ||
}) | ||
.then(() => { | ||
browser.session | ||
.fromPartition(browser.current_view.partition) | ||
.clearCache() | ||
.then(() => { | ||
win.webContents.reload(); | ||
}); | ||
}); | ||
} else { | ||
browser.session | ||
.fromPartition(browser.current_view.partition) | ||
.clearCache() | ||
.then(() => { | ||
browser.session | ||
.fromPartition(browser.current_view.partition) | ||
.clearStorageData({ | ||
origin: info.origin, | ||
storages: info.storages, | ||
quotas: info.quotas, | ||
}) | ||
.then(() => { | ||
browser.session | ||
.fromPartition(browser.current_view.partition) | ||
.clearCache() | ||
.then(() => { | ||
win.webContents.reload(); | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
} else if (info.name == 'show addressbar') { | ||
browser.showAddressbar(info); | ||
} else if (info.name == 'show setting') { | ||
// let bounds = browser.mainWindow.getBounds() | ||
// let win = browser.newWindow({ | ||
// url: 'http://127.0.0.1:60080/setting', | ||
// x: bounds.x + 25, | ||
// y: 20, | ||
// width: bounds.width - 50, | ||
// height: bounds.height - 50, | ||
// alwaysOnTop: true | ||
// }) | ||
} else if (info.name == 'show profiles') { | ||
browser.showUserProfile(); | ||
} else if (info.name == 'go back') { | ||
info.win_id = info.win_id || browser.current_view.id; | ||
let win = BrowserWindow.fromId(info.win_id); | ||
if (win && win.webContents.canGoBack()) { | ||
win.webContents.goBack(); | ||
} | ||
} else if (info.name == 'go forward') { | ||
info.win_id = info.win_id || browser.current_view.id; | ||
let win = BrowserWindow.fromId(info.win_id); | ||
if (win && win.webContents.canGoForward()) { | ||
win.webContents.goForward(); | ||
} | ||
} else if (info.name == 'body_clicked') { | ||
if (browser.views.filter((v) => v.id == info.win_id).length > 0) { | ||
browser.hideAddressbar(); | ||
} else { | ||
info.name = ''; | ||
} | ||
} else if (info.name == 'copy') { | ||
browser.clipboard.writeText(info.text.replace('#___new_tab___', '').replace('#___new_window__', '')); | ||
} else if (info.name == 'user-input') { | ||
if (info.host == '127.0.0.1:60080') { | ||
return; | ||
} | ||
let exists = false; | ||
browser.var.user_data_input = browser.var.user_data_input || []; | ||
browser.var.user_data_input.forEach((u) => { | ||
if (u.id === info.id) { | ||
exists = true; | ||
} | ||
} else if (info.name == 'show addressbar') { | ||
browser.showAddressbar(info) | ||
} else if (info.name == 'show setting') { | ||
// let bounds = browser.mainWindow.getBounds() | ||
// let win = browser.newWindow({ | ||
// url: 'http://127.0.0.1:60080/setting', | ||
// x: bounds.x + 25, | ||
// y: 20, | ||
// width: bounds.width - 50, | ||
// height: bounds.height - 50, | ||
// alwaysOnTop: true | ||
// }) | ||
} else if (info.name == 'show profiles') { | ||
browser.showUserProfile() | ||
} else if (info.name == 'go back') { | ||
info.win_id = info.win_id || browser.current_view.id | ||
let win = BrowserWindow.fromId(info.win_id) | ||
if (win && win.webContents.canGoBack()) { | ||
win.webContents.goBack() | ||
} | ||
} else if (info.name == 'go forward') { | ||
info.win_id = info.win_id || browser.current_view.id | ||
let win = BrowserWindow.fromId(info.win_id) | ||
if (win && win.webContents.canGoForward()) { | ||
win.webContents.goForward() | ||
} | ||
} else if (info.name == 'body_clicked') { | ||
if (browser.views.filter(v => v.id == info.win_id).length > 0) { | ||
browser.hideAddressbar() | ||
} else { | ||
info.name = '' | ||
} | ||
} else if (info.name == 'copy') { | ||
browser.clipboard.writeText(info.text.replace('#___new_tab___', '').replace('#___new_window__', '')) | ||
} else if (info.name == 'user-input') { | ||
if (info.host == '127.0.0.1:60080') { | ||
return | ||
} | ||
let exists = false | ||
browser.var.user_data_input = browser.var.user_data_input || [] | ||
browser.var.user_data_input.forEach(u => { | ||
if (u.id === info.id) { | ||
exists = true | ||
if (JSON.stringify(u.data) !== JSON.stringify(info.data)) { | ||
u.data = info.data | ||
browser.var.$user_data_input = true | ||
} | ||
} else if (u.url === info.url || u.url.like('*' + info.host + '*') || u.host === info.host) { | ||
if (JSON.stringify(u.data) == JSON.stringify(info.data)) { | ||
exists = true | ||
} | ||
} | ||
}) | ||
if (!exists) { | ||
browser.var.user_data_input.push(info) | ||
browser.var.$user_data_input = true | ||
} | ||
} else if (info.name == 'user-data') { | ||
if (info.host == '127.0.0.1:60080') { | ||
return | ||
} | ||
browser.var.user_data = browser.var.user_data || [] | ||
let exists = false | ||
browser.var.user_data.forEach(u => { | ||
if (u.id === info.id) { | ||
exists = true | ||
if (JSON.stringify(u.data) !== JSON.stringify(info.data)) { | ||
u.data = info.data | ||
browser.var.$user_data = true | ||
} | ||
} else if (u.url === info.url || u.url.like('*' + info.host + '*') || u.host === info.host) { | ||
if (u.data && u.data.length > 0 && u.data.length == info.data.length && u.data[0].value == info.data[0].value) { | ||
exists = true | ||
} | ||
} | ||
}) | ||
if (!exists) { | ||
browser.var.user_data.push(info) | ||
browser.var.$user_data = true | ||
} | ||
} else { | ||
if (JSON.stringify(u.data) !== JSON.stringify(info.data)) { | ||
u.data = info.data; | ||
browser.var.$user_data_input = true; | ||
} | ||
browser.mainWindow.webContents.send('render_message', info); | ||
} else if (u.url === info.url || u.url.like('*' + info.host + '*') || u.host === info.host) { | ||
if (JSON.stringify(u.data) == JSON.stringify(info.data)) { | ||
exists = true; | ||
} | ||
} | ||
}); | ||
if (!exists) { | ||
browser.var.user_data_input.push(info); | ||
browser.var.$user_data_input = true; | ||
} | ||
} else if (info.name == 'user-data') { | ||
if (info.host == '127.0.0.1:60080') { | ||
return; | ||
} | ||
ipcMain.on('new-view', (e, info) => { | ||
if (browser.addressbarWindow) { | ||
browser.addressbarWindow.hide() | ||
} | ||
browser.var.user_data = browser.var.user_data || []; | ||
if (typeof info.partition == 'undefined' || info.partition == 'undefined') { | ||
browser.views.forEach(v => { | ||
if (v.id == browser.current_view.id) { | ||
info.partition = v.partition | ||
info.user_name = v.user_name | ||
browser.current_view = v | ||
} | ||
}) | ||
let exists = false; | ||
browser.var.user_data.forEach((u) => { | ||
if (u.id === info.id) { | ||
exists = true; | ||
if (JSON.stringify(u.data) !== JSON.stringify(info.data)) { | ||
u.data = info.data; | ||
browser.var.$user_data = true; | ||
} | ||
let win = browser.newView(info) | ||
let new_view = { | ||
_id: info._id, | ||
id: win.id, | ||
partition: info.partition, | ||
user_name: info.user_name, | ||
zoom: 1 | ||
} else if (u.url === info.url || u.url.like('*' + info.host + '*') || u.host === info.host) { | ||
if (u.data && u.data.length > 0 && u.data.length == info.data.length && u.data[0].value == info.data[0].value) { | ||
exists = true; | ||
} | ||
browser.views.push(new_view) | ||
if (browser.views.length == 0) { | ||
browser.current_view = new_view | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-url', | ||
tab_id: browser.current_view._id, | ||
url: decodeURI(info.url) | ||
}); | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-audio', | ||
tab_id: browser.current_view._id, | ||
muted: win.webContents.audioMuted | ||
}); | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-buttons', | ||
tab_id: browser.current_view._id, | ||
forward: win.webContents.canGoForward(), | ||
back: win.webContents.canGoBack() | ||
}); | ||
// browser.hideOthersViews() | ||
} | ||
} | ||
}); | ||
e.returnValue = win | ||
return win | ||
}) | ||
if (!exists) { | ||
browser.var.user_data.push(info); | ||
browser.var.$user_data = true; | ||
} | ||
} else { | ||
} | ||
ipcMain.on('show-view', (e, info) => { | ||
browser.mainWindow.webContents.send('render_message', info); | ||
}); | ||
if (browser.addressbarWindow) { | ||
browser.addressbarWindow.hide() | ||
} | ||
ipcMain.on('new-view', (e, info) => { | ||
if (browser.addressbarWindow) { | ||
browser.addressbarWindow.hide(); | ||
} | ||
browser.views.forEach(v => { | ||
let win = BrowserWindow.fromId(v.id) | ||
if (win && v._id == info._id) { | ||
browser.handleViewPosition(win) | ||
win.show() | ||
browser.current_view = browser.getView(win.id) | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-user_name', | ||
user_name: v.user_name | ||
}); | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-url', | ||
tab_id: browser.current_view._id, | ||
url: decodeURI(win.getURL()) | ||
}); | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-audio', | ||
tab_id: browser.current_view._id, | ||
muted: win.webContents.audioMuted | ||
}); | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-buttons', | ||
tab_id: browser.current_view._id, | ||
forward: win.webContents.canGoForward(), | ||
back: win.webContents.canGoBack() | ||
}); | ||
browser.mainWindow.setTitle(win.getTitle()) | ||
e.returnValue = win | ||
} | ||
}) | ||
if (typeof info.partition == 'undefined' || info.partition == 'undefined') { | ||
browser.views.forEach((v) => { | ||
if (v.id == browser.current_view.id) { | ||
info.partition = v.partition; | ||
info.user_name = v.user_name; | ||
browser.current_view = v; | ||
} | ||
}); | ||
} | ||
let win = browser.newView(info); | ||
let new_view = { | ||
_id: info._id, | ||
id: win.id, | ||
partition: info.partition, | ||
user_name: info.user_name, | ||
zoom: 1, | ||
}; | ||
browser.views.push(new_view); | ||
if (browser.views.length == 0) { | ||
browser.current_view = new_view; | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-url', | ||
tab_id: browser.current_view._id, | ||
url: decodeURI(info.url), | ||
}); | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-audio', | ||
tab_id: browser.current_view._id, | ||
muted: win.webContents.audioMuted, | ||
}); | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-buttons', | ||
tab_id: browser.current_view._id, | ||
forward: win.webContents.canGoForward(), | ||
back: win.webContents.canGoBack(), | ||
}); | ||
browser.hideOthersViews(); | ||
} | ||
// browser.hideOthersViews() | ||
}) | ||
e.returnValue = win; | ||
return win; | ||
}); | ||
ipcMain.on('update-view', (e, info) => { | ||
ipcMain.on('show-view', (e, info) => { | ||
if (browser.addressbarWindow) { | ||
browser.addressbarWindow.hide(); | ||
} | ||
if (browser.addressbarWindow) { | ||
browser.addressbarWindow.hide() | ||
} | ||
browser.views.forEach((v) => { | ||
let win = BrowserWindow.fromId(v.id); | ||
if (win && v._id == info._id) { | ||
browser.handleViewPosition(win); | ||
win.show(); | ||
browser.current_view = browser.getView(win.id); | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-user_name', | ||
user_name: v.user_name, | ||
}); | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-url', | ||
tab_id: browser.current_view._id, | ||
url: decodeURI(win.getURL()), | ||
}); | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-audio', | ||
tab_id: browser.current_view._id, | ||
muted: win.webContents.audioMuted, | ||
}); | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-buttons', | ||
tab_id: browser.current_view._id, | ||
forward: win.webContents.canGoForward(), | ||
back: win.webContents.canGoBack(), | ||
}); | ||
browser.mainWindow.setTitle(win.getTitle()); | ||
e.returnValue = win; | ||
} | ||
}); | ||
if (info.url) { | ||
info.url = info.url.replace('#___new_tab___', '').replace('#___new_window___', '') | ||
} | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-url', | ||
url: decodeURI(info.url), | ||
tab_id: info._id || browser.current_view._id | ||
}) | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-title', | ||
title: decodeURI(info.url), | ||
tab_id: info._id || browser.current_view._id | ||
}) | ||
browser.hideOthersViews(); | ||
}); | ||
if (!info._id) { | ||
let win = BrowserWindow.fromId(browser.current_view.id) | ||
win.webContents.stop() | ||
ipcMain.on('update-view', (e, info) => { | ||
if (browser.addressbarWindow) { | ||
browser.addressbarWindow.hide(); | ||
} | ||
browser.var.overwrite.urls.forEach(data => { | ||
if (info.url.like(data.from)) { | ||
console.log(`\nAuto overwrite redirect \n ${data.to} \n `) | ||
let q = info.url.split('?')[1] | ||
if (q) { | ||
q = '?' + q | ||
} else { | ||
q = '' | ||
} | ||
info.url = data.to + q | ||
} | ||
}) | ||
console.log(info.url) | ||
win.loadURL(info.url) | ||
e.returnValue = win | ||
return | ||
} | ||
if (info.url) { | ||
info.url = info.url.replace('#___new_tab___', '').replace('#___new_window___', ''); | ||
} | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-url', | ||
url: decodeURI(info.url), | ||
tab_id: info._id || browser.current_view._id, | ||
}); | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-title', | ||
title: decodeURI(info.url), | ||
tab_id: info._id || browser.current_view._id, | ||
}); | ||
browser.views.forEach(v => { | ||
let win = BrowserWindow.fromId(v.id) | ||
if (win && v._id == info._id) { | ||
if (!info._id) { | ||
let win = BrowserWindow.fromId(browser.current_view.id); | ||
win.webContents.stop(); | ||
win.webContents.stop() | ||
win.loadURL(info.url) | ||
e.returnValue = win | ||
return | ||
} | ||
}) | ||
}) | ||
ipcMain.on('close-view', (e, info) => { | ||
if (browser.addressbarWindow) { | ||
browser.addressbarWindow.hide() | ||
browser.var.overwrite.urls.forEach((data) => { | ||
if (info.url.like(data.from)) { | ||
console.log(`\nAuto overwrite redirect \n ${data.to} \n `); | ||
let q = info.url.split('?')[1]; | ||
if (q) { | ||
q = '?' + q; | ||
} else { | ||
q = ''; | ||
} | ||
info.url = data.to + q; | ||
} | ||
}); | ||
console.log(info.url); | ||
win.loadURL(info.url); | ||
e.returnValue = win; | ||
return; | ||
} | ||
browser.views.forEach(v => { | ||
if (v._id == info._id) { | ||
let win = BrowserWindow.fromId(v.id) | ||
if (win) { | ||
e.returnValue = win | ||
win.destroy() | ||
return | ||
} | ||
} | ||
}) | ||
browser.views.forEach((v) => { | ||
let win = BrowserWindow.fromId(v.id); | ||
if (win && v._id == info._id) { | ||
win.webContents.stop(); | ||
win.loadURL(info.url); | ||
e.returnValue = win; | ||
return; | ||
} | ||
}); | ||
}); | ||
ipcMain.on('close-view', (e, info) => { | ||
if (browser.addressbarWindow) { | ||
browser.addressbarWindow.hide(); | ||
} | ||
browser.views.forEach((v) => { | ||
if (v._id == info._id) { | ||
let win = BrowserWindow.fromId(v.id); | ||
if (win) { | ||
e.returnValue = win; | ||
win.destroy(); | ||
return; | ||
} | ||
} | ||
}); | ||
}); | ||
ipcMain.on('new-window', (e, info) => { | ||
info.partition = info.partition || browser.current_view.partition; | ||
info.user_name = info.user_name || browser.current_view.user_name; | ||
let win = browser.newWindow(info); | ||
e.returnValue = win; | ||
return win; | ||
}); | ||
}) | ||
ipcMain.on('new-trusted-window', (e, info) => { | ||
info.partition = info.partition || browser.current_view.partition; | ||
info.user_name = info.user_name || browser.current_view.user_name; | ||
let win = browser.newTrustedWindow(info); | ||
e.returnValue = win; | ||
return win; | ||
}); | ||
ipcMain.on('new-window', (e, info) => { | ||
ipcMain.on('new-youtube-window', (e, info) => { | ||
info.partition = info.partition || browser.current_view.partition; | ||
info.user_name = info.user_name || browser.current_view.user_name; | ||
let win = browser.newYoutubeWindow(info); | ||
e.returnValue = win; | ||
return win; | ||
}); | ||
info.partition = info.partition || browser.current_view.partition | ||
info.user_name = info.user_name || browser.current_view.user_name | ||
let win = browser.newWindow(info) | ||
e.returnValue = win | ||
return win | ||
}) | ||
ipcMain.on('new-iframe-window', (e, info) => { | ||
info.partition = info.partition || browser.current_view.partition; | ||
info.user_name = info.user_name || browser.current_view.user_name; | ||
let win = browser.newIframeWindow(info); | ||
e.returnValue = win; | ||
return win; | ||
}); | ||
ipcMain.on('new-trusted-window', (e, info) => { | ||
ipcMain.on('redownload-item', (e, info) => { | ||
browser.var.download_list.forEach((dd, i) => { | ||
if (dd.id === info.id) { | ||
browser.var.download_list.splice(i, 1); | ||
} | ||
}); | ||
browser.tryDownload(info.url); | ||
}); | ||
ipcMain.on('remove-item', (e, info) => { | ||
browser.var.download_list.forEach((dd, i) => { | ||
if (dd.id === info.id) { | ||
browser.var.download_list.splice(i, 1); | ||
} | ||
}); | ||
}); | ||
info.partition = info.partition || browser.current_view.partition | ||
info.user_name = info.user_name || browser.current_view.user_name | ||
let win = browser.newTrustedWindow(info) | ||
e.returnValue = win | ||
return win | ||
}) | ||
ipcMain.on('new-youtube-window', (e, info) => { | ||
info.partition = info.partition || browser.current_view.partition | ||
info.user_name = info.user_name || browser.current_view.user_name | ||
let win = browser.newYoutubeWindow(info) | ||
e.returnValue = win | ||
return win | ||
}) | ||
ipcMain.on('new-iframe-window', (e, info) => { | ||
info.partition = info.partition || browser.current_view.partition | ||
info.user_name = info.user_name || browser.current_view.user_name | ||
let win = browser.newIframeWindow(info) | ||
e.returnValue = win | ||
return win | ||
}) | ||
ipcMain.on('redownload-item', (e, info) => { | ||
browser.var.download_list.forEach((dd, i) => { | ||
if (dd.id === info.id) { | ||
browser.var.download_list.splice(i, 1) | ||
} | ||
}) | ||
browser.tryDownload(info.url) | ||
}) | ||
ipcMain.on('remove-item', (e, info) => { | ||
browser.var.download_list.forEach((dd, i) => { | ||
if (dd.id === info.id) { | ||
browser.var.download_list.splice(i, 1) | ||
} | ||
}) | ||
}) | ||
ipcMain.on('new-video-window', (e, info) => { | ||
info.partition = info.partition || browser.current_view.partition | ||
info.user_name = info.user_name || browser.current_view.user_name | ||
let win = browser.newVideoWindow(info) | ||
e.returnValue = win | ||
return win | ||
}) | ||
} | ||
} | ||
ipcMain.on('new-video-window', (e, info) => { | ||
info.partition = info.partition || browser.current_view.partition; | ||
info.user_name = info.user_name || browser.current_view.user_name; | ||
let win = browser.newVideoWindow(info); | ||
e.returnValue = win; | ||
return win; | ||
}); | ||
} | ||
}; |
153
lib/file.js
module.exports = function (browser) { | ||
const fs = browser.fs | ||
browser.mkdirSync = function (path) { | ||
try { | ||
fs.mkdirSync(path) | ||
} catch (error) { | ||
console.log(error.message) | ||
} | ||
} | ||
const fs = browser.fs; | ||
browser.readFileSync = function (path, encode) { | ||
let path2 = path + '_tmp' | ||
if (fs.existsSync(path)) { | ||
return fs.readFileSync(path).toString(encode || 'utf8') | ||
} else if (fs.existsSync(path2)) { | ||
return fs.readFileSync(path2).toString(encode || 'utf8') | ||
} | ||
return '' | ||
browser.mkdirSync = function (dirname) { | ||
try { | ||
if (fs.existsSync(dirname)) { | ||
return true; | ||
} | ||
if (browser.mkdirSync(browser.path.dirname(dirname))) { | ||
fs.mkdirSync(dirname); | ||
return true; | ||
} | ||
} catch (error) { | ||
console.log(error.message); | ||
return false; | ||
} | ||
}; | ||
browser.writeFileSync = function (path, data, encode) { | ||
let path2 = path + '_tmp' | ||
browser.deleteFileSync(path2) | ||
fs.writeFileSync(path2, data, { | ||
encoding: encode || 'utf8' | ||
}) | ||
browser.deleteFileSync(path) | ||
fs.renameSync(path2, path) | ||
browser.deleteFileSync(path2) | ||
browser.readFileSync = function (path, encode) { | ||
let path2 = path + '_tmp'; | ||
if (fs.existsSync(path)) { | ||
return fs.readFileSync(path).toString(encode || 'utf8'); | ||
} else if (fs.existsSync(path2)) { | ||
return fs.readFileSync(path2).toString(encode || 'utf8'); | ||
} | ||
return ''; | ||
}; | ||
browser.deleteFileSync = function (path) { | ||
try { | ||
if (fs.existsSync(path)) { | ||
return fs.unlinkSync(path) | ||
} | ||
} catch (error) { | ||
return null | ||
} | ||
browser.writeFile = function (path, data, encode) { | ||
let path2 = path + '_tmp'; | ||
browser.deleteFile(path2, () => { | ||
fs.writeFile( | ||
path2, | ||
data, | ||
{ | ||
encoding: encode || 'utf8', | ||
}, | ||
() => { | ||
browser.deleteFile(path, () => { | ||
fs.rename(path2, path, () => { | ||
browser.deleteFile(path2, () => { | ||
console.log('writeFile : ', path); | ||
}); | ||
}); | ||
}); | ||
}, | ||
); | ||
}); | ||
}; | ||
return null | ||
browser.deleteFileSync = function (path) { | ||
try { | ||
if (fs.existsSync(path)) { | ||
return fs.unlinkSync(path); | ||
} | ||
} catch (error) { | ||
return null; | ||
} | ||
browser.parseJson = function (content) { | ||
try { | ||
if (content && typeof content === 'string') { | ||
return JSON.parse(content) | ||
} else { | ||
return null | ||
} | ||
} catch (error) { | ||
return null | ||
} | ||
return null; | ||
}; | ||
browser.deleteFile = function (path, callback) { | ||
fs.stat(path, (err, stats) => { | ||
if (!err && stats.isFile()) { | ||
fs.unlink(path, (err) => { | ||
callback(path); | ||
}); | ||
} else { | ||
callback(path); | ||
} | ||
}); | ||
}; | ||
browser.parseJson = function (content) { | ||
try { | ||
if (content && typeof content === 'string') { | ||
return JSON.parse(content); | ||
} else { | ||
return null; | ||
} | ||
} catch (error) { | ||
return null; | ||
} | ||
}; | ||
browser.js = function (name) { | ||
return browser.readFileSync(browser.files_dir + '/js/' + name + '.js') | ||
} | ||
browser.css = function (name) { | ||
return browser.readFileSync(browser.files_dir + '/css/' + name + '.css') | ||
} | ||
browser.html = function (name) { | ||
return browser.readFileSync(browser.files_dir + '/html/' + name + '.html') | ||
} | ||
browser.json = function (name) { | ||
return browser.readFileSync(browser.files_dir + '/json/' + name + '.json') | ||
} | ||
browser.xml = function (name) { | ||
return browser.readFileSync(browser.files_dir + '/xml/' + name + '.xml') | ||
} | ||
} | ||
browser.js = function (name) { | ||
return browser.readFileSync(browser.files_dir + '/js/' + name + '.js'); | ||
}; | ||
browser.css = function (name) { | ||
return browser.readFileSync(browser.files_dir + '/css/' + name + '.css'); | ||
}; | ||
browser.html = function (name) { | ||
return browser.readFileSync(browser.files_dir + '/html/' + name + '.html'); | ||
}; | ||
browser.json = function (name) { | ||
return browser.readFileSync(browser.files_dir + '/json/' + name + '.json'); | ||
}; | ||
browser.xml = function (name) { | ||
return browser.readFileSync(browser.files_dir + '/xml/' + name + '.xml'); | ||
}; | ||
}; |
240
lib/fn.js
module.exports = function init(browser) { | ||
browser.exe = function (app_path, args) { | ||
var child = require('child_process').execFile; | ||
var executablePath = app_path | ||
var parameters = args; | ||
console.log(executablePath + ' ' + parameters) | ||
child(executablePath, parameters, function (err, data) { | ||
if (err) { | ||
console.log(err) | ||
} | ||
}); | ||
browser.exe = function (app_path, args) { | ||
var child = browser.child_process.execFile; | ||
var executablePath = app_path; | ||
var parameters = args; | ||
console.log(executablePath + ' ' + parameters); | ||
child(executablePath, parameters, function (err, data) { | ||
if (err) { | ||
console.log(err); | ||
} | ||
}); | ||
}; | ||
browser.guid = function () { | ||
function s4() { | ||
return Math.floor((1 + Math.random()) * 0x10000) | ||
.toString(16) | ||
.substring(1); | ||
} | ||
browser.guid = function () { | ||
function s4() { | ||
return Math.floor((1 + Math.random()) * 0x10000) | ||
.toString(16) | ||
.substring(1); | ||
} | ||
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); | ||
} | ||
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); | ||
}; | ||
browser.to_dateX = function (d) { | ||
d = d || new Date() | ||
return d.getFullYear() + '/' + (d.getMonth() + 1) + '/' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds() | ||
} | ||
browser.to_dateX = function (d) { | ||
d = d || new Date(); | ||
return d.getFullYear() + '/' + (d.getMonth() + 1) + '/' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds(); | ||
}; | ||
browser.wait = function (resolve, reject) { | ||
return new Promise((resolve, reject) => {}) | ||
browser.wait = function (resolve, reject) { | ||
return new Promise((resolve, reject) => {}); | ||
}; | ||
browser.sleep = function (millis) { | ||
return new Promise((resolve) => setTimeout(resolve, millis)); | ||
}; | ||
browser.decodeURIComponent = (value) => { | ||
try { | ||
return decodeURIComponent(value); | ||
} catch (error) { | ||
// console.log(error) | ||
return value; | ||
} | ||
}; | ||
browser.encodeURIComponent = (value) => { | ||
try { | ||
return encodeURIComponent(value); | ||
} catch (error) { | ||
// console.log(error) | ||
return value; | ||
} | ||
}; | ||
browser.cookieParse = (cookie) => { | ||
if (typeof cookie === 'undefined') return []; | ||
return cookie.split(';').reduce(function (prev, curr) { | ||
let m = / *([^=]+)=(.*)/.exec(curr); | ||
if (m) { | ||
let key = browser.decodeURIComponent(m[1]); | ||
let value = browser.decodeURIComponent(m[2]); | ||
prev[key] = value; | ||
} | ||
return prev; | ||
}, {}); | ||
}; | ||
browser.sleep = function (millis) { | ||
return new Promise(resolve => setTimeout(resolve, millis)) | ||
browser.cookieStringify = (cookie) => { | ||
let out = ''; | ||
for (let co in cookie) { | ||
out += browser.encodeURIComponent(co) + '=' + browser.encodeURIComponent(cookie[co]) + ';'; | ||
} | ||
return out; | ||
}; | ||
browser.decodeURIComponent = value=>{ | ||
try { | ||
return decodeURIComponent(value) | ||
} catch (error) { | ||
// console.log(error) | ||
return value | ||
} | ||
} | ||
browser.encodeURIComponent = value=>{ | ||
try { | ||
return encodeURIComponent(value) | ||
} catch (error) { | ||
// console.log(error) | ||
return value | ||
} | ||
} | ||
browser.cookieParse = cookie => { | ||
if (typeof cookie === "undefined") return [] | ||
return cookie.split(";").reduce(function (prev, curr) { | ||
let m = / *([^=]+)=(.*)/.exec(curr) | ||
if (m) { | ||
let key = browser.decodeURIComponent(m[1]) | ||
let value = browser.decodeURIComponent(m[2]) | ||
prev[key] = value | ||
browser.get_network = function () { | ||
let addresses = {}; | ||
try { | ||
let ifaces = browser.os.networkInterfaces(); | ||
let hasAddresses = false; | ||
Object.keys(ifaces).forEach(function (iface) { | ||
ifaces[iface].forEach(function (address) { | ||
if (!hasAddresses && !address.internal) { | ||
addresses[(address.family || '').toLowerCase()] = address.address; | ||
if (address.mac && address.mac !== '00:00:00:00:00:00') { | ||
addresses = address; | ||
hasAddresses = true; | ||
} | ||
return prev | ||
}, {}) | ||
} | ||
}); | ||
}); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
return addresses; | ||
}; | ||
browser.cookieStringify = cookie => { | ||
browser.json_to_html = function (data) { | ||
let content = ''; | ||
let out = "" | ||
for (var co in cookie) { | ||
out += browser.encodeURIComponent(co) + "=" + browser.encodeURIComponent(cookie[co]) + ";" | ||
} | ||
return out | ||
} | ||
data.forEach((el) => { | ||
if (el.type == 'text') { | ||
content += `<p> ${el.value} </p>`; | ||
} else if (el.type == 'text2') { | ||
content += `<div class="text2" > | ||
<div class="value"> ${el.value} </div> | ||
<div class="value2"> ${el.value2} </div> | ||
</div>`; | ||
}else if (el.type == 'text2b') { | ||
content += `<div class="text2b" > | ||
<div class="value"> ${el.value} </div> | ||
<div class="value2"> ${el.value2} </div> | ||
</div>`; | ||
} else if (el.type == 'line') { | ||
content += `<div class="line" > </div>`; | ||
} else if (el.type == 'line2') { | ||
content += `<div class="line2" > </div>`; | ||
} else if (el.type == 'line3') { | ||
content += `<div class="line3" > </div>`; | ||
} else if (el.type == 'invoice-top-title') { | ||
content += `<p class="invoice-top-title" > ${el.name} </p>`; | ||
} else if (el.type == 'invoice-header') { | ||
content += `<h2 class="invoice-header" > ${el.name} </h2>`; | ||
} else if (el.type == 'invoice-footer') { | ||
content += `<h2 class="invoice-footer" > ${el.name} </h2>`; | ||
} else if (el.type == 'invoice-logo') { | ||
content += `<div class="invoice-logo" > <img src="${el.url}" /> </div>`; | ||
} else if (el.type == 'title') { | ||
content += `<h1 class="title" > ${el.value} </h1>`; | ||
} else if (el.type == 'space') { | ||
content += `<br>`; | ||
} else if (el.type == 'invoice-code') { | ||
content += `<div class="invoice-code" > | ||
<div class="name"> ${el.name} </div> | ||
<div class="value"> ${el.value} </div> | ||
</div>`; | ||
} else if (el.type == 'invoice-date') { | ||
content += `<div class="invoice-date" > | ||
<div class="name"> ${el.name} </div> | ||
<div class="value"> ${el.value} </div> | ||
</div>`; | ||
} else if (el.type == 'invoice-total') { | ||
content += `<div class="invoice-total" > | ||
<div class="name"> ${el.name} </div> | ||
<div class="value"> ${el.value} </div> | ||
</div>`; | ||
} else if (el.type == 'invoice-item-title') { | ||
content += ` | ||
<div class="invoice-item-title"> | ||
<div class="count"> ${el.count} </div> | ||
<div class="name"> ${el.name} </div> | ||
<div class="price"> ${el.price} </div> | ||
</div> | ||
`; | ||
} else if (el.type == 'invoice-item') { | ||
content += ` | ||
<div class="invoice-item"> | ||
<div class="count"> ${el.count} </div> | ||
<div class="name"> ${el.name} </div> | ||
<div class="price"> ${el.price} </div> | ||
</div> | ||
`; | ||
} else if (el.type == 'invoice-barcode') { | ||
content += `<div class="invoice-barcode" > | ||
<svg class="barcode" | ||
jsbarcode-format="auto" | ||
jsbarcode-value="${el.value}" | ||
jsbarcode-textmargin="0" | ||
jsbarcode-fontoptions="bold"> | ||
</svg> | ||
</div>`; | ||
} | ||
}); | ||
} | ||
let html = ` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Printing Viewer</title> | ||
<script src="http://127.0.0.1:60080/js/JsBarcode.all.min.js"></script> | ||
<link rel="stylesheet" href="http://127.0.0.1:60080/css/printing.css"> | ||
</head> | ||
<body> | ||
${content} | ||
<script> | ||
JsBarcode(".barcode").init(); | ||
</script> | ||
</body> | ||
</html> | ||
`; | ||
return html; | ||
}; | ||
}; |
@@ -19,9 +19,14 @@ module.exports = function init(browser) { | ||
browser.call = function (channel, value) { | ||
browser.mainWindow.send(channel, value) | ||
browser.window_list.forEach(view => { | ||
let win = browser.electron.BrowserWindow.fromId(view.id) | ||
if (win) { | ||
win.send(channel, value) | ||
} | ||
}); | ||
if(browser.mainWindow){ | ||
browser.mainWindow.send(channel, value) | ||
} | ||
if(browser.window_list){ | ||
browser.window_list.forEach(view => { | ||
let win = browser.electron.BrowserWindow.fromId(view.id) | ||
if (win) { | ||
win.send(channel, value) | ||
} | ||
}); | ||
} | ||
} | ||
@@ -28,0 +33,0 @@ } |
module.exports = function (browser) { | ||
browser.sessionConfig = () => { | ||
const { app, session, dialog, ipcMain, protocol, BrowserWindow } = browser.electron; | ||
const { | ||
app, | ||
session, | ||
dialog, | ||
ipcMain, | ||
protocol, | ||
BrowserWindow | ||
} = browser.electron | ||
// protocol.registerHttpProtocol( | ||
@@ -32,26 +21,20 @@ // "browser", | ||
let old_sessions = []; | ||
let old_sessions = [] | ||
browser.handleSessions = function () { | ||
browser.var.session_list.push({}) | ||
browser.var.session_list.forEach(s1 => { | ||
let is_new_session = true | ||
old_sessions.forEach(os => { | ||
browser.var.session_list.push({}); | ||
browser.var.session_list.forEach((s1) => { | ||
let is_new_session = true; | ||
old_sessions.forEach((os) => { | ||
if (os.name === s1.name) { | ||
is_new_session = false | ||
is_new_session = false; | ||
} | ||
}) | ||
}); | ||
if (is_new_session) { | ||
old_sessions.push(s1) | ||
old_sessions.push(s1); | ||
} | ||
let ss = s1.name == null ? browser.session.defaultSession : browser.session.fromPartition(s1.name); | ||
let ss = s1.name == null ? browser.session.defaultSession : browser.session.fromPartition(s1.name) | ||
// if (browser.var.internet_speed.type == 'custom') { | ||
@@ -93,6 +76,9 @@ // console.log('enableNetworkEmulation custom ' + s1.name) | ||
if (browser.var.proxy.enabled && browser.var.proxy.url) { | ||
ss.setProxy({ | ||
proxyRules: browser.var.proxy.url, | ||
proxyBypassRules: '127.0.0.1' | ||
}, function () {}); | ||
ss.setProxy( | ||
{ | ||
proxyRules: browser.var.proxy.url, | ||
proxyBypassRules: '127.0.0.1', | ||
}, | ||
function () {}, | ||
); | ||
} else { | ||
@@ -102,12 +88,11 @@ ss.setProxy({}, function () {}); | ||
ss.allowNTLMCredentialsForDomains('*') | ||
ss.userAgent = browser.var.core.user_agent | ||
ss.allowNTLMCredentialsForDomains('*'); | ||
ss.userAgent = browser.var.core.user_agent; | ||
if (is_new_session) { | ||
ss.protocol.registerHttpProtocol("browser", (request, callback) => { | ||
let url = request.url.substr(10) | ||
url = `http://127.0.0.1:60080/${url}` | ||
request.url = url | ||
callback(request) | ||
ss.protocol.registerHttpProtocol('browser', (request, callback) => { | ||
let url = request.url.substr(10); | ||
url = `http://127.0.0.1:60080/${url}`; | ||
request.url = url; | ||
callback(request); | ||
// callback({ | ||
@@ -117,5 +102,5 @@ // url : request.url, | ||
// session : request.session, | ||
// uploadData : request.uploadData | ||
// uploadData : request.uploadData | ||
// }) | ||
}) | ||
}); | ||
@@ -131,200 +116,185 @@ // ss.protocol.registerHttpProtocol("chrome-extension", (request, callback) => { | ||
// // session : request.session, | ||
// // uploadData : request.uploadData | ||
// // uploadData : request.uploadData | ||
// // }) | ||
// }) | ||
const filter = { | ||
urls: ["*://*/*"] | ||
} | ||
urls: ['*://*/*'], | ||
}; | ||
let ids = [] | ||
function add_id(id) { | ||
if (ids.indexOf(id) === -1) { | ||
ids.push(id) | ||
setTimeout(() => { | ||
ids.splice(ids.indexOf(id)) | ||
}, 1000 * 10); | ||
ss.webRequest.onBeforeRequest(filter, function (details, callback) { | ||
if(details.url.like('*google.com*')){ | ||
callback({ | ||
cancel: false, | ||
requestHeaders: details.requestHeaders, | ||
}); | ||
return | ||
} | ||
} | ||
let url = details.url.toLowerCase(); | ||
let source_url = details['referrer'] || details['host'] || url; | ||
source_url = source_url.toLowerCase(); | ||
ss.webRequest.onBeforeRequest(filter, function (details, callback) { | ||
let url = details.url.toLowerCase() | ||
let source_url = details['referrer'] || details['host'] || url | ||
source_url = source_url.toLowerCase() | ||
if (url.like('localhost*')) { | ||
callback({ | ||
cancel: true, | ||
redirectURL: details.url.replace('localhost:', 'http://localhost:') | ||
}) | ||
return | ||
redirectURL: details.url.replace('localhost:', 'http://localhost:'), | ||
}); | ||
return; | ||
} | ||
// protect from know login info | ||
if (!url.contains(source_url) && url.like('*favicon.ico*')) { | ||
callback({ | ||
cancel: true | ||
}) | ||
return | ||
cancel: true, | ||
}); | ||
return; | ||
} | ||
let end = false | ||
browser.var.overwrite.urls.forEach(data => { | ||
let end = false; | ||
browser.var.overwrite.urls.forEach((data) => { | ||
if (end) { | ||
return | ||
return; | ||
} | ||
if (url.like(data.from)) { | ||
// console.log(`\nAuto overwrite redirect \n ${data.to} \n `) | ||
let q = url.split('?')[1] | ||
let q = url.split('?')[1]; | ||
if (q) { | ||
q = '?' + q | ||
q = '?' + q; | ||
} else { | ||
q = '' | ||
q = ''; | ||
} | ||
callback({ | ||
cancel: false, | ||
redirectURL: data.to + q | ||
}) | ||
end = true | ||
return | ||
redirectURL: data.to + q, | ||
}); | ||
end = true; | ||
return; | ||
} | ||
}) | ||
}); | ||
if (end) { | ||
return | ||
return; | ||
} | ||
browser.var.white_list.forEach(s => { | ||
browser.var.white_list.forEach((s) => { | ||
if (end) { | ||
return | ||
return; | ||
} | ||
if (source_url.like(s.url)) { | ||
if (s.url.length > 2 && source_url.like(s.url)) { | ||
callback({ | ||
cancel: false | ||
}) | ||
end = true | ||
return | ||
cancel: false, | ||
}); | ||
end = true; | ||
return; | ||
} | ||
}) | ||
}); | ||
if (end) { | ||
return | ||
return; | ||
} | ||
if (browser.var.black_list) { | ||
browser.var.black_list.forEach(s => { | ||
browser.var.black_list.forEach((s) => { | ||
if (url.like(s.url)) { | ||
end = true | ||
// console.log(`\n Block black_list : ${s.url} \n`) | ||
end = true; | ||
console.log(`\n Block black_list : ${s.url} \n`); | ||
} | ||
}) | ||
}); | ||
if (end) { | ||
callback({ | ||
cancel: true | ||
}) | ||
cancel: true, | ||
}); | ||
browser.call('user_info', { | ||
message: 'Black List Blocked :: ' + url, | ||
class: 'bg-red' | ||
}) | ||
class: 'bg-red', | ||
}); | ||
return | ||
return; | ||
} | ||
} | ||
if (browser.var.blocking.allow_safty_mode) { | ||
browser.var.blocking.un_safe_list.forEach(s => { | ||
browser.var.blocking.un_safe_list.forEach((s) => { | ||
if (url.like(s.url)) { | ||
end = true | ||
// console.log(`\n Block un_safe_list : ${s.url} \n`) | ||
end = true; | ||
console.log(`\n Block un_safe_list : ${s.url} \n`); | ||
} | ||
}) | ||
}); | ||
if (end) { | ||
callback({ | ||
cancel: true | ||
}) | ||
cancel: true, | ||
}); | ||
browser.call('user_info', { | ||
message: 'un Safty List Blocked :: ' + url, | ||
class: 'bg-red' | ||
}) | ||
class: 'bg-red', | ||
}); | ||
return | ||
return; | ||
} | ||
} | ||
if (browser.var.blocking.block_ads) { | ||
browser.var.blocking.ad_list.forEach(l => { | ||
browser.var.blocking.ad_list.forEach((l) => { | ||
if (url.like(l.url)) { | ||
end = true | ||
// console.log(`\n Block Ads : ${l.url} \n ${url} \n`) | ||
end = true; | ||
//console.log(`\n Block Ads : ${l.url} \n ${url} \n`); | ||
} | ||
}) | ||
}); | ||
if (end) { | ||
callback({ | ||
cancel: true | ||
}) | ||
cancel: true, | ||
}); | ||
browser.call('user_info', { | ||
message: 'Ads List Blocked :: ' + details.url, | ||
class: 'bg-red' | ||
}) | ||
class: 'bg-red', | ||
}); | ||
return | ||
return; | ||
} | ||
} | ||
// continue loading url | ||
callback({ | ||
cancel: false | ||
}) | ||
cancel: false, | ||
}); | ||
}); | ||
}) | ||
ss.webRequest.onBeforeSendHeaders(filter, function (details, callback) { | ||
if(details.url.like('*google.com*')){ | ||
callback({ | ||
cancel: false, | ||
requestHeaders: details.requestHeaders, | ||
}); | ||
return | ||
} | ||
let exit = false; | ||
let exit = false | ||
let url = details.url.toLowerCase() | ||
let source_url = details['referrer'] || details['host'] || url | ||
let url = details.url.toLowerCase(); | ||
// console.log(details); | ||
let source_url = details['referrer'] || details['Referer'] || details['Host'] || details['host'] || url; | ||
if (source_url) { | ||
source_url = source_url.toLowerCase() | ||
source_url = source_url.toLowerCase(); | ||
} | ||
let d = new Date().getTime() | ||
details.requestHeaders = details.requestHeaders || {} | ||
let d = browser.startTime.toString().substring(0, 9); | ||
details.requestHeaders = details.requestHeaders || {}; | ||
// details.requestHeaders['x-browser'] = `social-browser-${browser.var.core.id}-${d}`; | ||
if (browser.var.blocking.privacy.dnt) { | ||
details.requestHeaders['DNT'] = "1"; // dont track me | ||
} | ||
details.requestHeaders['User-Agent'] = browser.var.core.user_agent; | ||
browser.var.sites.forEach(site=>{ | ||
if(url.like(site.url)){ | ||
details.requestHeaders['User-Agent'] = site.user_agent | ||
browser.var.sites.forEach((site) => { | ||
if (url.like(site.url)) { | ||
details.requestHeaders['User-Agent'] = site.user_agent; | ||
} | ||
}) | ||
}); | ||
if (url.contains('embed')) { | ||
if (url.like('*youtu.be*|*www.youtube.com*')) { | ||
details.requestHeaders['Host'] = 'https://www.youtube.com/'; | ||
details.requestHeaders['Referer'] = 'https://www.youtube.com/'; | ||
// console.log(' [ .. youtube video hack .. ] ' , details.requestHeaders) | ||
} else if (url.contains('embed')) { | ||
details.requestHeaders['referer'] = details.requestHeaders['referer'] || url; | ||
@@ -334,6 +304,4 @@ details.requestHeaders['sec-fetch-dest'] = `iframe`; | ||
delete details.requestHeaders['sec-fetch-user']; | ||
} | ||
//details.requestHeaders['Referrer-Policy'] = 'no-referrer'; | ||
@@ -343,73 +311,89 @@ | ||
// console.log(details.requestHeaders['Cookie']) | ||
if (!url.like('*google.com*|*youtube.com*')) { | ||
if (browser.var.blocking.privacy.dnt) { | ||
details.requestHeaders['DNT'] = '1'; // dont track me | ||
} | ||
} | ||
if (!url.like('*google.com*|*youtube.com*') && details.requestHeaders['Cookie']) { | ||
let cookie_obj = browser.cookieParse(details.requestHeaders['Cookie']); | ||
if (!url.like('*.google.*|*youtube.com*') && details.requestHeaders['Cookie']) { | ||
let cookie_obj = browser.cookieParse(details.requestHeaders['Cookie']) | ||
if (browser.var.blocking.privacy.hide_gid) { | ||
cookie_obj['_ga'] = 'GA1.2.' + d + 'sb.' + d; | ||
if (cookie_obj['_gid']) { | ||
cookie_obj['_gid'] = 'GA1.' + d | ||
cookie_obj['_gid'] = cookie_obj['_ga']; | ||
} | ||
} else { | ||
details.requestHeaders['x-browser'] = `social-browser-${browser.var.core.id}-${d}`; | ||
} | ||
cookie_obj['_ga'] = 'GA1.sb' + d | ||
if (browser.var.blocking.privacy.block_cloudflare) { | ||
if (cookie_obj['_cflb']) { | ||
cookie_obj['_cflb'] = 'cf.' + cookie_obj['_ga']; | ||
} | ||
if (cookie_obj['_cflb']) { | ||
cookie_obj['_cflb'] = 'cf.' + d | ||
} | ||
if (cookie_obj['_cf_bm']) { | ||
cookie_obj['_cf_bm'] = 'cf.' + cookie_obj['_ga']; | ||
} | ||
if (cookie_obj['_cf_bm']) { | ||
cookie_obj['_cf_bm'] = 'cf.' + d | ||
} | ||
if (cookie_obj['_cfduid']) { | ||
cookie_obj['_cfduid'] = 'cf.' + cookie_obj['_ga']; | ||
} | ||
if (cookie_obj['_cfduid']) { | ||
cookie_obj['_cfduid'] = 'cf.' + d | ||
if (cookie_obj['__cfduid']) { | ||
cookie_obj['__cfduid'] = 'cf.' + cookie_obj['_ga']; | ||
} | ||
} | ||
if (cookie_obj['__cfduid']) { | ||
cookie_obj['__cfduid'] = 'cf.' + d | ||
let cookie_string = browser.cookieStringify(cookie_obj); | ||
details.requestHeaders['Cookie'] = cookie_string; | ||
} else if (!url.like('*google.com*|*youtube.com*') && !details.requestHeaders['Cookie']) { | ||
let cookie_obj = {}; | ||
if (browser.var.blocking.privacy.hide_gid) { | ||
cookie_obj['_ga'] = 'GA1.2.' + d + 'sb.' + d; | ||
} else { | ||
details.requestHeaders['x-browser'] = `social-browser-${browser.var.core.id}-${d}`; | ||
} | ||
let cookie_string = browser.cookieStringify(cookie_obj) | ||
details.requestHeaders['Cookie'] = cookie_string | ||
} else if (!url.like('*google.com*|*youtube.com*') && !details.requestHeaders['Cookie']) { | ||
let cookie_obj = {} | ||
cookie_obj['_ga'] = 'GA1.sb' + d | ||
let cookie_string = browser.cookieStringify(cookie_obj) | ||
details.requestHeaders['Cookie'] = cookie_string | ||
let cookie_string = browser.cookieStringify(cookie_obj); | ||
details.requestHeaders['Cookie'] = cookie_string; | ||
} else if (url.like('browser*') || url.like('http://127.0.0.1*') || url.like('https://127.0.0.1*')) { | ||
let cookie_obj = details.requestHeaders['Cookie'] ? browser.cookieParse(details.requestHeaders['Cookie']) : {} | ||
cookie_obj['_ga'] = 'GA1.sb' + d | ||
let cookie_string = browser.cookieStringify(cookie_obj) | ||
details.requestHeaders['Cookie'] = cookie_string | ||
let cookie_obj = details.requestHeaders['Cookie'] ? browser.cookieParse(details.requestHeaders['Cookie']) : {}; | ||
cookie_obj['_ga'] = 'GA1.2.' + d + 'sb.' + d; | ||
let cookie_string = browser.cookieStringify(cookie_obj); | ||
details.requestHeaders['Cookie'] = cookie_string; | ||
} | ||
if (url.like('browser*') || url.like('http://127.0.0.1*') || url.like('https://127.0.0.1*')) { | ||
exit = true | ||
exit = true; | ||
callback({ | ||
cancel: false, | ||
requestHeaders: details.requestHeaders | ||
}) | ||
requestHeaders: details.requestHeaders, | ||
}); | ||
if (exit) { | ||
return | ||
return; | ||
} | ||
} | ||
// continue loading url | ||
callback({ | ||
cancel: false, | ||
requestHeaders: details.requestHeaders | ||
}) | ||
requestHeaders: details.requestHeaders, | ||
}); | ||
browser.call('user_info', { | ||
message: 'Loading :: ' + details.url | ||
}) | ||
}) | ||
message: 'Loading :: ' + details.url, | ||
}); | ||
}); | ||
ss.webRequest.onHeadersReceived(filter, function (details, callback) { | ||
if(details.url.like('*google.com*')){ | ||
callback({ | ||
cancel: false, | ||
responseHeaders: { | ||
...details.responseHeaders, | ||
}, | ||
statusLine: details.statusLine, | ||
}); | ||
return | ||
} | ||
// delete details.responseHeaders['x-frame-options'] // sameorigin | deny | ||
@@ -422,148 +406,138 @@ // delete details.responseHeaders['Content-Security-Policy'] | ||
let a_orgin = details.responseHeaders['Access-Control-Allow-Origin'] || details.responseHeaders['Access-Control-Allow-Origin'.toLowerCase()] | ||
let a_Headers = details.responseHeaders['Access-Control-Allow-Headers'] || details.responseHeaders['Access-Control-Allow-Headers'.toLowerCase()] | ||
let a_Methods = details.responseHeaders['Access-Control-Allow-Methods'] || details.responseHeaders['Access-Control-Allow-Methods'.toLowerCase()] | ||
let a_orgin = details.responseHeaders['Access-Control-Allow-Origin'] || details.responseHeaders['Access-Control-Allow-Origin'.toLowerCase()]; | ||
let a_Headers = details.responseHeaders['Access-Control-Allow-Headers'] || details.responseHeaders['Access-Control-Allow-Headers'.toLowerCase()]; | ||
let a_Methods = details.responseHeaders['Access-Control-Allow-Methods'] || details.responseHeaders['Access-Control-Allow-Methods'.toLowerCase()]; | ||
['Cross-Origin-Embedder-Policy','Cross-Origin-Opener-Policy','Strict-Transport-Security','Cross-Origin-Resource-Policy','X-XSS-Protection','X-Content-Type-Options','Content-Security-Policy-Report-Only','Content-Security-Policy','Access-Control-Allow-Credentials', 'Access-Control-Allow-Methods', 'Access-Control-Allow-Headers', 'Access-Control-Allow-Origin', 'X-Frame-Options'].forEach((p) => { | ||
delete details.responseHeaders[p]; | ||
delete details.responseHeaders[p.toLowerCase()]; | ||
}); | ||
delete details.responseHeaders['Access-Control-Allow-Credentials'] | ||
delete details.responseHeaders['Access-Control-Allow-Methods'] | ||
delete details.responseHeaders['Access-Control-Allow-Headers'] | ||
delete details.responseHeaders['Access-Control-Allow-Origin'] | ||
delete details.responseHeaders['x-frame-options'] | ||
details.responseHeaders['Access-Control-Allow-Credentials'.toLowerCase()] = 'true'; | ||
details.responseHeaders['Access-Control-Allow-Methods'.toLowerCase()] = a_Methods || 'POST,GET,DELETE,PUT,OPTIONS,VIEW,HEAD,CONNECT,TRACE'; | ||
details.responseHeaders['Access-Control-Allow-Headers'.toLowerCase()] = | ||
a_Headers || 'Authorization ,Access-Control-Allow-Headers, Access-Control-Request-Method, Access-Control-Request-Headers,Origin, X-Requested-With, Content-Type, Accept'; | ||
details.responseHeaders['Access-Control-Allow-Origin'.toLowerCase()] = a_orgin || '*'; | ||
details.responseHeaders['X-Browser'.toLowerCase()] = 'social browser'; | ||
details.responseHeaders['X-XSS-Protection'.toLowerCase()] = '0'; | ||
details.responseHeaders['Cross-Origin-Resource-Policy'.toLowerCase()] = 'cross-origin'; | ||
delete details.responseHeaders['Access-Control-Allow-Credentials'.toLowerCase()] | ||
delete details.responseHeaders['Access-Control-Allow-Methods'.toLowerCase()] | ||
delete details.responseHeaders['Access-Control-Allow-Headers'.toLowerCase()] | ||
delete details.responseHeaders['Access-Control-Allow-Origin'.toLowerCase()] | ||
delete details.responseHeaders['x-frame-options'.toLowerCase()] | ||
details.responseHeaders["Access-Control-Allow-Credentials".toLowerCase()] = "true" | ||
details.responseHeaders["Access-Control-Allow-Methods".toLowerCase()] = a_Methods || "POST,GET,DELETE,PUT,OPTIONS,VIEW,HEAD,CONNECT,TRACE" | ||
details.responseHeaders["Access-Control-Allow-Headers".toLowerCase()] = a_Headers || "Authorization ,Access-Control-Allow-Headers, Access-Control-Request-Method, Access-Control-Request-Headers,Origin, X-Requested-With, Content-Type, Accept" | ||
details.responseHeaders["Access-Control-Allow-Origin".toLowerCase()] = a_orgin || "*" | ||
callback({ | ||
cancel: false, | ||
responseHeaders: { | ||
...details.responseHeaders | ||
...details.responseHeaders, | ||
}, | ||
statusLine: details.statusLine | ||
}) | ||
}) | ||
ss.webRequest.onResponseStarted(filter, function (details) { | ||
statusLine: details.statusLine, | ||
}); | ||
}) | ||
ss.webRequest.onBeforeRedirect(filter, function (details) { | ||
}); | ||
ss.webRequest.onResponseStarted(filter, function (details) {}); | ||
ss.webRequest.onBeforeRedirect(filter, function (details) {}); | ||
ss.webRequest.onCompleted(filter, function (details) {}); | ||
ss.webRequest.onErrorOccurred(filter, function (details) {}); | ||
}) | ||
ss.webRequest.onCompleted(filter, function (details) { | ||
}) | ||
ss.webRequest.onErrorOccurred(filter, function (details) { | ||
}) | ||
ss.setPermissionRequestHandler((webContents, permission, callback) => { | ||
// Enum of 'media', 'geolocation', 'notifications', 'midiSysex', 'pointerLock', 'fullscreen', 'openExternal'. | ||
if (webContents.getURL().like('http://127.0.0.1*')) { | ||
callback(true) | ||
return | ||
if (webContents.getURL().like('*127.0.0.1*')) { | ||
console.log(` \n << permission asked and Allow : ${permission} , from ${webContents.getURL()} \n `); | ||
callback(true); | ||
return; | ||
} else { | ||
if (permission === 'fullscreen' || permission === 'openExternal') { | ||
callback(true) | ||
return | ||
console.log(` \n << permission asked and Allow : ${permission} , from ${webContents.getURL()} \n `); | ||
callback(true); | ||
return; | ||
} | ||
console.log(` \n << permission asked and Blocked : ${permission} , from ${webContents.getURL()} \n `) | ||
callback(false) | ||
return | ||
console.log(` \n << permission asked and Blocked : ${permission} , from ${webContents.getURL()} \n `); | ||
callback(false); | ||
return; | ||
} | ||
}) | ||
}); | ||
ss.setPermissionCheckHandler((webContents, permission) => { | ||
// Enum of 'media', 'geolocation', 'notifications', 'midiSysex', 'pointerLock', 'fullscreen', 'openExternal'. | ||
if (webContents.getURL().like('http://127.0.0.1*')) { | ||
return true | ||
if (webContents.getURL().like('*127.0.0.1*')) { | ||
console.log(` \n << permission asked and Allow : ${permission} , from ${webContents.getURL()} \n `); | ||
return true; | ||
} else { | ||
if (permission === 'fullscreen' || permission === 'openExternal') { | ||
return true | ||
console.log(` \n << permission asked and Allow : ${permission} , from ${webContents.getURL()} \n `); | ||
return true; | ||
} | ||
console.log(`\n << setPermissionCheckHandler deny : ${permission} , from ${webContents.getURL()} \n `) | ||
return false | ||
console.log(`\n << setPermissionCheckHandler deny : ${permission} , from ${webContents.getURL()} \n `); | ||
return false; | ||
} | ||
}) | ||
}); | ||
ss.on('will-download', (event, item, webContents) => { | ||
console.log(' [ session will-download ] ') | ||
console.log(' [ session will-download ] '); | ||
if (browser.var.downloader.enabled && !item.getURL().like('*127.0.0.1*') && !item.getURL().like('blob*')) { | ||
if (browser.site.isFileExistsSync(browser.var.downloader.app)) { | ||
event.preventDefault() | ||
if (browser.last_download_url !== item.getURL()) { | ||
browser.last_download_url = item.getURL(); | ||
if (browser.var.downloader.enabled && !item.getURL().like('*127.0.0.1*') && !item.getURL().like('blob*')) { | ||
if (browser.site.isFileExistsSync(browser.var.downloader.app)) { | ||
event.preventDefault(); | ||
let dl = { | ||
date: new Date(), | ||
total: item.getTotalBytes(), | ||
received: item.getReceivedBytes(), | ||
name: item.getFilename().replace('#___new_tab___', '').replace('#___new_window__', '').replace('#___trusted_window___', ''), | ||
path: item.getSavePath(), | ||
url: item.getURL().replace('#___new_tab___', '').replace('#___new_window__', '').replace('#___trusted_window___', ''), | ||
id: item.id, | ||
canResume: item.canResume(), | ||
type: item.getMimeType(), | ||
status: 'starting' | ||
} | ||
let dl = { | ||
date: new Date(), | ||
total: item.getTotalBytes(), | ||
received: item.getReceivedBytes(), | ||
name: item.getFilename().replace('#___new_tab___', '').replace('#___new_window__', '').replace('#___trusted_window___', ''), | ||
path: item.getSavePath(), | ||
url: item.getURL().replace('#___new_tab___', '').replace('#___new_window__', '').replace('#___trusted_window___', ''), | ||
id: item.id, | ||
canResume: item.canResume(), | ||
type: item.getMimeType(), | ||
status: 'starting', | ||
}; | ||
browser.var.download_list = browser.var.download_list || [] | ||
browser.var.download_list.push(dl) | ||
browser.set_var('download_list', browser.var.download_list) | ||
browser.var.download_list = browser.var.download_list || []; | ||
browser.var.download_list.push(dl); | ||
browser.set_var('download_list', browser.var.download_list); | ||
let params = browser.var.downloader.params.split(' ') | ||
let params = browser.var.downloader.params.split(' '); | ||
for (const i in params) { | ||
params[i] = params[i].replace("$url", decodeURIComponent(dl.url)).replace("$file_name", dl.name) | ||
} | ||
for (const i in params) { | ||
params[i] = params[i].replace('$url', decodeURIComponent(dl.url)).replace('$file_name', dl.name); | ||
} | ||
browser.exe(browser.var.downloader.app, params) | ||
browser.exe(browser.var.downloader.app, params); | ||
return | ||
return; | ||
} | ||
} | ||
} | ||
console.log(' [ Bulit in will-download :::::::::: ] ') | ||
browser.views.forEach(v => { | ||
let win = BrowserWindow.fromId(v.id) | ||
browser.last_download_url = null; | ||
console.log(' [ Bulit in will-download :::::::::: ] '); | ||
browser.views.forEach((v) => { | ||
let win = BrowserWindow.fromId(v.id); | ||
if (win) { | ||
win.setAlwaysOnTop(false) | ||
win.setAlwaysOnTop(false); | ||
} | ||
}) | ||
}); | ||
item.id = browser.guid(); | ||
item.id = browser.guid() | ||
ipcMain.on('pause-item', (e, info) => { | ||
if (item.id === info.id) { | ||
item.pause(); | ||
item.pause() | ||
browser.var.download_list.forEach(dd => { | ||
browser.var.download_list.forEach((dd) => { | ||
if (dd.id === item.id) { | ||
dd.status = 'paused' | ||
dd.path = item.getSavePath() | ||
dd.status = 'paused'; | ||
dd.path = item.getSavePath(); | ||
} | ||
}) | ||
}); | ||
} | ||
}) | ||
}); | ||
ipcMain.on('remove-item', (e, info) => { | ||
if (item.id === info.id) { | ||
console.log('cancel download::' + info.url) | ||
item.cancel() | ||
//console.log('cancel download::' + info.url); | ||
item.cancel(); | ||
} | ||
}) | ||
}); | ||
@@ -573,17 +547,16 @@ ipcMain.on('resume-item', (e, info) => { | ||
if (item.canResume()) { | ||
item.resume() | ||
item.resume(); | ||
browser.var.download_list.forEach(dd => { | ||
browser.var.download_list.forEach((dd) => { | ||
if (dd.id === item.id) { | ||
dd.status = 'downloading' | ||
dd.path = item.getSavePath() | ||
dd.status = 'downloading'; | ||
dd.path = item.getSavePath(); | ||
} | ||
}) | ||
}); | ||
} | ||
} | ||
}) | ||
}); | ||
let url = item.getURL() | ||
let filename = item.getFilename() | ||
let url = item.getURL(); | ||
let filename = item.getFilename(); | ||
@@ -600,145 +573,134 @@ let dl = { | ||
type: item.getMimeType(), | ||
status: 'starting' | ||
} | ||
status: 'starting', | ||
}; | ||
browser.var.download_list.push(dl) | ||
browser.var.download_list.push(dl); | ||
item.on('updated', (event, state) => { | ||
if (!item.getSavePath()) { | ||
return | ||
return; | ||
} | ||
if (state === 'interrupted') { | ||
browser.var.download_list.forEach(dd => { | ||
browser.var.download_list.forEach((dd) => { | ||
if (dd.id === item.id) { | ||
browser.call('user_downloads', { | ||
message: " (interrupted )" + ` ${item.getFilename()} `, | ||
class: 'bg-red white' | ||
}) | ||
dd.status = 'error' | ||
dd.canResume = item.canResume() | ||
dd.type = item.getMimeType() | ||
dd.path = item.getSavePath() | ||
dd.name = item.getFilename() | ||
message: ' (interrupted )' + ` ${item.getFilename()} `, | ||
class: 'bg-red white', | ||
}); | ||
dd.status = 'error'; | ||
dd.canResume = item.canResume(); | ||
dd.type = item.getMimeType(); | ||
dd.path = item.getSavePath(); | ||
dd.name = item.getFilename(); | ||
} | ||
}) | ||
}); | ||
} else if (state === 'progressing') { | ||
if (item.isPaused()) { | ||
browser.var.download_list.forEach(dd => { | ||
browser.var.download_list.forEach((dd) => { | ||
if (dd.id === item.id) { | ||
dd.status = 'paused' | ||
dd.status = 'paused'; | ||
browser.call('user_downloads', { | ||
message: " Paused " + ` ${item.getFilename()} ( ${(item.getReceivedBytes()/1000000).toFixed(2)} MB / ${(item.getTotalBytes()/1000000).toFixed(2)} MB )`, | ||
class: 'bg-orange black' | ||
}) | ||
dd.type = item.getMimeType() | ||
dd.path = item.getSavePath() | ||
dd.name = item.getFilename() | ||
dd.canResume = item.canResume() | ||
progress: (item.getReceivedBytes() / item.getTotalBytes()).toFixed(2), | ||
message: ' Paused ' + ` ${item.getFilename()} ( ${(item.getReceivedBytes() / 1000000).toFixed(2)} MB / ${(item.getTotalBytes() / 1000000).toFixed(2)} MB )`, | ||
class: 'bg-orange black', | ||
}); | ||
dd.type = item.getMimeType(); | ||
dd.path = item.getSavePath(); | ||
dd.name = item.getFilename(); | ||
dd.canResume = item.canResume(); | ||
} | ||
}) | ||
}); | ||
} else { | ||
browser.var.download_list.forEach(dd => { | ||
browser.var.download_list.forEach((dd) => { | ||
if (dd.id === item.id) { | ||
browser.call('user_downloads', { | ||
message: ` ( ${(item.getReceivedBytes()/1000000).toFixed(2)} MB / ${(item.getTotalBytes()/1000000).toFixed(2)} MB ) ${item.getFilename()}`, | ||
class: 'bg-blue white' | ||
}) | ||
dd.type = item.getMimeType() | ||
dd.path = item.getSavePath() | ||
dd.name = item.getFilename() | ||
dd.canResume = item.canResume() | ||
dd.total = item.getTotalBytes() | ||
dd.received = item.getReceivedBytes() | ||
dd.status = 'downloading' | ||
progress: (item.getReceivedBytes() / item.getTotalBytes()).toFixed(2), | ||
message: ` ( ${(item.getReceivedBytes() / 1000000).toFixed(2)} MB / ${(item.getTotalBytes() / 1000000).toFixed(2)} MB ) ${item.getFilename()}`, | ||
class: 'bg-blue white', | ||
}); | ||
dd.type = item.getMimeType(); | ||
dd.path = item.getSavePath(); | ||
dd.name = item.getFilename(); | ||
dd.canResume = item.canResume(); | ||
dd.total = item.getTotalBytes(); | ||
dd.received = item.getReceivedBytes(); | ||
dd.status = 'downloading'; | ||
} | ||
}) | ||
}); | ||
} | ||
} | ||
}) | ||
}); | ||
item.once('done', (event, state) => { | ||
if (!item.getSavePath()) { | ||
return | ||
return; | ||
} | ||
if (state === 'completed') { | ||
browser.call('user_downloads', { | ||
message: " ( 100% ) " + ` ${item.getFilename()} `, | ||
class: 'bg-green white' | ||
}) | ||
progress: 0, | ||
message: ' ( 100% ) ' + ` ${item.getFilename()} `, | ||
class: 'bg-green white', | ||
}); | ||
browser.var.download_list.forEach(dd => { | ||
browser.var.download_list.forEach((dd) => { | ||
if (dd.id === item.id) { | ||
dd.name = item.getFilename() | ||
dd.type = item.getMimeType() | ||
dd.total = item.getTotalBytes() | ||
dd.canResume = item.canResume() | ||
dd.received = item.getReceivedBytes() | ||
dd.status = 'completed' | ||
dd.path = item.getSavePath() | ||
dd.name = item.getFilename(); | ||
dd.type = item.getMimeType(); | ||
dd.total = item.getTotalBytes(); | ||
dd.canResume = item.canResume(); | ||
dd.received = item.getReceivedBytes(); | ||
dd.status = 'completed'; | ||
dd.path = item.getSavePath(); | ||
} | ||
}) | ||
}); | ||
browser.set_var('download_list', browser.var.download_list) | ||
let _path = item.getSavePath() | ||
let _url = item.getURL().replace('#___new_tab___', '').replace('#___new_window__', '').replace('#___trusted_window___', '') | ||
browser.backAllViews() | ||
browser.dialog.showMessageBox({ | ||
title: "Download Complete", | ||
type: "info", | ||
buttons: ["Open File", "Open Folder", "Close"], | ||
message: `Saved URL \n ${_url} \n To \n ${_path} ` | ||
}).then( | ||
result => { | ||
console.log(result) | ||
browser.shell.beep() | ||
browser.set_var('download_list', browser.var.download_list); | ||
let _path = item.getSavePath(); | ||
let _url = item.getURL().replace('#___new_tab___', '').replace('#___new_window__', '').replace('#___trusted_window___', ''); | ||
browser.backAllViews(); | ||
browser.dialog | ||
.showMessageBox({ | ||
title: 'Download Complete', | ||
type: 'info', | ||
buttons: ['Open File', 'Open Folder', 'Close'], | ||
message: `Saved URL \n ${_url} \n To \n ${_path} `, | ||
}) | ||
.then((result) => { | ||
// console.log(result); | ||
browser.shell.beep(); | ||
if (result.response == 1) { | ||
browser.shell.showItemInFolder(_path) | ||
browser.shell.showItemInFolder(_path); | ||
} | ||
if (result.response == 0) { | ||
browser.shell.openItem(_path) | ||
browser.shell.openItem(_path); | ||
} | ||
} | ||
) | ||
}); | ||
} else { | ||
browser.var.download_list.forEach(dd => { | ||
browser.var.download_list.forEach((dd) => { | ||
if (dd.id === item.id) { | ||
browser.call('user_downloads', { | ||
message: " ( Error ) " + ` ${item.getFilename()} ==> ${state} `, | ||
class: 'bg-red white' | ||
}) | ||
dd.name = item.getFilename() | ||
dd.type = item.getMimeType() | ||
dd.total = item.getTotalBytes() | ||
dd.canResume = item.canResume() | ||
dd.received = item.getReceivedBytes() | ||
dd.status = state | ||
dd.path = item.getSavePath() | ||
message: ' ( Error ) ' + ` ${item.getFilename()} ==> ${state} `, | ||
class: 'bg-red white', | ||
}); | ||
dd.name = item.getFilename(); | ||
dd.type = item.getMimeType(); | ||
dd.total = item.getTotalBytes(); | ||
dd.canResume = item.canResume(); | ||
dd.received = item.getReceivedBytes(); | ||
dd.status = state; | ||
dd.path = item.getSavePath(); | ||
} | ||
}) | ||
browser.set_var('download_list', browser.var.download_list) | ||
}); | ||
browser.set_var('download_list', browser.var.download_list); | ||
} | ||
}) | ||
}) | ||
}); | ||
}); | ||
} | ||
}) | ||
browser.var.session_list.pop() | ||
}); | ||
browser.var.session_list.pop(); | ||
}; | ||
} | ||
browser.handleSessions() | ||
} | ||
} | ||
browser.handleSessions(); | ||
}; | ||
}; |
1202
lib/windows.js
module.exports = function init(browser) { | ||
const electron = browser.electron; | ||
const { BrowserWindow, nativeImage, dialog, BrowserWindowProxy, ipcMain } = electron; | ||
const electron = browser.electron | ||
const { | ||
BrowserWindow, | ||
nativeImage, | ||
dialog, | ||
BrowserWindowProxy, | ||
ipcMain | ||
} = electron | ||
browser.window_list = []; | ||
browser.icons = []; | ||
browser.icons['darwin'] = browser.path.join(browser.files_dir, 'images', 'logo.icns'); | ||
browser.icons['linux'] = browser.path.join(browser.files_dir, 'images', 'logo.png'); | ||
browser.icons['win32'] = browser.path.join(browser.files_dir, 'images', 'logo.ico'); | ||
browser.window_list = [] | ||
browser.icons = [] | ||
browser.icons['darwin'] = browser.path.join(browser.files_dir, "images", "logo.icns") | ||
browser.icons['linux'] = browser.path.join(browser.files_dir, "images", "logo.png") | ||
browser.icons['win32'] = browser.path.join(browser.files_dir, "images", "logo.ico") | ||
function newWindowEvent(event, url, frameName, disposition, options, additionalFeatures) { | ||
event.preventDefault(); | ||
event.preventDefault() | ||
console.log('newWindowEvent'); | ||
let view = browser.getView(this.id) || browser.current_view; | ||
console.log('newWindowEvent') | ||
let y_url = url || event.url || ''; | ||
let view = browser.getView(this.id) || browser.current_view | ||
let y_url = url || event.url || '' | ||
if (y_url.like('https://www.youtube.com/watch*')) { | ||
url = 'https://www.youtube.com/embed/' + y_url.split('=')[1].split('&')[0] | ||
url = 'https://www.youtube.com/embed/' + y_url.split('=')[1].split('&')[0]; | ||
browser.newYoutubeWindow({ | ||
url: y_url, | ||
partition: view.partition, | ||
user_name: view.user_name | ||
}) | ||
return | ||
user_name: view.user_name, | ||
}); | ||
return; | ||
} else if (y_url.like('https://www.youtube.com/embed*')) { | ||
@@ -42,17 +32,15 @@ browser.newYoutubeWindow({ | ||
partition: view.partition, | ||
user_name: view.user_name | ||
}) | ||
return | ||
user_name: view.user_name, | ||
}); | ||
return; | ||
} | ||
event.options = event.options || { | ||
url: url | ||
} | ||
url: url, | ||
}; | ||
let url_p = browser.url.parse(event.options.url); | ||
console.log('call new url from new window ', event.options.url); | ||
console.log(view); | ||
let url_p = browser.url.parse(event.options.url) | ||
console.log('call new url from new window ', event.options.url) | ||
console.log(view) | ||
if (event.options.url.like('*#___new_tab___*')) { | ||
@@ -63,5 +51,5 @@ browser.call('render_message', { | ||
partition: view.partition, | ||
user_name: view.user_name | ||
}) | ||
return | ||
user_name: view.user_name, | ||
}); | ||
return; | ||
} | ||
@@ -75,5 +63,5 @@ | ||
partition: view.partition, | ||
user_name: view.user_name | ||
}) | ||
return | ||
user_name: view.user_name, | ||
}); | ||
return; | ||
} | ||
@@ -88,11 +76,10 @@ | ||
partition: view.partition, | ||
user_name: view.user_name | ||
}) | ||
return | ||
user_name: view.user_name, | ||
}); | ||
return; | ||
} | ||
let url2_p = browser.url.parse(this.getURL()); | ||
let url2_p = browser.url.parse(this.getURL()) | ||
if (url_p.host === url2_p.host && browser.var.blocking.popup.allow_internal) { | ||
if (url_p.host.contains(url2_p.host) && browser.var.blocking.popup.allow_internal) { | ||
browser.call('render_message', { | ||
@@ -102,5 +89,5 @@ name: 'open new tab', | ||
partition: view.partition, | ||
user_name: view.user_name | ||
}) | ||
} else if (url_p.host !== url2_p.host && browser.var.blocking.popup.allow_external) { | ||
user_name: view.user_name, | ||
}); | ||
} else if (!url_p.host.contains(url2_p.host) && browser.var.blocking.popup.allow_external) { | ||
browser.call('render_message', { | ||
@@ -110,11 +97,11 @@ name: 'open new tab', | ||
partition: view.partition, | ||
user_name: view.user_name | ||
}) | ||
user_name: view.user_name, | ||
}); | ||
} else { | ||
let allow = false | ||
browser.var.blocking.popup.white_list.forEach(d => { | ||
let allow = false; | ||
browser.var.blocking.popup.white_list.forEach((d) => { | ||
if (url_p.host.like(d.url) || url2_p.host.like(d.url)) { | ||
allow = true | ||
allow = true; | ||
} | ||
}) | ||
}); | ||
if (allow) { | ||
@@ -125,4 +112,4 @@ browser.call('render_message', { | ||
partition: view.partition, | ||
user_name: view.user_name | ||
}) | ||
user_name: view.user_name, | ||
}); | ||
} else { | ||
@@ -133,15 +120,13 @@ //console.log('Block Popup : ' + url) | ||
} | ||
} | ||
browser.handleViewPosition = function (win) { | ||
if (!win) { | ||
return | ||
if (!win || win.isDestroyed()) { | ||
return; | ||
} | ||
let view = browser.getView(win.id) | ||
let view = browser.getView(win.id); | ||
if (view.full_screen == true) { | ||
let display = browser.electron.screen.getPrimaryDisplay() | ||
let width = display.bounds.width | ||
let height = display.bounds.height | ||
let display = browser.electron.screen.getPrimaryDisplay(); | ||
let width = display.bounds.width; | ||
let height = display.bounds.height; | ||
win.setBounds({ | ||
@@ -151,7 +136,6 @@ x: 0, | ||
width: width, | ||
height: height | ||
}) | ||
height: height, | ||
}); | ||
} else { | ||
let bounds = browser.mainWindow.getBounds() | ||
let bounds = browser.mainWindow.getBounds(); | ||
win.setBounds({ | ||
@@ -161,9 +145,7 @@ x: browser.mainWindow.isMaximized() ? bounds.x + 8 : bounds.x, | ||
width: browser.mainWindow.isMaximized() ? bounds.width - 15 : bounds.width - 2, | ||
height: browser.mainWindow.isMaximized() ? bounds.height - 84 : bounds.height - 72 | ||
}) | ||
height: browser.mainWindow.isMaximized() ? bounds.height - 84 : bounds.height - 72, | ||
}); | ||
} | ||
}; | ||
} | ||
browser.newView = function (options) { | ||
@@ -175,10 +157,12 @@ let tab_id = options._id; | ||
options.webPreferences = options.webPreferences || {} | ||
options.webPreferences = options.webPreferences || {}; | ||
let bounds = browser.mainWindow.getBounds() | ||
let bounds = browser.mainWindow.getBounds(); | ||
let win = new BrowserWindow({ | ||
parent: browser.mainWindow, | ||
// parent: browser.mainWindow, | ||
show: false, | ||
alwaysOnTop: false, | ||
skipTaskbar: true, | ||
resizable: false, | ||
width: bounds.width - 5, | ||
@@ -188,3 +172,2 @@ height: browser.mainWindow.isMaximized() ? bounds.height - 85 : bounds.height - 75, | ||
y: browser.mainWindow.isMaximized() ? bounds.y + 75 : bounds.y + 70, | ||
resizable: false, | ||
fullscreenable: true, | ||
@@ -196,4 +179,5 @@ title: 'New Tab', | ||
webPreferences: { | ||
sandbox: false, | ||
enableRemoteModule: true, | ||
contextIsolation: false, | ||
contextIsolation: false, // false -> can access preload window functions | ||
partition: options.partition, | ||
@@ -205,126 +189,138 @@ preload: browser.files_dir + '/js/context-menu.js', | ||
nodeIntegrationInWorker: false, | ||
experimentalFeatures: true, | ||
webSecurity: options.webPreferences.webSecurity ? true : false, | ||
guestInstanceId: options.webPreferences.guestInstanceId, | ||
openerId: options.webPreferences.openerId, | ||
allowRunningInsecureContent: true, | ||
plugins: false, | ||
icon: browser.icons[process.platform] | ||
experimentalFeatures: false, | ||
webSecurity: true, | ||
allowRunningInsecureContent: false, | ||
plugins: true, | ||
icon: browser.icons[process.platform], | ||
}, | ||
}); | ||
} | ||
}) | ||
browser.handleViewPosition(win); | ||
browser.handleViewPosition(win) | ||
win.once("ready-to-show", function () { | ||
win.once('ready-to-show', function () { | ||
// win.show() | ||
}) | ||
}); | ||
options.win_id = win.id; | ||
browser.window_list.push({ | ||
id: win.id, | ||
id: options.win_id, | ||
is_youtube: false, | ||
partition: options.partition | ||
}) | ||
partition: options.partition, | ||
}); | ||
win.on("close", function () { | ||
let view = browser.getView(win.id) | ||
browser.mainWindow.webContents.executeJavaScript("closeTab('" + view._id + "');") | ||
win.on('closed', function () { | ||
let view = browser.getView(options.win_id); | ||
browser.mainWindow.webContents.executeJavaScript("closeTab('" + view._id + "');"); | ||
browser.window_list.forEach((v, i) => { | ||
if (v.id == win.id) { | ||
browser.window_list.splice(i, 1) | ||
if (v.id == options.win_id) { | ||
browser.window_list.splice(i, 1); | ||
} | ||
}); | ||
}) | ||
}); | ||
win.on('focus', function () { | ||
if (browser.getView(win.id).full_screen) { | ||
win.setAlwaysOnTop(true) | ||
win.show() | ||
win.setAlwaysOnTop(true); | ||
win.show(); | ||
} else { | ||
browser.mainWindow.setAlwaysOnTop(true) | ||
browser.showYoutubeWindows() | ||
// browser.mainWindow.setAlwaysOnTop(true) | ||
browser.showYoutubeWindows(); | ||
} | ||
}); | ||
}) | ||
win.on('blur', function () { | ||
browser.mainWindow.setAlwaysOnTop(false); | ||
}); | ||
browser.mainWindow.setAlwaysOnTop(false) | ||
win.setMenuBarVisibility(false); | ||
}) | ||
win.setMenuBarVisibility(false) | ||
if (options.url) { | ||
win.loadURL(options.url, { | ||
referrer: options.referrer | ||
}) | ||
referrer: options.referrer, | ||
}); | ||
} else { | ||
win.loadURL(browser.var.core.default_page || 'http://127.0.0.1:60080/newTab') | ||
win.loadURL(browser.var.core.default_page || 'http://127.0.0.1:60080/newTab'); | ||
} | ||
win.on("enter-full-screen", e => { | ||
console.log('enter-full-screen') | ||
let view = browser.getView(win.id) | ||
view.full_screen = true | ||
browser.handleViewPosition(win) | ||
win.on('enter-full-screen', (e) => { | ||
console.log('enter-full-screen'); | ||
let view = browser.getView(win.id); | ||
view.full_screen = true; | ||
browser.handleViewPosition(win); | ||
if (browser.getView(win.id).full_screen) { | ||
win.setAlwaysOnTop(true) | ||
win.show() | ||
win.setAlwaysOnTop(true); | ||
win.show(); | ||
} else { | ||
browser.mainWindow.setAlwaysOnTop(true) | ||
// browser.mainWindow.setAlwaysOnTop(true) | ||
} | ||
}) | ||
}); | ||
win.on("leave-full-screen", e => { | ||
console.log('leave-full-screen') | ||
let view = browser.getView(win.id) | ||
view.full_screen = false | ||
win.on('leave-full-screen', (e) => { | ||
console.log('leave-full-screen'); | ||
win.setAlwaysOnTop(false); | ||
let view = browser.getView(win.id); | ||
view.full_screen = false; | ||
setTimeout(() => { | ||
browser.handleViewPosition(win) | ||
browser.handleViewPosition(win); | ||
}, 500); | ||
}); | ||
}) | ||
win.on("enter-html-full-screen", e => { | ||
console.log('enter-html-full-screen') | ||
let view = browser.getView(win.id) | ||
view.html_full_screen = true | ||
browser.handleViewPosition(win) | ||
win.on('enter-html-full-screen', (e) => { | ||
console.log('enter-html-full-screen'); | ||
let view = browser.getView(win.id); | ||
view.html_full_screen = true; | ||
browser.handleViewPosition(win); | ||
if (browser.getView(win.id).full_screen) { | ||
win.setAlwaysOnTop(true) | ||
win.show() | ||
win.setAlwaysOnTop(true); | ||
win.show(); | ||
} else { | ||
browser.mainWindow.setAlwaysOnTop(true) | ||
//browser.mainWindow.setAlwaysOnTop(true) | ||
} | ||
}) | ||
win.on("leave-html-full-screen", e => { | ||
console.log('leave-html-full-screen') | ||
let view = browser.getView(win.id) | ||
view.html_full_screen = false | ||
}); | ||
win.on('leave-html-full-screen', (e) => { | ||
console.log('leave-html-full-screen'); | ||
win.setAlwaysOnTop(false); | ||
let view = browser.getView(win.id); | ||
view.html_full_screen = false; | ||
setTimeout(() => { | ||
browser.handleViewPosition(win) | ||
browser.handleViewPosition(win); | ||
}, 500); | ||
}) | ||
}); | ||
win.on('app-command', (e, cmd) => { | ||
// Navigate the window back when the user hits their mouse back button | ||
// APPCOMMAND_BROWSER_BACKWARD converted to browser-backward | ||
if (cmd === 'browser-backward' && win.webContents.canGoBack()) { | ||
win.webContents.goBack(); | ||
} else if (cmd === 'browser-forward' && win.webContents.canGoForward()) { | ||
win.webContents.goForward(); | ||
} | ||
}); | ||
let contents = win.webContents | ||
let contents = win.webContents; | ||
// contents.unselect(); | ||
// contents.findInPage(text, options); | ||
// contents.stopFindInPage('clearSelection'); | ||
contents.on('found-in-page', (event, result) => { | ||
console.log(result); | ||
browser.call('found-in-page', { | ||
win_id: win.id, | ||
result: result, | ||
}); | ||
}); | ||
contents.on("update-target-url", (e, url) => { | ||
url = url.replace('#___new_tab___', '').replace('#___new_window___', '') | ||
contents.on('update-target-url', (e, url) => { | ||
url = url.replace('#___new_tab___', '').replace('#___new_window___', ''); | ||
contents.send('render_message', { | ||
name: 'update-target-url', | ||
url: decodeURI(url) | ||
}) | ||
}) | ||
url: decodeURI(url), | ||
}); | ||
}); | ||
contents.on("page-title-updated", e => { | ||
contents.on('page-title-updated', (e) => { | ||
contents.stopFindInPage('clearSelection'); | ||
if (win.id == browser.current_view.id) { | ||
browser.mainWindow.setTitle(contents.getTitle()) | ||
browser.mainWindow.setTitle(contents.getTitle()); | ||
} | ||
@@ -335,4 +331,4 @@ | ||
title: contents.getTitle(), | ||
tab_id: tab_id | ||
}) | ||
tab_id: tab_id, | ||
}); | ||
@@ -342,4 +338,4 @@ browser.mainWindow.webContents.send('render_message', { | ||
tab_id: tab_id, | ||
url: decodeURI(win.getURL()) | ||
}) | ||
url: decodeURI(win.getURL()), | ||
}); | ||
@@ -350,64 +346,78 @@ browser.mainWindow.webContents.send('render_message', { | ||
forward: contents.canGoForward(), | ||
back: contents.canGoBack() | ||
}) | ||
}) | ||
back: contents.canGoBack(), | ||
}); | ||
}); | ||
contents.on("page-favicon-updated", (e, urls) => { | ||
contents.on('page-favicon-updated', (e, urls) => { | ||
if (urls && urls.length > 0) { | ||
let image_name = browser.op.md5(urls[0]) + '.' + urls[0].split('.').pop().split('?')[0] | ||
let window_icon_path2 = browser.path.join(browser.data_dir, 'favicons', image_name) | ||
let image_name = browser.op.md5(urls[0]) + '.' + urls[0].split('.').pop().split('?')[0]; | ||
let window_icon_path2 = browser.path.join(browser.data_dir, 'favicons', image_name); | ||
if (!browser.fs.existsSync(window_icon_path2)) { | ||
browser.downloadFile0( | ||
urls[0], | ||
window_icon_path2, | ||
null, | ||
(info) => { | ||
console.log(info); | ||
window_icon_path = window_icon_path2; | ||
browser.views.forEach((view) => { | ||
if (view.id == win.id) { | ||
view.favicon_path = window_icon_path; | ||
} | ||
}); | ||
browser.downloadFile0(urls[0], window_icon_path2, null, (info) => { | ||
console.log(info) | ||
window_icon_path = window_icon_path2 | ||
browser.views.forEach(view => { | ||
if (view.id == win.id) { | ||
view.favicon_path = window_icon_path | ||
} | ||
}) | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-favicon', | ||
icon: window_icon_path | ||
? nativeImage | ||
.createFromPath(window_icon_path) | ||
.resize({ | ||
width: 16, | ||
height: 16, | ||
}) | ||
.toDataURL() | ||
: '', | ||
tab_id: tab_id, | ||
}); | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-favicon', | ||
icon: window_icon_path ? nativeImage.createFromPath(window_icon_path).resize({ | ||
width: 16, | ||
height: 16 | ||
}).toDataURL() : '', | ||
tab_id: tab_id | ||
}) | ||
browser.addURL({ | ||
url: decodeURI(win.getURL()), | ||
logo: window_icon_path | ||
}) | ||
}, true) | ||
browser.addURL({ | ||
url: decodeURI(win.getURL()), | ||
logo: window_icon_path, | ||
ignore: true, | ||
}); | ||
}, | ||
true, | ||
); | ||
} else { | ||
window_icon_path = window_icon_path2 | ||
browser.views.forEach(view => { | ||
window_icon_path = window_icon_path2; | ||
browser.views.forEach((view) => { | ||
if (view.id == win.id) { | ||
view.favicon_path = window_icon_path | ||
view.favicon_path = window_icon_path; | ||
} | ||
}) | ||
}); | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-favicon', | ||
icon: window_icon_path ? nativeImage.createFromPath(window_icon_path).resize({ | ||
width: 16, | ||
height: 16 | ||
}).toDataURL() : '', | ||
tab_id: tab_id | ||
}) | ||
icon: window_icon_path | ||
? nativeImage | ||
.createFromPath(window_icon_path) | ||
.resize({ | ||
width: 16, | ||
height: 16, | ||
}) | ||
.toDataURL() | ||
: '', | ||
tab_id: tab_id, | ||
}); | ||
browser.addURL({ | ||
url: decodeURI(win.getURL()), | ||
logo: window_icon_path | ||
}) | ||
logo: window_icon_path, | ||
ignore: true, | ||
}); | ||
} | ||
} | ||
}); | ||
}) | ||
contents.on("did-start-loading", (e, url) => { | ||
contents.on('did-start-loading', (e, url) => { | ||
// browser.mainWindow.webContents.send('render_message', { | ||
@@ -422,29 +432,36 @@ // name: 'update-url', | ||
icon: loading_icon, | ||
tab_id: tab_id | ||
}) | ||
tab_id: tab_id, | ||
}); | ||
}); | ||
}) | ||
contents.on("did-stop-loading", (e) => { | ||
contents.on('did-stop-loading', (e) => { | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'show-loading', | ||
icon: window_icon_path ? nativeImage.createFromPath(window_icon_path).resize({ | ||
width: 16, | ||
height: 16 | ||
}).toDataURL() : '', | ||
tab_id: tab_id | ||
}) | ||
icon: window_icon_path | ||
? nativeImage | ||
.createFromPath(window_icon_path) | ||
.resize({ | ||
width: 16, | ||
height: 16, | ||
}) | ||
.toDataURL() | ||
: '', | ||
tab_id: tab_id, | ||
}); | ||
}); | ||
}) | ||
contents.on("did-finish-load", (e) => { | ||
contents.on('did-finish-load', (e) => { | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'show-loading', | ||
icon: window_icon_path ? nativeImage.createFromPath(window_icon_path).resize({ | ||
width: 16, | ||
height: 16 | ||
}).toDataURL() : '', | ||
tab_id: tab_id | ||
}) | ||
icon: window_icon_path | ||
? nativeImage | ||
.createFromPath(window_icon_path) | ||
.resize({ | ||
width: 16, | ||
height: 16, | ||
}) | ||
.toDataURL() | ||
: '', | ||
tab_id: tab_id, | ||
}); | ||
browser.mainWindow.webContents.send('render_message', { | ||
@@ -454,25 +471,29 @@ name: 'update-buttons', | ||
forward: contents.canGoForward(), | ||
back: contents.canGoBack() | ||
}) | ||
}) | ||
back: contents.canGoBack(), | ||
}); | ||
}); | ||
contents.on("did-fail-load", (e) => { | ||
contents.on('did-fail-load', (e) => { | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'show-loading', | ||
icon: window_icon_path ? nativeImage.createFromPath(window_icon_path).resize({ | ||
width: 16, | ||
height: 16 | ||
}).toDataURL() : '', | ||
tab_id: tab_id | ||
}) | ||
icon: window_icon_path | ||
? nativeImage | ||
.createFromPath(window_icon_path) | ||
.resize({ | ||
width: 16, | ||
height: 16, | ||
}) | ||
.toDataURL() | ||
: '', | ||
tab_id: tab_id, | ||
}); | ||
}); | ||
}) | ||
contents.on("dom-ready", e => { | ||
contents.on('dom-ready', (e) => { | ||
contents.stopFindInPage('clearSelection'); | ||
browser.addURL({ | ||
url: decodeURI(win.getURL()), | ||
title: contents.getTitle(), | ||
logo: window_icon_path | ||
}) | ||
logo: window_icon_path, | ||
}); | ||
@@ -482,4 +503,4 @@ browser.mainWindow.webContents.send('render_message', { | ||
url: decodeURI(win.getURL()), | ||
tab_id: tab_id | ||
}) | ||
tab_id: tab_id, | ||
}); | ||
browser.mainWindow.webContents.send('render_message', { | ||
@@ -489,7 +510,5 @@ name: 'update-buttons', | ||
forward: contents.canGoForward(), | ||
back: contents.canGoBack() | ||
}) | ||
let css = browser.readFileSync(browser.files_dir + '/css/inject.css') | ||
contents.insertCSS(css) | ||
}) | ||
back: contents.canGoBack(), | ||
}); | ||
}); | ||
@@ -499,56 +518,54 @@ contents.on('before-input-event', (event, input) => { | ||
// Ctrl/Cmd are down. | ||
contents.setIgnoreMenuShortcuts(!input.control && !input.meta) | ||
}) | ||
contents.setIgnoreMenuShortcuts(!input.control && !input.meta); | ||
}); | ||
contents.on('crashed', (e) => { | ||
console.log('window Crashed') | ||
console.log('window Crashed'); | ||
setTimeout(() => { | ||
win.loadURL(options.url || browser.var.core.default_page || 'http://127.0.0.1:60080/newTab') | ||
}, 1000) | ||
}) | ||
win.loadURL(options.url || browser.var.core.default_page || 'http://127.0.0.1:60080/newTab'); | ||
}, 1000); | ||
}); | ||
contents.on("will-navigate", (e, url) => { | ||
contents.on('will-navigate', (e, url) => { | ||
// when user click on link _blank | ||
console.log('will-navigate :: ' + url) | ||
contents.stopFindInPage('clearSelection'); | ||
console.log('will-navigate :: ' + url); | ||
if (url.like('*#___new_tab___*')) { | ||
e.preventDefault() | ||
url = (url.replace('#___new_tab___', '')) | ||
win.loadURL(url) | ||
e.preventDefault(); | ||
url = url.replace('#___new_tab___', ''); | ||
win.loadURL(url); | ||
browser.mainWindow.webContents.send('render_message', { | ||
name: 'update-url', | ||
tab_id: tab_id, | ||
url: decodeURI(url) | ||
}) | ||
url: decodeURI(url), | ||
}); | ||
} | ||
}); | ||
}) | ||
contents.on("will-redirect", e => { | ||
contents.on('will-redirect', (e) => { | ||
// console.log('will-redirect') | ||
}) | ||
}); | ||
contents.on("did-redirect-navigation", e => { | ||
contents.on('did-redirect-navigation', (e) => { | ||
//console.log('did-redirect-navigation') | ||
}) | ||
}); | ||
contents.on("did-navigate", e => { | ||
contents.on('did-navigate', (e) => { | ||
//console.log('did-navigate') | ||
}) | ||
}); | ||
contents.on("did-frame-navigate", e => { | ||
contents.on('did-frame-navigate', (e) => { | ||
//console.log('did-frame-navigate') | ||
}) | ||
}); | ||
contents.on("did-navigate-in-page", e => { | ||
contents.on('did-navigate-in-page', (e) => { | ||
//console.log('did-navigate-in-page') | ||
}) | ||
}); | ||
contents.on("did-get-redirect-request", e => { | ||
console.log('did-get-redirect-request') | ||
contents.on('did-get-redirect-request', (e) => { | ||
console.log('did-get-redirect-request'); | ||
if (e.isMainFrame) { | ||
win.loadURL(e.newURL) | ||
win.loadURL(e.newURL); | ||
} | ||
}) | ||
}); | ||
@@ -570,11 +587,10 @@ // contents.on('will-prevent-unload', (event) => { | ||
contents.on("new-window", newWindowEvent) | ||
contents.on('new-window', newWindowEvent); | ||
return win | ||
} | ||
return win; | ||
}; | ||
browser.addressbarWindow = null; | ||
browser.newAddressbarWindow = function () { | ||
let win = new BrowserWindow({ | ||
let win = browser.newWindow({ | ||
parent: browser.mainWindow, | ||
@@ -593,2 +609,3 @@ show: false, | ||
icon: browser.icons[process.platform], | ||
skipTaskbar: true, | ||
webPreferences: { | ||
@@ -603,37 +620,37 @@ enableRemoteModule: true, | ||
allowRunningInsecureContent: true, | ||
plugins: false, | ||
icon: browser.icons[process.platform] | ||
plugins: true, | ||
icon: browser.icons[process.platform], | ||
}, | ||
}); | ||
} | ||
}) | ||
win.setMenuBarVisibility(false); | ||
win.loadURL( | ||
browser.url.format({ | ||
pathname: browser.path.join(browser.files_dir, 'html', 'address-bar.html'), | ||
protocol: 'file:', | ||
slashes: true, | ||
}), | ||
); | ||
win.setMenuBarVisibility(false) | ||
win.loadURL(browser.url.format({ | ||
pathname: browser.path.join(browser.files_dir, "html", "address-bar.html"), | ||
protocol: "file:", | ||
slashes: true | ||
})) | ||
win.on('blur', function () { | ||
win.hide() | ||
}) | ||
win.hide(); | ||
}); | ||
// win.openDevTools() | ||
return win | ||
} | ||
return win; | ||
}; | ||
browser.hideAddressbar = function () { | ||
if (browser.addressbarWindow) { | ||
browser.addressbarWindow.hide() | ||
browser.addressbarWindow.hide(); | ||
} | ||
} | ||
}; | ||
browser.showAddressbar = function (options) { | ||
options = options || {}; | ||
options = options || {} | ||
browser.addressbarWindow = browser.addressbarWindow || browser.newAddressbarWindow() | ||
browser.addressbarWindow = browser.addressbarWindow || browser.newAddressbarWindow(); | ||
if (!options.url) { | ||
let win = BrowserWindow.fromId(browser.current_view.id) | ||
let win = BrowserWindow.fromId(browser.current_view.id); | ||
if (win) { | ||
options.url = win.getURL() | ||
options.url = win.getURL(); | ||
} | ||
@@ -643,8 +660,8 @@ } | ||
if (options.url.like('http://127.0.0.1:60080*')) { | ||
options.url = '' | ||
options.url = ''; | ||
} | ||
browser.addressbarWindow.webContents.executeJavaScript("loadurl('" + options.url + "');") | ||
browser.addressbarWindow.webContents.executeJavaScript("loadurl('" + options.url + "');"); | ||
let bounds = browser.mainWindow.getBounds() | ||
let bounds = browser.mainWindow.getBounds(); | ||
browser.addressbarWindow.setBounds({ | ||
@@ -655,12 +672,9 @@ width: bounds.y == -8 ? bounds.width - 100 : bounds.width - 95, | ||
y: (bounds.y == -8 ? 0 : bounds.y - 5) + 30, | ||
}) | ||
browser.addressbarWindow.show() | ||
return browser.addressbarWindow | ||
}); | ||
browser.addressbarWindow.show(); | ||
return browser.addressbarWindow; | ||
}; | ||
} | ||
browser.userProfileWindow = null; | ||
browser.newUserProfileWindow = function () { | ||
let win = new BrowserWindow({ | ||
@@ -674,9 +688,13 @@ parent: browser.mainWindow, | ||
alwaysOnTop: true, | ||
skipTaskbar: true, | ||
resizable: false, | ||
fullscreenable: false, | ||
title: 'Address-bar', | ||
title: 'user-profile', | ||
backgroundColor: '#ffffff', | ||
frame: false, | ||
icon: browser.icons[process.platform], | ||
webPreferences: { | ||
contextIsolation: false, | ||
enableRemoteModule: true, | ||
partition: 'user_profile', | ||
@@ -689,35 +707,35 @@ preload: browser.files_dir + '/js/addressbar-context-menu.js', | ||
allowRunningInsecureContent: true, | ||
plugins: false, | ||
icon: browser.icons[process.platform] | ||
plugins: true, | ||
icon: browser.icons[process.platform], | ||
}, | ||
}); | ||
} | ||
}) | ||
win.setMenuBarVisibility(false); | ||
win.loadURL( | ||
browser.url.format({ | ||
pathname: browser.path.join(browser.files_dir, 'html', 'user-profiles.html'), | ||
protocol: 'file:', | ||
slashes: true, | ||
}), | ||
); | ||
win.setMenuBarVisibility(false) | ||
win.loadURL(browser.url.format({ | ||
pathname: browser.path.join(browser.files_dir, "html", "user-profiles.html"), | ||
protocol: "file:", | ||
slashes: true | ||
})) | ||
win.on('blur', function () { | ||
win.hide() | ||
}) | ||
win.hide(); | ||
}); | ||
// win.openDevTools() | ||
return win; | ||
}; | ||
return win | ||
} | ||
browser.hideUserProfile = function () { | ||
if (browser.userProfileWindow) { | ||
browser.userProfileWindow.hide() | ||
browser.userProfileWindow.hide(); | ||
} | ||
} | ||
}; | ||
browser.showUserProfile = function (options) { | ||
options = options || {}; | ||
options = options || {} | ||
browser.userProfileWindow = browser.userProfileWindow || browser.newuserProfileWindow(); | ||
browser.userProfileWindow = browser.userProfileWindow || browser.newuserProfileWindow() | ||
let bounds = browser.mainWindow.getBounds() | ||
let bounds = browser.mainWindow.getBounds(); | ||
browser.userProfileWindow.setBounds({ | ||
@@ -728,29 +746,26 @@ width: 400, | ||
y: (bounds.y == -8 ? 0 : bounds.y - 5) + 30, | ||
}) | ||
browser.userProfileWindow.show() | ||
return browser.userProfileWindow | ||
}); | ||
browser.userProfileWindow.show(); | ||
return browser.userProfileWindow; | ||
}; | ||
} | ||
browser.newWindow = function (options) { | ||
// console.log('newWindow()', options) | ||
console.log('newWindow()', options) | ||
browser.mainWindow.setAlwaysOnTop(false); | ||
browser.mainWindow.setAlwaysOnTop(false) | ||
options = options || {}; | ||
options.webPreferences = options.webPreferences || {}; | ||
options = options || {} | ||
options.webPreferences = options.webPreferences || {} | ||
options.x = options.x || 200 | ||
options.x = options.x || 200; | ||
// options.x = options.x > 1200 ? 200 : options.x | ||
options.y = options.y || 200 | ||
options.y = options.y || 200; | ||
// options.y = options.y > 600 ? 200 : options.y | ||
if (!options.partition && !options.webPreferences.partition) { | ||
options.partition = browser.current_view.partition | ||
options.partition = browser.current_view.partition; | ||
} | ||
let win = new BrowserWindow({ | ||
show: true, | ||
show: false, | ||
title: options.title || 'New Window', | ||
@@ -763,210 +778,215 @@ alwaysOnTop: options.alwaysOnTop, | ||
backgroundColor: options.backgroundColor || '#ffffff', | ||
frame: true, | ||
frame: typeof options.frame !== 'undefined' ? options.frame : true, | ||
icon: browser.icons[process.platform], | ||
titleBarStyle: 'hidden', | ||
webPreferences: { | ||
contextIsolation: false, | ||
enableRemoteModule: true, | ||
partition: options.webPreferences.partition || options.partition, | ||
sandbox: options.webPreferences.sandbox, | ||
preload: options.preload || browser.files_dir + '/js/context-menu.js', | ||
nativeWindowOpen: false, | ||
nodeIntegration: false, | ||
nodeIntegrationInSubFrames: true, | ||
experimentalFeatures: true, | ||
webSecurity: options.webPreferences.webSecurity || false, | ||
guestInstanceId: options.webPreferences.guestInstanceId, | ||
openerId: options.webPreferences.openerId, | ||
allowRunningInsecureContent: true, | ||
plugins: false, | ||
icon: browser.icons[process.platform] | ||
sandbox: typeof options.webPreferences.sandbox !== 'undefined' ? options.webPreferences.sandbox : null, | ||
preload: typeof options.webPreferences.preload !== 'undefined' ? options.webPreferences.preload : browser.files_dir + '/js/context-menu.js', | ||
nativeWindowOpen: typeof options.webPreferences.nativeWindowOpen !== 'undefined' ? options.webPreferences.nativeWindowOpen : false, | ||
nodeIntegration: typeof options.webPreferences.nodeIntegration !== 'undefined' ? options.webPreferences.nodeIntegration : false, | ||
nodeIntegrationInWorker: typeof options.webPreferences.nodeIntegrationInWorker !== 'undefined' ? options.webPreferences.nodeIntegrationInWorker : false, | ||
nodeIntegrationInSubFrames: typeof options.webPreferences.nodeIntegrationInSubFrames !== 'undefined' ? options.webPreferences.nodeIntegrationInSubFrames : true, | ||
experimentalFeatures: typeof options.webPreferences.experimentalFeatures !== 'undefined' ? options.webPreferences.experimentalFeatures : false, | ||
webSecurity: typeof options.webPreferences.webSecurity !== 'undefined' ? options.webPreferences.webSecurity : true, | ||
allowRunningInsecureContent: typeof options.webPreferences.allowRunningInsecureContent !== 'undefined' ? options.webPreferences.allowRunningInsecureContent : false, | ||
plugins: true, | ||
}, | ||
}); | ||
} | ||
}) | ||
options.win_id = win.id; | ||
browser.window_list.push({ | ||
id: win.id, | ||
id: options.win_id, | ||
is_youtube: options.title == 'Youtube' ? true : false, | ||
partition: options.webPreferences.partition || options.partition | ||
}) | ||
partition: options.webPreferences.partition || options.partition, | ||
}); | ||
win.on('close', (e) => { | ||
win.on('closed', (e) => { | ||
browser.window_list.forEach((v, i) => { | ||
if (v.id == win.id) { | ||
browser.window_list.splice(i, 1) | ||
if (v.id == options.win_id) { | ||
browser.window_list.splice(i, 1); | ||
} | ||
}); | ||
}) | ||
}); | ||
if (options.max) { | ||
win.maximize() | ||
win.maximize(); | ||
} | ||
win.setMenuBarVisibility(false) | ||
win.setMenuBarVisibility(false); | ||
if (options.proxy) { | ||
win.webContents.session.setProxy({ | ||
proxyRules: options.proxy | ||
}) | ||
proxyRules: options.proxy, | ||
}); | ||
} | ||
win.loadURL(options.url, { | ||
referrer: options.referrer, | ||
userAgent: options.user_agent || browser.var.core.user_agent | ||
}) | ||
if (options.url) { | ||
win.loadURL(options.url, { | ||
referrer: options.referrer, | ||
userAgent: options.user_agent || browser.var.core.user_agent, | ||
}); | ||
} | ||
win.once('ready-to-show', function () { | ||
if (typeof options.show === "undefined" || options.show) { | ||
win.show(); | ||
} | ||
}); | ||
win.webContents.on("dom-ready", e => { | ||
let css = browser.readFileSync(browser.files_dir + '/css/inject.css') | ||
win.webContents.insertCSS(css) | ||
}) | ||
win.webContents.on('dom-ready', (e) => { | ||
// let css = browser.readFileSync(browser.files_dir + '/css/inject.css') | ||
// win.webContents.insertCSS(css) | ||
}); | ||
win.webContents.on('unresponsive', async () => { | ||
win.webContents.forcefullyCrashRenderer(); | ||
win.webContents.reload(); | ||
}); | ||
win.webContents.on('crashed', (e) => { | ||
showInfo('window Crashed') | ||
setTimeout(() => { | ||
win.loadURL(url) | ||
}, 1000) | ||
}) | ||
win.webContents.on("did-get-redirect-request", e => { | ||
win.webContents.forcefullyCrashRenderer(); | ||
win.webContents.reload(); | ||
}); | ||
win.webContents.on('did-get-redirect-request', (e) => { | ||
if (e.isMainFrame) { | ||
win.loadURL(e.newURL) | ||
win.loadURL(e.newURL); | ||
} | ||
}) | ||
}); | ||
if (!options.window_off) { | ||
win.webContents.on("new-window", newWindowEvent) | ||
win.webContents.on('new-window', newWindowEvent); | ||
} | ||
return win; | ||
}; | ||
return win | ||
} | ||
browser.newYoutubeWindow = function (options) { | ||
console.log('newYoutubeWindow()'); | ||
console.log('newYoutubeWindow()') | ||
browser.mainWindow.setAlwaysOnTop(false); | ||
options = options || {}; | ||
browser.mainWindow.setAlwaysOnTop(false) | ||
options = options || {} | ||
if (options.url.like('https://www.youtube.com/watch*')) { | ||
options.url = 'https://www.youtube.com/embed/' + options.url.split('=')[1].split('&')[0] | ||
options.url = 'https://www.youtube.com/embed/' + options.url.split('=')[1].split('&')[0]; | ||
} else if (options.url.like('https://www.youtube.com/embed*')) { | ||
options.url = options.url | ||
options.url = options.url; | ||
} else { | ||
options.url = options.url.split('&')[0] | ||
options.url = options.url.split('&')[0]; | ||
} | ||
let display = browser.electron.screen.getPrimaryDisplay() | ||
let width = display.bounds.width | ||
let height = display.bounds.height | ||
let display = browser.electron.screen.getPrimaryDisplay(); | ||
let width = display.bounds.width; | ||
let height = display.bounds.height; | ||
options.width = 420 | ||
options.height = 280 | ||
options.x = width - 430, | ||
options.y = height - 310 | ||
options.alwaysOnTop = true | ||
options.disableEvents = true | ||
options.backgroundColor = '#030303' | ||
options.title = 'Youtube' | ||
options.width = 440; | ||
options.height = 300; | ||
(options.x = width - 450), (options.y = height - 330); | ||
options.alwaysOnTop = true; | ||
options.disableEvents = true; | ||
options.backgroundColor = '#030303'; | ||
options.title = 'Youtube'; | ||
options.window_off = true | ||
options.window_off = true; | ||
let win = browser.newWindow(options) | ||
let win = browser.newWindow(options); | ||
win.webContents.on("will-navigate", (e, url2) => { | ||
e.preventDefault() | ||
win.webContents.on('will-navigate', (e, url2) => { | ||
e.preventDefault(); | ||
if (url2.like('https://www.youtube.com/watch*')) { | ||
url = 'https://www.youtube.com/embed/' + url2.split('=')[1].split('&')[0] | ||
win.loadURL(url) | ||
url = 'https://www.youtube.com/embed/' + url2.split('=')[1].split('&')[0]; | ||
win.loadURL(url); | ||
} else if (url2.like('https://www.youtube.com/embed*')) { | ||
win.loadURL(url) | ||
win.loadURL(url); | ||
} | ||
}) | ||
}); | ||
win.webContents.on("new-window", (event, url, frameName, disposition, options, additionalFeatures) => { | ||
win.webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) => { | ||
event.preventDefault(); | ||
event.preventDefault() | ||
url = url || event.url || ''; | ||
url = url || event.url || '' | ||
if (url.like('https://www.youtube.com/watch*')) { | ||
url = 'https://www.youtube.com/embed/' + url.split('=')[1].split('&')[0] | ||
win.loadURL(url) | ||
return | ||
url = 'https://www.youtube.com/embed/' + url.split('=')[1].split('&')[0]; | ||
win.loadURL(url); | ||
return; | ||
} else if (url.like('https://www.youtube.com/embed*')) { | ||
win.loadURL(url) | ||
return | ||
win.loadURL(url); | ||
return; | ||
} | ||
}); | ||
}) | ||
return win; | ||
}; | ||
return win | ||
} | ||
browser.newIframeWindow = function (options) { | ||
console.log('newIframeWindow()') | ||
browser.mainWindow.setAlwaysOnTop(false) | ||
options = options || {} | ||
console.log('newIframeWindow()'); | ||
browser.mainWindow.setAlwaysOnTop(false); | ||
options = options || {}; | ||
options.url = 'http://127.0.0.1:60080/iframe?url=' + options.url | ||
options.url = 'http://127.0.0.1:60080/iframe?url=' + options.url; | ||
options.width = 800; | ||
options.height = 600; | ||
(options.x = 200), (options.y = 100); | ||
options.alwaysOnTop = true; | ||
options.disableEvents = true; | ||
options.backgroundColor = '#030303'; | ||
let win = browser.newWindow(options); | ||
win.webContents.on('will-navigate', (e, url2) => { | ||
e.preventDefault(); | ||
options.url = 'http://127.0.0.1:60080/iframe?url=' + options.url; | ||
}); | ||
options.width = 800 | ||
options.height = 600 | ||
options.x = 200, | ||
options.y = 100 | ||
options.alwaysOnTop = true | ||
options.disableEvents = true | ||
options.backgroundColor = '#030303' | ||
let win = browser.newWindow(options) | ||
return win; | ||
}; | ||
win.webContents.on("will-navigate", (e, url2) => { | ||
e.preventDefault() | ||
options.url = 'http://127.0.0.1:60080/iframe?url=' + options.url | ||
}) | ||
return win | ||
} | ||
browser.newVideoWindow = function (options) { | ||
console.log('newVideoWindow()') | ||
browser.mainWindow.setAlwaysOnTop(false) | ||
options = options || {} | ||
console.log('newVideoWindow()'); | ||
browser.mainWindow.setAlwaysOnTop(false); | ||
options = options || {}; | ||
options.url = 'http://127.0.0.1:60080/html/mini_video.html?url=' + options.url | ||
options.url = 'http://127.0.0.1:60080/html/mini_video.html?url=' + options.url; | ||
let display = browser.electron.screen.getPrimaryDisplay() | ||
let width = display.bounds.width | ||
let height = display.bounds.height | ||
let display = browser.electron.screen.getPrimaryDisplay(); | ||
let width = display.bounds.width; | ||
let height = display.bounds.height; | ||
options.width = 420 | ||
options.height = 280 | ||
options.x = width - 430, | ||
options.y = height - 310 | ||
options.alwaysOnTop = true | ||
options.disableEvents = true | ||
options.backgroundColor = '#030303' | ||
options.width = 420; | ||
options.height = 280; | ||
(options.x = width - 430), (options.y = height - 310); | ||
options.alwaysOnTop = true; | ||
options.disableEvents = true; | ||
options.backgroundColor = '#030303'; | ||
let win = browser.newWindow(options) | ||
let win = browser.newWindow(options); | ||
win.webContents.on("will-navigate", (e, url2) => { | ||
e.preventDefault() | ||
url = 'http://127.0.0.1:60080/html/mini_video.html?url=' + url | ||
}) | ||
win.webContents.on('will-navigate', (e, url2) => { | ||
e.preventDefault(); | ||
url = 'http://127.0.0.1:60080/html/mini_video.html?url=' + url; | ||
}); | ||
return win; | ||
}; | ||
return win | ||
} | ||
browser.newTrustedWindow = function (op) { | ||
op = op || {}; | ||
browser.mainWindow.setAlwaysOnTop(false); | ||
browser.mainWindow.setAlwaysOnTop(false) | ||
let win = new BrowserWindow({ | ||
show: typeof op.show == 'undefined' ? false : op.show, | ||
show: false, | ||
width: op.width || 1200, | ||
height: op.height || 800, | ||
title: op.title || 'TRUESTED WINDOW ', | ||
icon: browser.icons[process.platform], | ||
webPreferences: { | ||
contextIsolation: false, | ||
enableRemoteModule: true, | ||
@@ -983,38 +1003,54 @@ preload: op.preload || browser.files_dir + '/js/context-menu.js', | ||
experimentalFeatures: true, | ||
icon: browser.icons[process.platform] | ||
}, | ||
}); | ||
op.win_id = win.id; | ||
win.setMenuBarVisibility(false); | ||
win.once('ready-to-show', function () { | ||
if (op.show) { | ||
win.show(); | ||
} | ||
}) | ||
win.setMenuBarVisibility(false) | ||
}); | ||
browser.window_list.push({ | ||
id: win.id, | ||
is_youtube: false, | ||
partition: op.partition || 'trusted' | ||
}) | ||
is_trusted: true, | ||
partition: op.partition || 'trusted', | ||
}); | ||
win.on("close", function () { | ||
win.on('closed', function () { | ||
browser.window_list.forEach((v, i) => { | ||
if (v.id == win.id) { | ||
browser.window_list.splice(i, 1) | ||
if (v.id == op.win_id) { | ||
browser.window_list.splice(i, 1); | ||
} | ||
}); | ||
}) | ||
}); | ||
win.loadURL(op.url) | ||
return win | ||
} | ||
win.loadURL(op.url); | ||
browser.newSocialBrowser = function (callback) { | ||
return win; | ||
}; | ||
let newWindow = null | ||
browser.showCurrentView = function (show = true) { | ||
if (browser.current_view && browser.current_view.id) { | ||
let win = BrowserWindow.fromId(browser.current_view.id); | ||
if (win) { | ||
if (show) { | ||
win.show(); | ||
console.log('view show'); | ||
} else { | ||
win.hide(); | ||
console.log('view hide'); | ||
} | ||
} | ||
} | ||
}; | ||
const { | ||
width, | ||
height | ||
} = electron.screen.getPrimaryDisplay().workAreaSize | ||
browser.newSOCIALBROWSER = function (callback) { | ||
console.log('browser.newSOCIALBROWSER'); | ||
let newWindow = null; | ||
const { width, height } = electron.screen.getPrimaryDisplay().workAreaSize; | ||
newWindow = new BrowserWindow({ | ||
@@ -1026,59 +1062,82 @@ show: false, | ||
webPreferences: { | ||
contextIsolation: false, | ||
enableRemoteModule: true, | ||
nativeWindowOpen: false, | ||
plugins: false, | ||
plugins: true, | ||
nodeIntegration: true, | ||
webSecurity: true, | ||
allowRunningInsecureContent: true, | ||
experimentalFeatures: true | ||
allowRunningInsecureContent: false, | ||
experimentalFeatures: true, | ||
}, | ||
frame: false, | ||
icon: browser.icons[process.platform] | ||
}) | ||
icon: browser.icons[process.platform], | ||
}); | ||
newWindow.setThumbarButtons([]); | ||
newWindow.setMenuBarVisibility(false); | ||
// newWindow.maximize() | ||
newWindow.setMenuBarVisibility(false) | ||
newWindow.maximize() | ||
newWindow.on('blur', function () {}) | ||
newWindow.on('focus', function () {}) | ||
newWindow.on('show', function () {}) | ||
newWindow.on('blur', function () { | ||
// browser.showCurrentView(false); | ||
}); | ||
newWindow.on('focus', function () { | ||
browser.showCurrentView(); | ||
console.log('focus'); | ||
}); | ||
newWindow.on('show', function () { | ||
browser.showCurrentView(); | ||
console.log('show'); | ||
}); | ||
newWindow.on('hide', function () { | ||
browser.hideAddressbar() | ||
}) | ||
browser.hideAddressbar(); | ||
browser.showCurrentView(false); | ||
console.log('hide'); | ||
}); | ||
newWindow.on('maximize', function () { | ||
let bounds = newWindow.getBounds() | ||
browser.hideAddressbar() | ||
browser.views.forEach(v => { | ||
let win = BrowserWindow.fromId(v.id) | ||
browser.handleViewPosition(win) | ||
}) | ||
}) | ||
newWindow.on('unmaximize', function () {}) | ||
newWindow.on('minimize', function () {}) | ||
newWindow.on('restore', function () {}) | ||
browser.hideAddressbar(); | ||
browser.views.forEach((v) => { | ||
let win = BrowserWindow.fromId(v.id); | ||
browser.handleViewPosition(win); | ||
}); | ||
browser.showCurrentView(); | ||
console.log('maximize'); | ||
}); | ||
newWindow.on('unmaximize', function () { | ||
browser.showCurrentView(); | ||
console.log('unmaximize'); | ||
}); | ||
newWindow.on('minimize', function () { | ||
browser.showCurrentView(false); | ||
console.log('minimize'); | ||
}); | ||
newWindow.on('restore', function () { | ||
browser.showCurrentView(); | ||
console.log('restore'); | ||
}); | ||
newWindow.on('resize', function () { | ||
let bounds = newWindow.getBounds() | ||
browser.hideAddressbar() | ||
browser.views.forEach(v => { | ||
let win = BrowserWindow.fromId(v.id) | ||
browser.handleViewPosition(win) | ||
}) | ||
}) | ||
browser.hideAddressbar(); | ||
browser.views.forEach((v) => { | ||
let win = BrowserWindow.fromId(v.id); | ||
browser.handleViewPosition(win); | ||
}); | ||
browser.showCurrentView(); | ||
console.log('resize'); | ||
}); | ||
newWindow.on('move', function () { | ||
browser.hideAddressbar() | ||
browser.views.forEach(v => { | ||
let win = BrowserWindow.fromId(v.id) | ||
browser.handleViewPosition(win) | ||
}) | ||
}) | ||
browser.hideAddressbar(); | ||
browser.views.forEach((v) => { | ||
let win = BrowserWindow.fromId(v.id); | ||
browser.handleViewPosition(win); | ||
}); | ||
browser.showCurrentView(); | ||
console.log('move'); | ||
}); | ||
newWindow.once("ready-to-show", function () { | ||
newWindow.show() | ||
}) | ||
newWindow.once('ready-to-show', function () { | ||
// newWindow.show() | ||
}); | ||
@@ -1089,13 +1148,12 @@ newWindow.webContents.on('crashed', (e) => { | ||
browser.url.format({ | ||
pathname: browser.path.join(browser.files_dir, "html", "social.html"), | ||
protocol: "file:", | ||
slashes: true | ||
}) | ||
) | ||
pathname: browser.path.join(browser.files_dir, 'html', 'social.html'), | ||
protocol: 'file:', | ||
slashes: true, | ||
}), | ||
); | ||
}, 1000); | ||
}); | ||
}) | ||
// newWindow.setMinimumSize(240, 500) | ||
newWindow.setMinimumSize(240, 500) | ||
// newWindow.loadURL('browser://html/social.html') | ||
@@ -1106,12 +1164,12 @@ // newWindow.openDevTools() | ||
browser.url.format({ | ||
pathname: browser.path.join(browser.files_dir, "html", "social.html"), | ||
protocol: "file:", | ||
slashes: true | ||
}) | ||
) | ||
pathname: browser.path.join(browser.files_dir, 'html', 'social.html'), | ||
protocol: 'file:', | ||
slashes: true, | ||
}), | ||
); | ||
callback(newWindow) | ||
callback(newWindow); | ||
return newWindow | ||
} | ||
} | ||
return newWindow; | ||
}; | ||
}; |
{ | ||
"name": "ibrowser", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "Integration For Social-browser.com", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
143375
16
3782
2