Skip to content

Commit

Permalink
feat: add support for Staging Ground
Browse files Browse the repository at this point in the history
  • Loading branch information
double-beep authored Dec 4, 2024
1 parent 8b986ea commit 16e9b0b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/AdvancedFlagging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function setupPostPage(): void {

page = new Page();

if (page.name && page.name !== 'Question') {
if (page.name && page.name !== 'Question' && page.name !== 'Staging Ground') {
page.posts.forEach(post => post.addIcons());

return;
Expand Down
8 changes: 5 additions & 3 deletions src/UserscriptTools/Page.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Post from './Post';

type Pages = 'Question' | 'NATO' | 'Flags' | 'Search' | 'Review';
type Pages = 'Question' | 'NATO' | 'Flags' | 'Search' | 'Review' | 'Staging Ground';

export default class Page {
public static readonly isStackOverflow = /^https:\/\/stackoverflow.com/.test(location.href);
public static readonly isQuestionPage = /\/questions\/\d+.*/.test(location.href);
public static readonly isLqpReviewPage = /\/review\/low-quality-posts(?:\/\d+)?(?:\/)?$/.test(location.href);
public static readonly isStagingGroundPage = /\/staging-ground\/\d+/.test(location.href);

public readonly name: Pages | '';
public readonly posts: Post[] = [];
Expand Down Expand Up @@ -52,16 +53,16 @@ export default class Page {
}

private getName(): Pages | '' {
const isQuestionPage = /\/questions\/\d+.*/.test(location.href);
const isNatoPage = this.href.pathname.startsWith('/tools/new-answers-old-questions');
const isFlagsPage = /\/users\/flag-summary\/\d+/.test(location.href);
const isSearch = this.href.pathname.startsWith('/search');

if (isFlagsPage) return 'Flags';
else if (isNatoPage) return 'NATO';
else if (isQuestionPage) return 'Question';
else if (Page.isQuestionPage) return 'Question';
else if (isSearch) return 'Search';
else if (Page.isLqpReviewPage) return 'Review';
else if (Page.isStagingGroundPage) return 'Staging Ground';
else return '';
}

Expand All @@ -72,6 +73,7 @@ export default class Page {
case 'Flags':
return '.flagged-post';
case 'Question':
case 'Staging Ground':
return '.question, .answer';
case 'Search':
return '.js-search-results .s-post-summary';
Expand Down
2 changes: 1 addition & 1 deletion src/UserscriptTools/Reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class Reporter {
const iconWrapper = document.createElement('div');
iconWrapper.classList.add('flex--item', 'd-inline-block', 'advanced-flagging-icon');

if (!Page.isQuestionPage && !Page.isLqpReviewPage) {
if (!Page.isQuestionPage && !Page.isLqpReviewPage && !Page.isStagingGroundPage) {
iconWrapper.classList.add('ml8'); // flag pages
}

Expand Down

0 comments on commit 16e9b0b

Please sign in to comment.