Move report issue and error log to browserAction context menu.

Also adds context menu item for toggling Quick Switch. Fix #464.
The context menu can be opened by right-clicking the browserAction icon.
This commit is contained in:
FelisCatus 2015-05-28 16:56:23 +08:00
parent 0316041745
commit 97de45e892
20 changed files with 125 additions and 82 deletions

View File

@ -1012,7 +1012,7 @@ msgid "popup_reportIssues"
msgstr "Report issues" msgstr "Report issues"
msgid "popup_errorLog" msgid "popup_errorLog"
msgstr "Error log" msgstr "Save error log"
msgid "popup_requestErrorCount" msgid "popup_requestErrorCount"
msgstr "$COUNT$ failed resources" msgstr "$COUNT$ failed resources"
@ -1114,3 +1114,6 @@ msgstr "Inspect proxy to be used if this Link is opened"
msgid "contextMenu_inspectElement" msgid "contextMenu_inspectElement"
msgstr "Inspect proxy used for this Element" msgstr "Inspect proxy used for this Element"
msgid "contextMenu_enableQuickSwitch"
msgstr "Enable Quick Switch"

View File

@ -1005,7 +1005,7 @@ msgid "popup_reportIssues"
msgstr "Report problémů" msgstr "Report problémů"
msgid "popup_errorLog" msgid "popup_errorLog"
msgstr "Protokol chyb" msgstr "Exportovat Protokol chyb"
msgid "popup_requestErrorCount" msgid "popup_requestErrorCount"
msgstr "$COUNT$ chybových požadavků" msgstr "$COUNT$ chybových požadavků"
@ -1110,3 +1110,6 @@ msgstr "Zkontrolujte, zda server proxy používaná tento prvek"
msgid "contextMenu_inspectElement" msgid "contextMenu_inspectElement"
msgstr "Zkontrolujte, zda server proxy používaná tento prvek" msgstr "Zkontrolujte, zda server proxy používaná tento prvek"
msgid "contextMenu_enableQuickSwitch"
msgstr "Povolit Rychlé přepínání"

View File

@ -1000,7 +1000,7 @@ msgid "popup_reportIssues"
msgstr "Report issues" msgstr "Report issues"
msgid "popup_errorLog" msgid "popup_errorLog"
msgstr "Error log" msgstr "Save error log"
msgid "popup_requestErrorCount" msgid "popup_requestErrorCount"
msgstr "$COUNT$ failed resources" msgstr "$COUNT$ failed resources"
@ -1096,3 +1096,6 @@ msgstr "Inspect proxy to be used if this Link is opened"
msgid "contextMenu_inspectElement" msgid "contextMenu_inspectElement"
msgstr "Inspect proxy used for this Element" msgstr "Inspect proxy used for this Element"
msgid "contextMenu_enableQuickSwitch"
msgstr "Enable Quick Switch"

View File

@ -1015,7 +1015,7 @@ msgid "popup_reportIssues"
msgstr "Report issues" msgstr "Report issues"
msgid "popup_errorLog" msgid "popup_errorLog"
msgstr "Error log" msgstr "Save error log"
msgid "popup_requestErrorCount" msgid "popup_requestErrorCount"
msgstr "$COUNT$ failed resources" msgstr "$COUNT$ failed resources"
@ -1117,3 +1117,6 @@ msgstr "Inspect proxy to be used if this Link is opened"
msgid "contextMenu_inspectElement" msgid "contextMenu_inspectElement"
msgstr "Inspeccionar proxy utilizado para este Elemento." msgstr "Inspeccionar proxy utilizado para este Elemento."
msgid "contextMenu_enableQuickSwitch"
msgstr "Enable Quick Switch"

View File

