Skip to content

Add Reddit version to submitIssue #5402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions lib/modules/submitIssue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, currentSubreddit, BrowserDetect, regexes, string } from '../utils';
import { ajax } from '../environment';
import type { RedditWikiPage } from '../types/reddit';
import * as NightMode from './nightMode';
Expand Down Expand Up @@ -119,16 +119,24 @@ 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'}

`);

function checkIfSubmitting() {
const subredditInput: ?HTMLInputElement = (document.getElementById('sr-autocomplete'): any);
const selfText: ?HTMLTextAreaElement = (document.querySelector('.usertext-edit textarea'): any);
/* $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);
}

if (subredditInput) {
function check() {
const subreddit = subredditInput.value;
const subreddit = isAppType('d2x') ? subredditInput : subredditInput.value;

if (subreddits.includes(subreddit.toLowerCase())) {
showWizard();
Expand All @@ -141,10 +149,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
Expand All @@ -154,7 +164,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, '');
Expand Down