Skip to content
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

Add module "Submission Shortcuts" #5465

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 53 additions & 0 deletions lib/modules/submissionShortcuts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* @flow */
import $ from 'jquery';
import { Module } from '../core/module';
import { checkKeysForEvent, click } from '../utils';

export const module: Module<*> = new Module('submissionShortcuts');

module.moduleName = 'submissionShortcutsName';
module.category = 'submissionsCategory';
module.description = 'submissionShurtcutsDesc';
module.options = {
markSpammed: {
type: 'keycode',
value: [70, true, false, false, false], // alt-f
description: 'submissionShortcutsMarkSpammedDesc',
title: 'submissionShortcutsMarkSpammedTitle',
mustBeLoggedIn: true,
buttonSelector: '.icon-spam',
},
remove: {
type: 'keycode',
value: [68, true, false, false, false], // alt-d
description: 'submissionShortcutsRemoveDesc',
title: 'submissionShortcutsRemoveTitle',
mustBeLoggedIn: true,
buttonSelector: '.icon-remove',
},
markApproved: {
type: 'keycode',
value: [63, true, false, false, false], // alt-s
description: 'submissionShortcutsMarkApprovedDesc',
title: 'submissionShortcutsMarkApprovedTitle',
mustBeLoggedIn: true,
buttonSelector: '.icon-approve',
},

};

module.contentStart = () => {
const optionValues = Object.values(module.options);

$(document.body).on('keydown', (e: KeyboardEvent) => {
optionValues.forEach(shortcut => {
if (checkKeysForEvent(e, shortcut.value)) {
const iconElement = document.querySelector(`:focus ${shortcut.buttonSelector}`);

if (iconElement) {
click(iconElement.parentNode);
}
}
});
});
};
38 changes: 31 additions & 7 deletions locales/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4456,10 +4456,34 @@
"quarantineHideFlairDesc": {
"message": "Hide \"Quarantined\" post flair (regardless of where the post is being viewed from)"
},
"quarantineHideInSubTitle": {
"message": "Hide subreddit warnings"
},
"quarantineHideInSubDesc": {
"message": "Hide all warnings of quarantine while viewing a quarantined subreddit"
}
}
"quarantineHideInSubTitle": {
"message": "Hide subreddit warnings"
},
"quarantineHideInSubDesc": {
"message": "Hide all warnings of quarantine while viewing a quarantined subreddit"
},
"submissionShortcutsName": {
"message": "Submission Shortcuts"
},
"submissionShurtcutsDesc": {
"message": "Add shortcuts to the currently focused submission."
},
"submissionShortcutsMarkSpammedDesc": {
"message": "Mark focused submission as spammed."
},
"submissionShortcutsMarkSpammedTitle": {
"message": "Mark as spammed"
},
"submissionShortcutsMarkApprovedDesc": {
"message": "Mark focused submission as approved."
},
"submissionShortcutsMarkApprovedTitle": {
"message": "Approve"
},
"submissionShortcutsRemoveDesc": {
"message": "Remove focused submission."
},
"submissionShortcutsRemoveTitle": {
"message": "Remove"
}
}