@ -1013,7 +1013,7 @@ msgid "popup_reportIssues"
msgstr "Report issues" msgstr "Report issues"
msgid "popup_errorLog" msgid "popup_errorLog"
msgstr "Error log" msgstr "Save error log"
msgid "popup_requestErrorCount" msgid "popup_requestErrorCount"
msgstr "$COUNT$ failed resources" msgstr "$COUNT$ failed resources"
@ -1115,3 +1115,6 @@ msgstr "Inspect proxy to be used if this Link is opened"
msgid "contextMenu_inspectElement" msgid "contextMenu_inspectElement"
msgstr "Inspect proxy used for this Element" msgstr "Inspect proxy used for this Element"
msgid "contextMenu_enableQuickSwitch"
msgstr "Enable Quick Switch"

View File

@ -1008,7 +1008,7 @@ msgid "popup_reportIssues"
msgstr "Report issues" msgstr "Report issues"
msgid "popup_errorLog" msgid "popup_errorLog"
msgstr "Error log" msgstr "Save error log"
msgid "popup_requestErrorCount" msgid "popup_requestErrorCount"
msgstr "$COUNT$ failed resources" msgstr "$COUNT$ failed resources"
@ -1105,3 +1105,6 @@ msgstr "Inspect proxy to be used if this Link is opened"
msgid "contextMenu_inspectElement" msgid "contextMenu_inspectElement"
msgstr "Inspect proxy used for this Element" msgstr "Inspect proxy used for this Element"
msgid "contextMenu_enableQuickSwitch"
msgstr "Enable Quick Switch"

View File

@ -1017,7 +1017,7 @@ msgid "popup_reportIssues"
msgstr "Report issues" msgstr "Report issues"
msgid "popup_errorLog" msgid "popup_errorLog"
msgstr "Error log" msgstr "Save error log"
msgid "popup_requestErrorCount" msgid "popup_requestErrorCount"
msgstr "$COUNT$ failed resources" msgstr "$COUNT$ failed resources"
@ -1119,3 +1119,6 @@ msgstr "Inspect proxy to be used if this Link is opened"
msgid "contextMenu_inspectElement" msgid "contextMenu_inspectElement"
msgstr "Inspect proxy used for this Element" msgstr "Inspect proxy used for this Element"
msgid "contextMenu_enableQuickSwitch"
msgstr "Enable Quick Switch"

View File

@ -1014,7 +1014,7 @@ msgid "popup_reportIssues"
msgstr "Report issues" msgstr "Report issues"
msgid "popup_errorLog" msgid "popup_errorLog"
msgstr "Error log" msgstr "Save error log"
msgid "popup_requestErrorCount" msgid "popup_requestErrorCount"
msgstr "$COUNT$ failed resources" msgstr "$COUNT$ failed resources"
@ -1111,3 +1111,6 @@ msgstr "Inspect proxy to be used if this Link is opened"
msgid "contextMenu_inspectElement" msgid "contextMenu_inspectElement"
msgstr "Inspect proxy used for this Element" msgstr "Inspect proxy used for this Element"
msgid "contextMenu_enableQuickSwitch"
msgstr "Enable Quick Switch"

View File

@ -879,7 +879,7 @@ msgid "popup_reportIssues"
msgstr "反馈问题" msgstr "反馈问题"
msgid "popup_errorLog" msgid "popup_errorLog"
msgstr "错误日志" msgstr "保存错误日志"
msgid "popup_requestErrorCount" msgid "popup_requestErrorCount"
msgstr "$COUNT$个资源未加载" msgstr "$COUNT$个资源未加载"
@ -975,3 +975,6 @@ msgstr "检查此[链接目标]将会使用的代理"
msgid "contextMenu_inspectElement" msgid "contextMenu_inspectElement"
msgstr "检查此[元素]使用的代理" msgstr "检查此[元素]使用的代理"
msgid "contextMenu_enableQuickSwitch"
msgstr "启用快速切换"

View File

