Backspace goes back

Backspace key = "go back" as it was before Chrome 52. And Shift+Backspace goes forward.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name          Backspace goes back
// @include       *
// @description   Backspace key = "go back" as it was before Chrome 52. And Shift+Backspace goes forward.
// @version       2.0.0
// @author        wOxxOm
// @namespace     wOxxOm.scripts
// @license       MIT License
// @run-at        document-start
// @grant         none
// ==/UserScript==

addEventListener('keyup', e => {
  if (e.which !== 8 || e.altKey || e.metaKey || e.ctrlKey) {
    return;
  }
  let el = document;
  while (el && (el = el.activeElement)) {
    if (el.isContentEditable ||
        el.localName == 'input' &&
          /^(text|color|date*|email|month|number|password|range|search|tel|time|url|week)$/.test(el.type) ||
        el.localName == 'textarea') {
      return;
    }
    el = el.shadowRoot;
  }
  e.preventDefault();
  el = e.shiftKey ? 'forward' : 'back';
  if (window === top) history[el]();
  else top.postMessage(GM_info.script.name + el, '*');
}, true);

if (window === top) {
  addEventListener('message', e => {
    if (`${e.data}`.startsWith(GM_info.script.name)) {
      e.stopPropagation();
      e.stopImmediatePropagation();
      history[e.data.slice(GM_info.script.name.length)]();
    }
  }, true);
}