mirror of
https://github.com/zero-peak/ZeroOmega.git
synced 2025-01-22 15:08:12 -05:00
Implement rule list exporting. Fix #99.
This commit is contained in:
parent
ca71a9a7d9
commit
8e56c4f883
@ -268,6 +268,12 @@
|
||||
"options_deleteProfile": {
|
||||
"message": "Delete"
|
||||
},
|
||||
"options_profileExportRuleList": {
|
||||
"message": "Publish rule list"
|
||||
},
|
||||
"options_profileExportRuleListHelp": {
|
||||
"message": "Export Switch Rules as text format for publishing."
|
||||
},
|
||||
"options_profileExportPac": {
|
||||
"message": "Export PAC"
|
||||
},
|
||||
|
@ -268,6 +268,12 @@
|
||||
"options_deleteProfile": {
|
||||
"message": "删除"
|
||||
},
|
||||
"options_profileExportRuleList": {
|
||||
"message": "发布规则列表"
|
||||
},
|
||||
"options_profileExportRuleListHelp": {
|
||||
"message": "将切换规则导出为文本格式以便发布。"
|
||||
},
|
||||
"options_profileExportPac": {
|
||||
"message": "导出PAC"
|
||||
},
|
||||
|
@ -268,6 +268,12 @@
|
||||
"options_deleteProfile": {
|
||||
"message": "刪除"
|
||||
},
|
||||
"options_profileExportRuleList": {
|
||||
"message": "釋出規則列表"
|
||||
},
|
||||
"options_profileExportRuleListHelp": {
|
||||
"message": "將切換規則匯出為文字格式以便釋出。"
|
||||
},
|
||||
"options_profileExportPac": {
|
||||
"message": "導出PAC"
|
||||
},
|
||||
|
@ -268,6 +268,12 @@
|
||||
"options_deleteProfile": {
|
||||
"message": "刪除"
|
||||
},
|
||||
"options_profileExportRuleList": {
|
||||
"message": "釋出規則列表"
|
||||
},
|
||||
"options_profileExportRuleListHelp": {
|
||||
"message": "將切換規則匯出為文字格式以便釋出。"
|
||||
},
|
||||
"options_profileExportPac": {
|
||||
"message": "匯出PAC"
|
||||
},
|
||||
|
@ -1,4 +1,5 @@
|
||||
Buffer = require('buffer').Buffer
|
||||
Conditions = require('./conditions')
|
||||
|
||||
strStartsWith = (str, prefix) ->
|
||||
str.substr(0, prefix.length) == prefix
|
||||
@ -52,6 +53,23 @@ module.exports = exports =
|
||||
# Exclusive rules have higher priority, so they come first.
|
||||
return exclusive_rules.concat normal_rules
|
||||
'Switchy':
|
||||
conditionFromLegacyWildcard: (pattern) ->
|
||||
if pattern[0] == '@'
|
||||
pattern = pattern.substring(1)
|
||||
else
|
||||
if pattern.indexOf('://') <= 0 and pattern[0] != '*'
|
||||
pattern = '*' + pattern
|
||||
if pattern[pattern.length - 1] != '*'
|
||||
pattern += '*'
|
||||
|
||||
host = Conditions.urlWildcard2HostWildcard(pattern)
|
||||
if host
|
||||
conditionType: 'HostWildcardCondition'
|
||||
pattern: host
|
||||
else
|
||||
conditionType: 'UrlWildcardCondition'
|
||||
pattern: pattern
|
||||
|
||||
parse: (text, matchProfileName, defaultProfileName) ->
|
||||
text = text.trim()
|
||||
normal_rules = []
|
||||
@ -79,8 +97,7 @@ module.exports = exports =
|
||||
line = line.substring(1)
|
||||
cond = switch section
|
||||
when 'WILDCARD'
|
||||
conditionType: 'UrlWildcardCondition'
|
||||
pattern: line
|
||||
exports['Switchy'].conditionFromLegacyWildcard(line)
|
||||
when 'REGEXP'
|
||||
conditionType: 'UrlRegexCondition'
|
||||
pattern: line
|
||||
|
@ -158,21 +158,7 @@ module.exports = (oldOptions, i18n) ->
|
||||
switch rule['patternType']
|
||||
when 'wildcard'
|
||||
pattern = rule['urlPattern']
|
||||
if pattern[0] == '@'
|
||||
pattern = pattern.substring(1)
|
||||
else
|
||||
if pattern.indexOf('://') <= 0 and pattern[0] != '*'
|
||||
pattern = '*' + pattern
|
||||
if pattern[pattern.length - 1] != '*'
|
||||
pattern += '*'
|
||||
|
||||
host = OmegaPac.Conditions.urlWildcard2HostWildcard(pattern)
|
||||
if host
|
||||
conditionType: 'HostWildcardCondition'
|
||||
pattern: host
|
||||
else
|
||||
conditionType: 'UrlWildcardCondition'
|
||||
pattern: pattern
|
||||
OmegaPac.RuleList['Switchy'].conditionFromLegacyWildcard(pattern)
|
||||
else
|
||||
conditionType: 'UrlRegexCondition'
|
||||
pattern: rule['urlPattern']
|
||||
|
@ -83,6 +83,10 @@ angular.module('omega').controller 'ProfileCtrl', ($scope, $stateParams,
|
||||
revisionChanged = true
|
||||
this.$watch expression, onChange, true
|
||||
|
||||
$scope.exportRuleList = null
|
||||
$scope.setExportRuleListHandler = (exportRuleList) ->
|
||||
$scope.exportRuleList = exportRuleList
|
||||
|
||||
unwatch = $scope.$watch (-> $scope.options?['+' + name]), (profile) ->
|
||||
if not profile
|
||||
if $scope.options
|
||||
|
@ -40,6 +40,38 @@ angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $location,
|
||||
}
|
||||
]
|
||||
|
||||
exportRuleList = ->
|
||||
wildcardRules = ''
|
||||
regexpRules = ''
|
||||
for rule in $scope.profile.rules
|
||||
i = ''
|
||||
if rule.profileName == 'direct'
|
||||
i = '!'
|
||||
switch rule.condition.conditionType
|
||||
when 'HostWildcardCondition'
|
||||
wildcardRules += i + '@*://' + rule.condition.pattern + '/*' + '\r\n'
|
||||
when 'UrlWildcardCondition'
|
||||
wildcardRules += i + '@' + rule.condition.pattern + '\r\n'
|
||||
when 'UrlRegexCondition'
|
||||
regexpRules += i + rule.condition.pattern + '\r\n'
|
||||
|
||||
text = """
|
||||
; Summary: Proxy Switchy! Exported Rule List
|
||||
; Date: #{new Date().toLocaleDateString()}
|
||||
; Website: http://bit.ly/proxyswitchy
|
||||
|
||||
#BEGIN
|
||||
|
||||
[wildcard]
|
||||
#{wildcardRules}
|
||||
[regexp]
|
||||
#{regexpRules}
|
||||
#END
|
||||
"""
|
||||
blob = new Blob [text], {type: "text/plain;charset=utf-8"}
|
||||
fileName = $scope.profile.name.replace(/\W+/g, '_')
|
||||
saveAs(blob, "SwitchyRules_#{fileName}.ssrl")
|
||||
|
||||
expandGroups = (groups) ->
|
||||
result = []
|
||||
for group in groups
|
||||
@ -82,8 +114,10 @@ angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $location,
|
||||
$scope.showConditionTypes = $scope.hasConditionTypes
|
||||
if $scope.showConditionTypes == 0
|
||||
$scope.conditionTypes = basicConditionTypesExpanded
|
||||
$scope.setExportRuleListHandler(exportRuleList)
|
||||
else
|
||||
$scope.conditionTypes = advancedConditionTypesExpanded
|
||||
$scope.setExportRuleListHandler(null)
|
||||
if not $scope.options["-showConditionTypes"]?
|
||||
$scope.options["-showConditionTypes"] = $scope.showConditionTypes
|
||||
unwatchRules?()
|
||||
|
@ -1,5 +1,10 @@
|
||||
.page-header
|
||||
.profile-actions
|
||||
button.btn.btn-default(ng-show='exportRuleList' ng-click='exportRuleList(profile.name)' title="{{'options_profileExportRuleListHelp' | tr}}")
|
||||
span.glyphicon.glyphicon-list
|
||||
= ' '
|
||||
| {{'options_profileExportRuleList' | tr}}
|
||||
= ' '
|
||||
button.btn.btn-default(ng-show='scriptable' ng-click='exportScript(profile.name)' title="{{'options_exportPacFileHelp' | tr}}")
|
||||
span.glyphicon.glyphicon-download
|
||||
= ' '
|
||||
|
Loading…
Reference in New Issue
Block a user