diff --git a/omega-i18n/en/messages.json b/omega-i18n/en/messages.json index 4c2d9ed..6421aee 100644 --- a/omega-i18n/en/messages.json +++ b/omega-i18n/en/messages.json @@ -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" }, diff --git a/omega-i18n/zh_CN/messages.json b/omega-i18n/zh_CN/messages.json index 5f4860f..eb83db3 100644 --- a/omega-i18n/zh_CN/messages.json +++ b/omega-i18n/zh_CN/messages.json @@ -268,6 +268,12 @@ "options_deleteProfile": { "message": "删除" }, + "options_profileExportRuleList": { + "message": "发布规则列表" + }, + "options_profileExportRuleListHelp": { + "message": "将切换规则导出为文本格式以便发布。" + }, "options_profileExportPac": { "message": "导出PAC" }, diff --git a/omega-i18n/zh_HK/messages.json b/omega-i18n/zh_HK/messages.json index 917c6be..9e67a08 100644 --- a/omega-i18n/zh_HK/messages.json +++ b/omega-i18n/zh_HK/messages.json @@ -268,6 +268,12 @@ "options_deleteProfile": { "message": "刪除" }, + "options_profileExportRuleList": { + "message": "釋出規則列表" + }, + "options_profileExportRuleListHelp": { + "message": "將切換規則匯出為文字格式以便釋出。" + }, "options_profileExportPac": { "message": "導出PAC" }, diff --git a/omega-i18n/zh_TW/messages.json b/omega-i18n/zh_TW/messages.json index 6ae11e3..584b798 100644 --- a/omega-i18n/zh_TW/messages.json +++ b/omega-i18n/zh_TW/messages.json @@ -268,6 +268,12 @@ "options_deleteProfile": { "message": "刪除" }, + "options_profileExportRuleList": { + "message": "釋出規則列表" + }, + "options_profileExportRuleListHelp": { + "message": "將切換規則匯出為文字格式以便釋出。" + }, "options_profileExportPac": { "message": "匯出PAC" }, diff --git a/omega-pac/src/rule_list.coffee b/omega-pac/src/rule_list.coffee index 988815e..d519d72 100644 --- a/omega-pac/src/rule_list.coffee +++ b/omega-pac/src/rule_list.coffee @@ -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 diff --git a/omega-target-chromium-extension/src/upgrade.coffee b/omega-target-chromium-extension/src/upgrade.coffee index 62016ca..f8ffbfd 100644 --- a/omega-target-chromium-extension/src/upgrade.coffee +++ b/omega-target-chromium-extension/src/upgrade.coffee @@ -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'] diff --git a/omega-web/src/omega/controllers/profile.coffee b/omega-web/src/omega/controllers/profile.coffee index f15f9c7..2b768d7 100644 --- a/omega-web/src/omega/controllers/profile.coffee +++ b/omega-web/src/omega/controllers/profile.coffee @@ -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 diff --git a/omega-web/src/omega/controllers/switch_profile.coffee b/omega-web/src/omega/controllers/switch_profile.coffee index efa7c29..8515702 100644 --- a/omega-web/src/omega/controllers/switch_profile.coffee +++ b/omega-web/src/omega/controllers/switch_profile.coffee @@ -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?() diff --git a/omega-web/src/partials/profile.jade b/omega-web/src/partials/profile.jade index 4331a6e..26d9951 100644 --- a/omega-web/src/partials/profile.jade +++ b/omega-web/src/partials/profile.jade @@ -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 = ' '