@ -879,7 +879,7 @@ msgid "popup_reportIssues"
msgstr "反饋問題" msgstr "反饋問題"
msgid "popup_errorLog" msgid "popup_errorLog"
msgstr "錯誤日誌" msgstr "儲存错误日志"
msgid "popup_requestErrorCount" msgid "popup_requestErrorCount"
msgstr "$COUNT$個資源未載入" msgstr "$COUNT$個資源未載入"
@ -975,3 +975,6 @@ msgstr "檢查此[連結目標]將會使用的代理"
msgid "contextMenu_inspectElement" msgid "contextMenu_inspectElement"
msgstr "檢查此[元素]使用的代理" msgstr "檢查此[元素]使用的代理"
msgid "contextMenu_enableQuickSwitch"
msgstr "啟用快速切換"

View File

@ -0,0 +1,56 @@
window.UglifyJS_NoUnsafeEval = true
localStorage['log'] = ''
localStorage['logLastError'] = ''
window.OmegaContextMenuQuickSwitchHandler = -> null
# We don't need this API. However its presence indicates that Chrome >= 35
# which provides info.checked we need in contextMenu callback.
# https://developer.chrome.com/extensions/contextMenus
if chrome.i18n.getUILanguage?
# We must create the menu item here before others to make it first in menu.
chrome.contextMenus.create({
id: 'enableQuickSwitch'
title: chrome.i18n.getMessage('contextMenu_enableQuickSwitch')
type: 'checkbox'
checked: false
contexts: ["browser_action"]
onclick: (info) -> window.OmegaContextMenuQuickSwitchHandler(info)
})
chrome.contextMenus.create({
title: chrome.i18n.getMessage('popup_reportIssues')
contexts: ["browser_action"]
onclick: ->
url = 'https://github.com/FelisCatus/SwitchyOmega/issues/new?title=&body='
finalUrl = url
try
extensionVersion = chrome.runtime.getManifest().version
env =
extensionVersion: extensionVersion
projectVersion: extensionVersion
userAgent: navigator.userAgent
body = chrome.i18n.getMessage('popup_issueTemplate', [
env.projectVersion, env.userAgent
])
body ||= """
\n\n
<!-- Please write your comment ABOVE this line. -->
SwitchyOmega #{env.projectVersion}
#{env.userAgent}
"""
finalUrl = url + encodeURIComponent(body)
err = localStorage['logLastError']
if err
body += "\n```\n#{err}\n```"
finalUrl = (url + encodeURIComponent(body)).substr(0, 2000)
chrome.tabs.create(url: finalUrl)
})
chrome.contextMenus.create({
title: chrome.i18n.getMessage('popup_errorLog')
contexts: ["browser_action"]
onclick: ->
blob = new Blob [localStorage['log']], {type: "text/plain;charset=utf-8"}
saveAs(blob, "OmegaLog_#{Date.now()}.txt")
})

View File

@ -2,9 +2,9 @@ module.exports =
target_web: target_web:
files: files:
'build/js/omega_target_web.js': 'omega_target_web.coffee' 'build/js/omega_target_web.js': 'omega_target_web.coffee'
target_web_log:
files:
'build/js/omega_target_web_basics.js': 'omega_target_web_basics.coffee'
background: background:
files: files:
'build/js/background.js': 'background.coffee' 'build/js/background.js': 'background.coffee'
background_preload:
files:
'build/js/background_preload.js': 'background_preload.coffee'

View File

@ -1,13 +0,0 @@
window.OmegaTargetWebBasics =
getLog: (callback) ->
callback(localStorage['log'] || '')
getError: (callback) ->
callback(localStorage['logLastError'] || '')
getEnv: (callback) ->
extensionVersion = chrome.runtime.getManifest().version
callback({
extensionVersion: extensionVersion
projectVersion: extensionVersion
userAgent: navigator.userAgent
})
getMessage: chrome.i18n.getMessage.bind(chrome.i18n)

View File

