-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitter-backspace-back.user.js
More file actions
30 lines (24 loc) · 984 Bytes
/
twitter-backspace-back.user.js
File metadata and controls
30 lines (24 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// ==UserScript==
// @name Twitter - Backspace to Go Back
// @namespace https://github.com/digitalby
// @version 1.1.1
// @author digitalby
// @description Press Backspace to navigate back on Twitter/X
// @match https://twitter.com/*
// @match https://x.com/*
// @require https://raw.githubusercontent.com/digitalby/twitter-userscripts/main/twitter-custom-keys.lib.js
// @grant none
// ==/UserScript==
(function () {
'use strict';
window.__twitterCustomKeys?.register('Backspace', 'Go back');
document.addEventListener('keydown', function (e) {
if (e.key !== 'Backspace') return;
if (window.__twitterCustomKeys?.isTyping?.(e)) return;
// Only act if Twitter's back button is visible
const backBtn = document.querySelector('[data-testid="app-bar-back"]');
if (!backBtn || backBtn.offsetParent === null) return;
e.preventDefault();
backBtn.click();
});
})();