Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Add shortcut to view page source #3474

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/localShortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports.register = (win) => {
['Ctrl+PageUp', messages.SHORTCUT_PREV_TAB],
['CmdOrCtrl+9', messages.SHORTCUT_SET_ACTIVE_FRAME_TO_LAST],
['CmdOrCtrl+G', messages.SHORTCUT_ACTIVE_FRAME_FIND_NEXT],
['CmdOrCtrl+U', messages.SHORTCUT_ACTIVE_FRAME_VIEW_SOURCE],
['CmdOrCtrl+Shift+G', messages.SHORTCUT_ACTIVE_FRAME_FIND_PREV],
['CmdOrCtrl+Alt+J', messages.SHORTCUT_ACTIVE_FRAME_TOGGLE_DEV_TOOLS],
['CmdOrCtrl+Shift+=', messages.SHORTCUT_ACTIVE_FRAME_ZOOM_IN],
Expand Down
4 changes: 3 additions & 1 deletion js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,9 @@ class Frame extends ImmutableComponent {
break
case 'view-source':
const sourceLocation = UrlUtil.getViewSourceUrlFromUrl(this.webview.getURL())
windowActions.newFrame({location: sourceLocation}, true)
if (sourceLocation !== null) {
windowActions.newFrame({location: sourceLocation}, true)
}
// TODO: Make the URL bar show the view-source: prefix
break
case 'save':
Expand Down
1 change: 1 addition & 0 deletions js/contextMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ function mainTemplateInit (nodeProps, frame) {
if (!isLink && !isImage) {
template.push({
label: locale.translation('viewPageSource'),
accelerator: 'CmdOrCtrl+U',
click: (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.send(messages.SHORTCUT_ACTIVE_FRAME_VIEW_SOURCE)
Expand Down
11 changes: 11 additions & 0 deletions js/lib/urlutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ const UrlUtil = {
}
},

isImageAddress (url) {
return (url.match(/\.(jpeg|jpg|gif|png|svg|bmp)$/))
},

isHttpAddress (url) {
return (url.match(/^https?:\/\/(.*)/))
},

/**
* Checks if a string is not a URL.
* @param {String} input The input value.
Expand Down Expand Up @@ -218,6 +226,9 @@ const UrlUtil = {
* @returns {String} The view-source URL.
*/
getViewSourceUrlFromUrl: function (input) {
if (this.isImageAddress(input) || !this.isHttpAddress(input)) {
return null
}
if (this.isViewSourceUrl(input)) {
return input
}
Expand Down