@ -8,6 +8,7 @@
<canvas id="canvas-icon"></canvas> <canvas id="canvas-icon"></canvas>
<canvas id="canvas-icon-2x"></canvas> <canvas id="canvas-icon-2x"></canvas>
<script src="js/log_error.js"></script> <script src="js/log_error.js"></script>
<script src="lib/FileSaver/FileSaver.js"></script>
<script src="js/background_preload.js"></script> <script src="js/background_preload.js"></script>
<script src="js/omega_pac.min.js"></script> <script src="js/omega_pac.min.js"></script>
<script src="js/omega_target.min.js"></script> <script src="js/omega_target.min.js"></script>

View File

@ -1,3 +0,0 @@
window.UglifyJS_NoUnsafeEval = true
localStorage['log'] = ''
localStorage['logLastError'] = ''

View File

@ -1,4 +1,4 @@
OmegaTarget = require('omega-target') OcontextMenu_inspectElementmegaTarget = require('omega-target')
OmegaPac = OmegaTarget.OmegaPac OmegaPac = OmegaTarget.OmegaPac
Promise = OmegaTarget.Promise Promise = OmegaTarget.Promise
xhr = Promise.promisify(require('xhr')) xhr = Promise.promisify(require('xhr'))
@ -165,7 +165,24 @@ class ChromeOptions extends OmegaTarget.Options
return return
_quickSwitchInit: false _quickSwitchInit: false
setQuickSwitch: (quickSwitch) -> _quickSwitchContextMenuCreated: false
_quickSwitchCanEnable: false
setQuickSwitch: (quickSwitch, canEnable) ->
@_quickSwitchCanEnable = canEnable
if not @_quickSwitchContextMenuCreated
@_quickSwitchContextMenuCreated = true
if quickSwitch
chrome.contextMenus.update('enableQuickSwitch', {checked: true})
window.OmegaContextMenuQuickSwitchHandler = (info) =>
changes = {}
changes['-enableQuickSwitch'] = info.checked
setOptions = @_setOptions(changes)
if info.checked and not @_quickSwitchCanEnable
setOptions.then ->
chrome.tabs.create(
url: chrome.extension.getURL('options.html#/ui')
)
if quickSwitch if quickSwitch
chrome.browserAction.setPopup({popup: ''}) chrome.browserAction.setPopup({popup: ''})
if not @_quickSwitchInit if not @_quickSwitchInit

View File

@ -391,14 +391,12 @@ class Options
# @returns {Promise} A promise which is fulfilled when the quick switch is set # @returns {Promise} A promise which is fulfilled when the quick switch is set
### ###
reloadQuickSwitch: -> reloadQuickSwitch: ->
profiles = @_options['-quickSwitchProfiles']
profiles = null if profiles.length < 2
if @_options['-enableQuickSwitch'] if @_options['-enableQuickSwitch']
profiles = @_options['-quickSwitchProfiles'] @setQuickSwitch(profiles, !!profiles)
if profiles.length >= 2
@setQuickSwitch(profiles)
else
@setQuickSwitch(null)
else else
@setQuickSwitch(null) @setQuickSwitch(null, !!profiles)
###* ###*
# Apply the settings related to element proxy inspection. # Apply the settings related to element proxy inspection.
@ -594,9 +592,10 @@ class Options
# Set or disable the quick switch profiles. # Set or disable the quick switch profiles.
# In base class, this method is not implemented and will not do anything. # In base class, this method is not implemented and will not do anything.
# @param {string[]|null} quickSwitch The profile names, or null to disable # @param {string[]|null} quickSwitch The profile names, or null to disable
# @param {boolean} canEnable Whether user can enable quick switch or not.
# @returns {Promise} A promise which is fulfilled when the quick switch is set # @returns {Promise} A promise which is fulfilled when the quick switch is set
### ###
setQuickSwitch: (quickSwitch) -> setQuickSwitch: (quickSwitch, canEnable) ->
Promise.resolve() Promise.resolve()
###* ###*

View File

