Skip to content

Commit c9a43b3

Browse files
committed
fix: fixed search optoins parse
1 parent f529cb7 commit c9a43b3

4 files changed

Lines changed: 18 additions & 9 deletions

File tree

src/plugins/reddit-search-options-persist/observeElement.test.ts renamed to src/plugins/duolingo-hide-popups/observeElement.test.ts

File renamed without changes.

src/plugins/reddit-search-options-persist/observeElement.ts renamed to src/plugins/duolingo-hide-popups/observeElement.ts

File renamed without changes.

src/plugins/duolingo-hide-popups/userscript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { observeElement } from '../reddit-search-options-persist/observeElement'
1+
import { observeElement } from './observeElement'
22

33
// Hide Duolingo popups that promote their app
44
function injectStyles() {

src/plugins/reddit-search-options-persist/userscript.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,27 @@ observe(
6565

6666
function 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(/\/user\/([^\/]+)/)
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)

0 commit comments

Comments
 (0)