From eeadb6d7a3d3e19d1f5863c592bacefb6c285f7d Mon Sep 17 00:00:00 2001 From: Elijah Date: Mon, 2 May 2022 11:21:14 -0700 Subject: [PATCH 1/3] Add Reddit version to submitIssue --- lib/modules/submitIssue.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/modules/submitIssue.js b/lib/modules/submitIssue.js index dddea2c2dc..199e7ea996 100644 --- a/lib/modules/submitIssue.js +++ b/lib/modules/submitIssue.js @@ -5,7 +5,7 @@ import { once } from 'lodash-es'; import * as Metadata from '../core/metadata'; import { guiders } from '../vendor/guiders'; import { Module } from '../core/module'; -import { BrowserDetect, regexes, string } from '../utils'; +import { isAppType, BrowserDetect, regexes, string } from '../utils'; import { ajax } from '../environment'; import type { RedditWikiPage } from '../types/reddit'; import * as NightMode from './nightMode'; @@ -119,6 +119,7 @@ export const diagnostics = once(() => ` - Browser Version: ${BrowserDetect.version} - Cookies Enabled: ${String(navigator.cookieEnabled)} - Reddit beta: ${String($('.beta-hint').length > 0)} +- Reddit Version: ${isAppType('d2x') ? 'new' : 'old'} `); From 5cf87f7e2d132fadc115236b30693eed866e87d9 Mon Sep 17 00:00:00 2001 From: ElijahPepe Date: Mon, 2 May 2022 17:41:52 -0700 Subject: [PATCH 2/3] Refactor submitIssue --- lib/modules/submitIssue.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/modules/submitIssue.js b/lib/modules/submitIssue.js index 199e7ea996..6cd66827d9 100644 --- a/lib/modules/submitIssue.js +++ b/lib/modules/submitIssue.js @@ -5,7 +5,7 @@ import { once } from 'lodash-es'; import * as Metadata from '../core/metadata'; import { guiders } from '../vendor/guiders'; import { Module } from '../core/module'; -import { isAppType, BrowserDetect, regexes, string } from '../utils'; +import { isAppType, currentSubreddit, BrowserDetect, regexes, string } from '../utils'; import { ajax } from '../environment'; import type { RedditWikiPage } from '../types/reddit'; import * as NightMode from './nightMode'; @@ -124,12 +124,17 @@ export const diagnostics = once(() => ` `); function checkIfSubmitting() { - const subredditInput: ?HTMLInputElement = (document.getElementById('sr-autocomplete'): any); - const selfText: ?HTMLTextAreaElement = (document.querySelector('.usertext-edit textarea'): any); + let subredditInput: ?any = (document.getElementById('sr-autocomplete'): any); + let selfText: ?HTMLTextAreaElement = (document.querySelector('.usertext-edit textarea'): any); + if (isAppType('d2x')) { + $('button[aria-label="Switch to markdown"]').trigger('click'); + subredditInput = (currentSubreddit(): any); + selfText = (document.querySelector('textarea[placeholder=\'Text (optional)\']'): any); + } if (subredditInput) { function check() { - const subreddit = subredditInput.value; + const subreddit = isAppType('d2x') ? subredditInput : subredditInput.value; if (subreddits.includes(subreddit.toLowerCase())) { showWizard(); @@ -142,10 +147,12 @@ function checkIfSubmitting() { check(); - subredditInput.addEventListener('change', e => { - if ((e: any).res) return; - check(); - }); + if (!isAppType('d2x')) { + subredditInput.addEventListener('change', e => { + if ((e: any).res) return; + check(); + }); + } // don't delegate, reddit cancels bubbling // wait a moment, reddit loads some metadata @@ -155,7 +162,7 @@ function checkIfSubmitting() { if (selfText && subredditInput) { $(selfText).add(subredditInput).on('blur', () => { - const subreddit = subredditInput.value; + const subreddit = isAppType('d2x') ? subredditInput : subredditInput.value; if ([...subreddits, ...subredditsForDiagnostics].includes(subreddit.toLowerCase())) { const diagnosticsStripped = diagnostics().replace(/\s/g, ''); const selfTextStripped = selfText.value.replace(/\s/g, ''); From 726c137a23e00d101fa5c4360bdd8c5951b7bb84 Mon Sep 17 00:00:00 2001 From: ElijahPepe Date: Mon, 2 May 2022 22:12:01 -0700 Subject: [PATCH 3/3] Fix Flow --- lib/modules/submitIssue.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/modules/submitIssue.js b/lib/modules/submitIssue.js index 6cd66827d9..555e76b0ab 100644 --- a/lib/modules/submitIssue.js +++ b/lib/modules/submitIssue.js @@ -124,12 +124,14 @@ export const diagnostics = once(() => ` `); function checkIfSubmitting() { + /* $FlowIgnore[1] */ let subredditInput: ?any = (document.getElementById('sr-autocomplete'): any); + /* $FlowIgnore[1] */ let selfText: ?HTMLTextAreaElement = (document.querySelector('.usertext-edit textarea'): any); if (isAppType('d2x')) { $('button[aria-label="Switch to markdown"]').trigger('click'); subredditInput = (currentSubreddit(): any); - selfText = (document.querySelector('textarea[placeholder=\'Text (optional)\']'): any); + selfText = (document.querySelector('textarea[placeholder="Text (optional)"]'): any); } if (subredditInput) {