Backspace goes back

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey to install this script.

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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);
}