Add more input types, fix lowercase nodeName, support shift-backspace
Add the date, datetime, datetime-local, month, time, url, and week input types.
Force node names to upper case and node types to lower case before comparison.
Support shift-backspace to go forward, and ignore other modified-backspace
keypresses (i.e. alt-, ctrl-, and meta-backspace).
BUG=638645, 637983, 638469
R=ojan@chromium.org
Review URL: https://codereview.chromium.org//2260633002 .
diff --git a/go-back-with-backspace/content_script.js b/go-back-with-backspace/content_script.js
index cf3a299..32fff92 100644
--- a/go-back-with-backspace/content_script.js
+++ b/go-back-with-backspace/content_script.js
@@ -1,8 +1,12 @@
-// Listen for the backspace key and go back if not in an editable field.
+// Listen for shift-backspace or unmodified backspace and navigate if not in
+// an editable field.
document.addEventListener('keydown', function(e) {
- if (e.which === 8 && // backspace key code
+ if (e.key === 'Backspace' &&
+ !e.altKey &&
+ !e.ctrlKey &&
+ !e.metaKey &&
!isEditable(e.path)) {
- window.history.back();
+ e.shiftKey ? window.history.forward(): window.history.back();
e.preventDefault();
}
});
diff --git a/go-back-with-backspace/is_editable.js b/go-back-with-backspace/is_editable.js
index 585aa4f..d0e4114 100644
--- a/go-back-with-backspace/is_editable.js
+++ b/go-back-with-backspace/is_editable.js
@@ -6,16 +6,24 @@
if (target.isContentEditable)
return true;
- // Several types of input fields are editable, but not all (e.g., checkboxes).
- var nodeName = target.nodeName;
- var nodeType = target.type;
+ // Many types of input fields are editable, but not all (e.g., checkboxes).
+ var nodeName = target.nodeName.toUpperCase();
+ var nodeType = target.type || '';
+ nodeType = nodeType.toLowerCase();
if (nodeName === 'TEXTAREA' ||
(nodeName === 'INPUT' && (nodeType === 'text' ||
- nodeType === 'email' ||
- nodeType === 'number' ||
nodeType === 'password' ||
nodeType === 'search' ||
- nodeType === 'tel'))) {
+ nodeType === 'date' ||
+ nodeType === 'datetime' ||
+ nodeType === 'datetime-local' ||
+ nodeType === 'email' ||
+ nodeType === 'month' ||
+ nodeType === 'number' ||
+ nodeType === 'tel' ||
+ nodeType === 'time' ||
+ nodeType === 'url' ||
+ nodeType === 'week'))) {
return true;
}
diff --git a/go-back-with-backspace/manifest.json b/go-back-with-backspace/manifest.json
index 3eeeb37..39ae0bb 100644
--- a/go-back-with-backspace/manifest.json
+++ b/go-back-with-backspace/manifest.json
@@ -2,7 +2,7 @@
"name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__",
"default_locale": "en",
- "version": "1.4",
+ "version": "1.5",
"manifest_version": 2,
"minimum_chrome_version": "52",
"icons": {
diff --git a/go-back-with-backspace/readme.txt b/go-back-with-backspace/readme.txt
index 9ed2d21..8f94359 100644
--- a/go-back-with-backspace/readme.txt
+++ b/go-back-with-backspace/readme.txt
@@ -6,6 +6,9 @@
pressing backspace and leaving a page -- so we removed the feature from Chrome,
and created this extension for those who prefer the old behavior.
+After this extension is newly installed, enabled, or updated, any open tabs
+will need to be reloaded for the changes to take effect.
+
This extension can't restore backspace on certain special pages, for example
any of the "chrome://" pages such as Settings or Extensions.