@ -28,8 +28,6 @@ shortcutKeys =
61: 'addRule' # = 61: 'addRule' # =
84: 'tempRule' # t 84: 'tempRule' # t
79: 'option' # o 79: 'option' # o
73: 'issue' # i
76: 'log' # l
82: 'requestInfo' # r 82: 'requestInfo' # r
for i in [1..9] for i in [1..9]
@ -63,8 +61,6 @@ jQuery(document).on 'keydown', (e) ->
'addRule': 'A' 'addRule': 'A'
'tempRule': 'T' 'tempRule': 'T'
'option': 'O' 'option': 'O'
'issue': 'I'
'log': 'L'
'requestInfo': 'R' 'requestInfo': 'R'
for shortcut, key of keys for shortcut, key of keys
showHelp(shortcut, key) showHelp(shortcut, key)

View File

@ -1,26 +0,0 @@
# Use events to ensure that the log can be downloaded even if everything else
# fails to load.
document.querySelector('.error-log').addEventListener 'click', (->
window.OmegaTargetWebBasics.getLog (log) ->
blob = new Blob [log], {type: "text/plain;charset=utf-8"}
saveAs(blob, "OmegaLog_#{Date.now()}.txt")
), false
window.OmegaTargetWebBasics.getEnv (env) ->
url = 'https://github.com/FelisCatus/SwitchyOmega/issues/new?title=&body='
body = window.OmegaTargetWebBasics.getMessage('popup_issueTemplate', [
env.projectVersion, env.userAgent
])
body ||= """
\n\n
<!-- Please write your comment ABOVE this line. -->
SwitchyOmega #{env.projectVersion}
#{env.userAgent}
"""
link = document.querySelector('.report-issue')
link.href = url + encodeURIComponent(body)
window.OmegaTargetWebBasics.getError (err) ->
return unless err
body += "\n```\n#{err}\n```"
final_url = url + encodeURIComponent(body)
link.href = final_url.substr(0, 2000) # Limit URL up to 2000 chars.

View File

@ -80,17 +80,6 @@ html(lang='en' ng-app='omegaPopup' ng-controller='PopupCtrl' ng-csp)
span.glyphicon.glyphicon-wrench span.glyphicon.glyphicon-wrench
= ' ' = ' '
span {{'popup_showOptions' | tr}} span {{'popup_showOptions' | tr}}
li
a.report-issue(href='https://github.com/FelisCatus/SwitchyOmega/issues'
target='_blank' data-shortcut='issue')
span.glyphicon.glyphicon-comment
= ' '
span {{'popup_reportIssues' | tr}}
li
a.error-log(href='#' role='button' data-shortcut='log')
span.glyphicon.glyphicon-download
= ' '
span {{'popup_errorLog' | tr}}
form.condition-form(name='conditionForm' style='display: none;' form.condition-form(name='conditionForm' style='display: none;'
ng-style='{display: showConditionForm ? "block" : "none"}' ng-style='{display: showConditionForm ? "block" : "none"}'
ng-submit='addCondition(rule.condition, rule.profileName)') ng-submit='addCondition(rule.condition, rule.profileName)')
@ -165,9 +154,6 @@ html(lang='en' ng-app='omegaPopup' ng-controller='PopupCtrl' ng-csp)
ng-click='openOptions("#/general")') {{'popup_configureMonitorWebRequests' | tr}} ng-click='openOptions("#/general")') {{'popup_configureMonitorWebRequests' | tr}}
script(src='js/log_error.js') script(src='js/log_error.js')
script(src='lib/FileSaver/FileSaver.js')
script(src='js/omega_target_web_basics.js')
script(src='js/popup_basics.js')
script(src='lib/jquery/jquery.min.js') script(src='lib/jquery/jquery.min.js')
script(src='lib/angular/angular.min.js') script(src='lib/angular/angular.min.js')
script(src='lib/angular-bootstrap/ui-bootstrap-tpls.min.js') script(src='lib/angular-bootstrap/ui-bootstrap-tpls.min.js')