mirror of
https://github.com/zero-peak/ZeroOmega.git
synced 2025-03-12 00:08:13 -04:00
1. Improve the performance of a large number of Rule Lists
2. Fix the pop-up window issue in Edge for Android #93
This commit is contained in:
parent
bd8187800a
commit
fa756d806a
@ -73,6 +73,18 @@ module.exports =
|
|||||||
]
|
]
|
||||||
new U2.AST_Do(
|
new U2.AST_Do(
|
||||||
body: new U2.AST_BlockStatement body: [
|
body: new U2.AST_BlockStatement body: [
|
||||||
|
new U2.AST_If(
|
||||||
|
condition: new U2.AST_UnaryPrefix(
|
||||||
|
operator: "!",
|
||||||
|
expression: new U2.AST_Sub(
|
||||||
|
expression: new U2.AST_SymbolRef name: 'profiles'
|
||||||
|
property: new U2.AST_SymbolRef name: 'result'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
body: new U2.AST_Return(
|
||||||
|
value: new U2.AST_SymbolRef name: "result"
|
||||||
|
)
|
||||||
|
)
|
||||||
new U2.AST_SimpleStatement body: new U2.AST_Assign(
|
new U2.AST_SimpleStatement body: new U2.AST_Assign(
|
||||||
left: new U2.AST_SymbolRef name: 'result'
|
left: new U2.AST_SymbolRef name: 'result'
|
||||||
operator: '='
|
operator: '='
|
||||||
|
@ -472,6 +472,12 @@ module.exports = exports =
|
|||||||
match: (profile, request) ->
|
match: (profile, request) ->
|
||||||
result = exports.match(profile, request, 'SwitchProfile')
|
result = exports.match(profile, request, 'SwitchProfile')
|
||||||
compile: (profile) ->
|
compile: (profile) ->
|
||||||
|
if profile.isTempPacProfile
|
||||||
|
exports.compile(profile, 'SwitchProfile')
|
||||||
|
else
|
||||||
|
if profile.pacScript
|
||||||
|
exports.compile(profile, 'PacProfile')
|
||||||
|
else
|
||||||
exports.compile(profile, 'SwitchProfile')
|
exports.compile(profile, 'SwitchProfile')
|
||||||
updateUrl: (profile) -> profile.sourceUrl
|
updateUrl: (profile) -> profile.sourceUrl
|
||||||
updateContentTypeHints: -> [
|
updateContentTypeHints: -> [
|
||||||
@ -497,6 +503,8 @@ module.exports = exports =
|
|||||||
if formatHandler.preprocess?
|
if formatHandler.preprocess?
|
||||||
data = formatHandler.preprocess(data)
|
data = formatHandler.preprocess(data)
|
||||||
return false if profile.ruleList == data
|
return false if profile.ruleList == data
|
||||||
|
# regenerator pacScript
|
||||||
|
profile.pacScript = ''
|
||||||
profile.ruleList = data
|
profile.ruleList = data
|
||||||
return true
|
return true
|
||||||
'SwitchyRuleListProfile': 'RuleListProfile'
|
'SwitchyRuleListProfile': 'RuleListProfile'
|
||||||
|
@ -24,6 +24,16 @@ import "./js/background.js" // zeroBackground
|
|||||||
const isFirefox = !!globalThis.localStorage
|
const isFirefox = !!globalThis.localStorage
|
||||||
const zcb = globalThis.zeroDetectModeCB
|
const zcb = globalThis.zeroDetectModeCB
|
||||||
|
|
||||||
|
globalThis.POPUPHTMLURL = './popup-iframe.html'
|
||||||
|
//if android, (eg. edge canary for android), use default popup/index.html
|
||||||
|
//https://github.com/zero-peak/ZeroOmega/issues/93
|
||||||
|
if (globalThis.navigator && /Android/i.test(globalThis.navigator.userAgent)){
|
||||||
|
globalThis.POPUPHTMLURL = './popup/index.html'
|
||||||
|
}
|
||||||
|
|
||||||
|
// keepAlive
|
||||||
|
setInterval(chrome.runtime.getPlatformInfo, 25 * 1000) //https://developer.chrome.com/docs/extensions/develop/migrate/to-service-workers
|
||||||
|
|
||||||
function detectPrivateMode(cb) {
|
function detectPrivateMode(cb) {
|
||||||
var db, tempMode,on, off;
|
var db, tempMode,on, off;
|
||||||
if (zcb) {
|
if (zcb) {
|
||||||
|
@ -23,7 +23,7 @@ module.exports = class ExternalApi
|
|||||||
|
|
||||||
@options.setProxyNotControllable(null)
|
@options.setProxyNotControllable(null)
|
||||||
#chrome.action.setPopup?({popup: 'popup/index.html'})
|
#chrome.action.setPopup?({popup: 'popup/index.html'})
|
||||||
chrome.action.setPopup?({popup: 'popup-iframe.html'})
|
chrome.action.setPopup?({popup: globalThis.POPUPHTMLURL})
|
||||||
@options.reloadQuickSwitch()
|
@options.reloadQuickSwitch()
|
||||||
@disabled = false
|
@disabled = false
|
||||||
@options.clearBadge()
|
@options.clearBadge()
|
||||||
|
@ -164,8 +164,7 @@ class ChromeOptions extends OmegaTarget.Options
|
|||||||
if quickSwitch
|
if quickSwitch
|
||||||
chrome.action.setPopup({popup: ''})
|
chrome.action.setPopup({popup: ''})
|
||||||
else
|
else
|
||||||
#chrome.action.setPopup({popup: 'popup/index.html'})
|
chrome.action.setPopup({popup: globalThis.POPUPHTMLURL})
|
||||||
chrome.action.setPopup({popup: 'popup-iframe.html'})
|
|
||||||
|
|
||||||
chrome.contextMenus?.update('enableQuickSwitch', {checked: !!quickSwitch})
|
chrome.contextMenus?.update('enableQuickSwitch', {checked: !!quickSwitch})
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
|
@ -2,6 +2,10 @@ OmegaTarget = require('omega-target')
|
|||||||
Promise = OmegaTarget.Promise
|
Promise = OmegaTarget.Promise
|
||||||
ProxyAuth = require('./proxy_auth')
|
ProxyAuth = require('./proxy_auth')
|
||||||
|
|
||||||
|
|
||||||
|
# TODO temp profile will always create new cache.
|
||||||
|
profilePacCache = new Map()
|
||||||
|
|
||||||
class ProxyImpl
|
class ProxyImpl
|
||||||
constructor: (log) ->
|
constructor: (log) ->
|
||||||
@log = log
|
@log = log
|
||||||
@ -31,6 +35,25 @@ class ProxyImpl
|
|||||||
)
|
)
|
||||||
getProfilePacScript: (profile, meta, options) ->
|
getProfilePacScript: (profile, meta, options) ->
|
||||||
meta ?= profile
|
meta ?= profile
|
||||||
|
referenced_profiles = []
|
||||||
|
ref_set = OmegaPac.Profiles.allReferenceSet(profile,
|
||||||
|
options, profileNotFound: @_profileNotFound.bind(this))
|
||||||
|
for own _, name of ref_set
|
||||||
|
_profile = OmegaPac.Profiles.byName(name, options)
|
||||||
|
if _profile
|
||||||
|
referenced_profiles.push(_profile)
|
||||||
|
cachedProfiles = profilePacCache.keys().toArray()
|
||||||
|
allProfiles = Object.values(options)
|
||||||
|
cachedProfiles.forEach((cachedProfile) ->
|
||||||
|
if allProfiles.indexOf(cachedProfile) < 0
|
||||||
|
profilePacCache.delete(cachedProfile)
|
||||||
|
)
|
||||||
|
profilePac = profilePacCache.get(profile)
|
||||||
|
profilePacKey = referenced_profiles.map(
|
||||||
|
(_profile) -> _profile.name + '_' + (_profile.revision or 1)
|
||||||
|
).join(',')
|
||||||
|
if profilePac?[profilePacKey]
|
||||||
|
return profilePac[profilePacKey]
|
||||||
ast = OmegaPac.PacGenerator.script(options, profile,
|
ast = OmegaPac.PacGenerator.script(options, profile,
|
||||||
profileNotFound: @_profileNotFound.bind(this))
|
profileNotFound: @_profileNotFound.bind(this))
|
||||||
ast = OmegaPac.PacGenerator.compress(ast)
|
ast = OmegaPac.PacGenerator.compress(ast)
|
||||||
@ -39,6 +62,10 @@ class ProxyImpl
|
|||||||
profileName = profileName.replace(/\*/g, '\\u002a')
|
profileName = profileName.replace(/\*/g, '\\u002a')
|
||||||
profileName = profileName.replace(/\\/g, '\\u002f')
|
profileName = profileName.replace(/\\/g, '\\u002f')
|
||||||
prefix = "/*OmegaProfile*#{profileName}*#{meta.revision}*/"
|
prefix = "/*OmegaProfile*#{profileName}*#{meta.revision}*/"
|
||||||
return prefix + script
|
pacScript = prefix + script
|
||||||
|
profilePac = {}
|
||||||
|
profilePac[profilePacKey] = pacScript
|
||||||
|
profilePacCache.set(profile, profilePac)
|
||||||
|
return pacScript
|
||||||
|
|
||||||
module.exports = ProxyImpl
|
module.exports = ProxyImpl
|
||||||
|
@ -4,6 +4,29 @@ Promise = OmegaTarget.Promise
|
|||||||
chromeApiPromisify = require('../chrome_api').chromeApiPromisify
|
chromeApiPromisify = require('../chrome_api').chromeApiPromisify
|
||||||
ProxyImpl = require('./proxy_impl')
|
ProxyImpl = require('./proxy_impl')
|
||||||
|
|
||||||
|
notExistentWebsite = "preflight-auth.non-existent-website.zzzzzzzzeroomega.zero"
|
||||||
|
|
||||||
|
getFirstAuthProfile = (profile, options) ->
|
||||||
|
for rule in profile.rules
|
||||||
|
profileName = rule.profileName
|
||||||
|
_profile = OmegaPac.Profiles.byName(profileName, options)
|
||||||
|
return _profile if _profile.auth
|
||||||
|
|
||||||
|
addAuthPreflightRule = (profile, options) ->
|
||||||
|
return unless profile.profileType is 'SwitchProfile'
|
||||||
|
return unless profile.rules or profile.rules.length is 0
|
||||||
|
authProfile = getFirstAuthProfile(profile, options)
|
||||||
|
return unless authProfile
|
||||||
|
profile.rules.unshift({
|
||||||
|
"condition": {
|
||||||
|
"conditionType": "HostWildcardCondition"
|
||||||
|
"pattern": notExistentWebsite
|
||||||
|
}
|
||||||
|
"isPreflightRule": true
|
||||||
|
"profileName": authProfile.name
|
||||||
|
})
|
||||||
|
return authProfile
|
||||||
|
|
||||||
class SettingsProxyImpl extends ProxyImpl
|
class SettingsProxyImpl extends ProxyImpl
|
||||||
@isSupported: -> chrome?.proxy?.settings?
|
@isSupported: -> chrome?.proxy?.settings?
|
||||||
features: ['fullUrlHttp', 'pacScript', 'watchProxyChange']
|
features: ['fullUrlHttp', 'pacScript', 'watchProxyChange']
|
||||||
@ -14,6 +37,7 @@ class SettingsProxyImpl extends ProxyImpl
|
|||||||
return chromeApiPromisify(chrome.proxy.settings, 'clear')({}).then =>
|
return chromeApiPromisify(chrome.proxy.settings, 'clear')({}).then =>
|
||||||
chrome.proxy.settings.get {}, @_proxyChangeListener
|
chrome.proxy.settings.get {}, @_proxyChangeListener
|
||||||
return
|
return
|
||||||
|
authProfile = null
|
||||||
config = {}
|
config = {}
|
||||||
if profile.profileType == 'DirectProfile'
|
if profile.profileType == 'DirectProfile'
|
||||||
config['mode'] = 'direct'
|
config['mode'] = 'direct'
|
||||||
@ -31,14 +55,24 @@ class SettingsProxyImpl extends ProxyImpl
|
|||||||
config = @_fixedProfileConfig(profile)
|
config = @_fixedProfileConfig(profile)
|
||||||
else
|
else
|
||||||
config['mode'] = 'pac_script'
|
config['mode'] = 'pac_script'
|
||||||
|
authProfile = addAuthPreflightRule(profile, options)
|
||||||
config['pacScript'] =
|
config['pacScript'] =
|
||||||
mandatory: true
|
mandatory: true
|
||||||
data: @getProfilePacScript(profile, meta, options)
|
data: @getProfilePacScript(profile, meta, options)
|
||||||
return @setProxyAuth(profile, options).then(->
|
return @setProxyAuth(profile, options).then(->
|
||||||
return chromeApiPromisify(chrome.proxy.settings, 'set')({value: config})
|
return chromeApiPromisify(chrome.proxy.settings, 'set')({value: config})
|
||||||
).then(=>
|
).then(=>
|
||||||
|
if authProfile
|
||||||
|
fetch("https://" + notExistentWebsite).catch(-> authProfile)
|
||||||
chrome.proxy.settings.get {}, @_proxyChangeListener
|
chrome.proxy.settings.get {}, @_proxyChangeListener
|
||||||
return
|
return
|
||||||
|
).finally(->
|
||||||
|
if authProfile
|
||||||
|
profile.rules.forEach((rule, index) ->
|
||||||
|
if rule.isPreflightRule
|
||||||
|
profile.rules.splice(index, 1)
|
||||||
|
)
|
||||||
|
profile.rules
|
||||||
)
|
)
|
||||||
_fixedProfileConfig: (profile) ->
|
_fixedProfileConfig: (profile) ->
|
||||||
config = {}
|
config = {}
|
||||||
|
@ -5,6 +5,31 @@ Storage = require './storage'
|
|||||||
OmegaPac = require 'omega-pac'
|
OmegaPac = require 'omega-pac'
|
||||||
jsondiffpatch = require 'jsondiffpatch'
|
jsondiffpatch = require 'jsondiffpatch'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PROFILETEMPPACKEY = '__tempZeroRuleListPac'
|
||||||
|
|
||||||
|
generateProfileTempPac = (profile) ->
|
||||||
|
tempProfile = OmegaPac.Profiles.create(PROFILETEMPPACKEY, profile.profileType)
|
||||||
|
tempProfile.defaultProfileName = profile.defaultProfileName
|
||||||
|
tempProfile.format = profile.format
|
||||||
|
tempProfile.matchProfileName = profile.matchProfileName
|
||||||
|
tempProfile.ruleList = profile.ruleList
|
||||||
|
tempProfile.isTempPacProfile = true
|
||||||
|
options = {}
|
||||||
|
nameKey = OmegaPac.Profiles.nameAsKey(tempProfile.name)
|
||||||
|
options[nameKey] = tempProfile
|
||||||
|
profileNotFound = -> 'ignore'
|
||||||
|
|
||||||
|
ast = OmegaPac.PacGenerator.script(options, tempProfile.name,
|
||||||
|
profileNotFound: profileNotFound)
|
||||||
|
pac = ast.print_to_string(beautify: true, comments: true)
|
||||||
|
pac = OmegaPac.PacGenerator.ascii(pac)
|
||||||
|
return pac
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Options
|
class Options
|
||||||
###*
|
###*
|
||||||
# The entire set of options including profiles and other settings.
|
# The entire set of options including profiles and other settings.
|
||||||
@ -109,7 +134,7 @@ class Options
|
|||||||
@_storage.get(null)
|
@_storage.get(null)
|
||||||
else
|
else
|
||||||
@sync.init({gistId, gistToken}).catch((e) ->
|
@sync.init({gistId, gistToken}).catch((e) ->
|
||||||
console.error('sync init fail::', e)
|
console.log('sync init fail::', e)
|
||||||
)
|
)
|
||||||
@_syncWatchStop = @sync.watchAndPull(@_storage)
|
@_syncWatchStop = @sync.watchAndPull(@_storage)
|
||||||
@sync.copyTo(@_storage).catch(Storage.StorageUnavailableError, =>
|
@sync.copyTo(@_storage).catch(Storage.StorageUnavailableError, =>
|
||||||
@ -384,6 +409,8 @@ class Options
|
|||||||
value.revision)
|
value.revision)
|
||||||
continue if result >= 0
|
continue if result >= 0
|
||||||
profilesChanged = true
|
profilesChanged = true
|
||||||
|
if value.profileType is 'RuleListProfile'
|
||||||
|
value.pacScript = generateProfileTempPac(value)
|
||||||
if key is '-builtinProfiles'
|
if key is '-builtinProfiles'
|
||||||
currentProfileAffected = 'changed'
|
currentProfileAffected = 'changed'
|
||||||
@_options[key] = value
|
@_options[key] = value
|
||||||
@ -722,6 +749,7 @@ class Options
|
|||||||
profile.lastUpdate = new Date().toISOString()
|
profile.lastUpdate = new Date().toISOString()
|
||||||
if OmegaPac.Profiles.update(profile, data)
|
if OmegaPac.Profiles.update(profile, data)
|
||||||
OmegaPac.Profiles.dropCache(profile)
|
OmegaPac.Profiles.dropCache(profile)
|
||||||
|
OmegaPac.Profiles.updateRevision(profile)
|
||||||
changes = {}
|
changes = {}
|
||||||
changes[key] = profile
|
changes[key] = profile
|
||||||
@_setOptions(changes).return(profile)
|
@_setOptions(changes).return(profile)
|
||||||
|
Loading…
Reference in New Issue
Block a user