File tree Expand file tree Collapse file tree
reddit-search-options-persist Expand file tree Collapse file tree File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change 1- import { observeElement } from '../reddit-search-options-persist /observeElement'
1+ import { observeElement } from './observeElement'
22
33// Hide Duolingo popups that promote their app
44function injectStyles ( ) {
Original file line number Diff line number Diff line change @@ -65,18 +65,27 @@ observe(
6565
6666function performSearch ( query : string ) {
6767 let baseURL = '/search'
68- if ( querySelector ( document . body , '#search-input-chip' ) ) {
69- const subredditMatch = location . pathname . match ( / ^ \/ r \/ ( [ ^ \/ ] + ) / )
68+ const searchInput = querySelector ( document . body , 'faceplate-search-input' ) as HTMLElement | null
69+ // {"action_info":{"type":"input-community"}}
70+ const trackingContext = JSON . parse ( searchInput ?. getAttribute ( 'data-faceplate-tracking-context' ) || '{}' ) as {
71+ action_info ?: {
72+ type ?: 'input-community' | 'input-global' | 'input-profile'
73+ }
74+ }
75+ if ( trackingContext . action_info ?. type === 'input-community' ) {
76+ // when /r/{subreddit}/search
77+ const subredditMatch = location . pathname . match ( / \/ r \/ ( [ ^ \/ ] + ) / )
7078 if ( subredditMatch ) {
7179 baseURL = `/r/${ subredditMatch [ 1 ] } /search`
7280 }
73- }
74- const filter = querySelector ( document . body , '#search-input-remove-filter' ) as HTMLDivElement | null
75- if ( filter && filter . innerText . trim ( ) . startsWith ( 'u/' ) ) {
76- const username = filter . innerText . trim ( ) . slice ( 2 )
77- if ( username ) {
78- baseURL = `/user/${ username } /search`
81+ } else if ( trackingContext . action_info ?. type === 'input-profile' ) {
82+ // when /user/{username}/search
83+ const userMatch = location . pathname . match ( / \/ u s e r \/ ( [ ^ \/ ] + ) / )
84+ if ( userMatch ) {
85+ baseURL = `/user/${ userMatch [ 1 ] } /search`
7986 }
87+ } else if ( trackingContext . action_info ?. type === 'input-global' ) {
88+ // when /search
8089 }
8190
8291 const params = new URLSearchParams ( location . search )
You can’t perform that action at this time.
0 commit comments