diff --git a/dist/twitter-shortcuts.user.js b/dist/twitter-shortcuts.user.js index 2ec419a..385ea80 100644 --- a/dist/twitter-shortcuts.user.js +++ b/dist/twitter-shortcuts.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Twitter - Shortcuts // @namespace mkobayashime -// @version 0.1.0 +// @version 0.2.0 // @description Refined shortcuts in Twitter for web // @author mkobayashime // @homepage https://github.com/mkobayashime/userscripts @@ -43,13 +43,10 @@ const config = {}; e.preventDefault(); } if (e.key === "[" || e.key === "]") { - if (!window.location.href.startsWith("https://twitter.com/home")) return; - const timelineTabs = Array.from( - document.querySelectorAll( - "[role='tablist'] a[href='/home'][role='tab']" - ) + const tabs = Array.from( + document.querySelectorAll("[role='tablist'] a[role='tab']") ); - const activeTabIndex = timelineTabs.findIndex( + const activeTabIndex = tabs.findIndex( (element) => element.ariaSelected === "true" ); if (activeTabIndex < 0) return; @@ -58,12 +55,12 @@ const config = {}; ? activeTabIndex === 0 ? -1 : activeTabIndex - 1 - : activeTabIndex === timelineTabs.length - 1 + : activeTabIndex === tabs.length - 1 ? -1 : activeTabIndex + 1; if (indexOfTabToClick < 0) return; - if (timelineTabs[indexOfTabToClick]) { - timelineTabs[indexOfTabToClick].click(); + if (tabs[indexOfTabToClick]) { + tabs[indexOfTabToClick].click(); } } }); diff --git a/src/userscripts/meta/index.ts b/src/userscripts/meta/index.ts index 85bf420..50352d8 100644 --- a/src/userscripts/meta/index.ts +++ b/src/userscripts/meta/index.ts @@ -200,7 +200,7 @@ export const meta: { [name: string]: UserScriptMeta | undefined } = { icon: "https://www.google.com/s2/favicons?domain=twitter.com", match: "https://twitter.com/*", name: "Twitter - Shortcuts", - version: "0.1.0", + version: "0.2.0", }, "zoom-web-shortcuts": { description: "Google Meet-like Ctrl-d/e shortcuts in Zoom", diff --git a/src/userscripts/twitter-shortcuts.user.ts b/src/userscripts/twitter-shortcuts.user.ts index 6a67b23..4316ab1 100644 --- a/src/userscripts/twitter-shortcuts.user.ts +++ b/src/userscripts/twitter-shortcuts.user.ts @@ -30,15 +30,11 @@ const config = {}; } if (e.key === "[" || e.key === "]") { - if (!window.location.href.startsWith("https://twitter.com/home")) return; - - const timelineTabs = Array.from( - document.querySelectorAll( - "[role='tablist'] a[href='/home'][role='tab']" - ) + const tabs = Array.from( + document.querySelectorAll("[role='tablist'] a[role='tab']") ); - const activeTabIndex = timelineTabs.findIndex( + const activeTabIndex = tabs.findIndex( (element) => element.ariaSelected === "true" ); if (activeTabIndex < 0) return; @@ -48,13 +44,13 @@ const config = {}; ? activeTabIndex === 0 ? -1 : activeTabIndex - 1 - : activeTabIndex === timelineTabs.length - 1 + : activeTabIndex === tabs.length - 1 ? -1 : activeTabIndex + 1; if (indexOfTabToClick < 0) return; - if (timelineTabs[indexOfTabToClick]) { - timelineTabs[indexOfTabToClick].click(); + if (tabs[indexOfTabToClick]) { + tabs[indexOfTabToClick].click(); } } });