1
Fork 0

Include counts of changed elements in debug logging.

This commit is contained in:
Bauke 2022-02-23 23:41:32 +01:00
parent af3e930544
commit 8a19364636
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 20 additions and 9 deletions

View File

@ -2,16 +2,19 @@ import Settings from '../settings.js';
import {log, querySelectorAll} from '../utilities/exports.js'; import {log, querySelectorAll} from '../utilities/exports.js';
export function runHideVotesFeature(settings: Settings) { export function runHideVotesFeature(settings: Settings) {
hideVotes(settings); const counts = hideVotes(settings);
log('Hide Votes: Initialized.'); log(`Hide Votes: Initialized for ${counts} votes.`);
} }
function hideVotes(settings: Settings) { function hideVotes(settings: Settings): number {
let count = 0;
if (settings.data.hideVotes.comments) { if (settings.data.hideVotes.comments) {
const commentVotes = querySelectorAll( const commentVotes = querySelectorAll(
'.btn-post-action[data-ic-put-to*="/vote"]:not(.trx-votes-hidden)', '.btn-post-action[data-ic-put-to*="/vote"]:not(.trx-votes-hidden)',
'.btn-post-action[data-ic-delete-from*="/vote"]:not(.trx-votes-hidden)', '.btn-post-action[data-ic-delete-from*="/vote"]:not(.trx-votes-hidden)',
); );
count += commentVotes.length;
for (const vote of commentVotes) { for (const vote of commentVotes) {
vote.classList.add('trx-votes-hidden'); vote.classList.add('trx-votes-hidden');
@ -23,7 +26,9 @@ function hideVotes(settings: Settings) {
} }
if (settings.data.hideVotes.ownComments) { if (settings.data.hideVotes.ownComments) {
for (const vote of querySelectorAll('.comment-votes')) { const ownComments = querySelectorAll('.comment-votes');
count += ownComments.length;
for (const vote of ownComments) {
vote.classList.add('trx-hidden'); vote.classList.add('trx-hidden');
} }
} }
@ -41,9 +46,13 @@ function hideVotes(settings: Settings) {
selectors.push('div > .topic-voting-votes:not(.trx-votes-hidden)'); selectors.push('div > .topic-voting-votes:not(.trx-votes-hidden)');
} }
for (const vote of querySelectorAll(...selectors)) { const topicVotes = querySelectorAll(...selectors);
count += topicVotes.length;
for (const vote of topicVotes) {
vote.classList.add('trx-votes-hidden'); vote.classList.add('trx-votes-hidden');
vote.textContent = '-'; vote.textContent = '-';
} }
} }
return count;
} }

View File

@ -75,15 +75,15 @@ const snippets: MarkdownSnippet[] = [
})); }));
export function runMarkdownToolbarFeature() { export function runMarkdownToolbarFeature() {
addToolbarsToTextareas(); const count = addToolbarsToTextareas();
log('Markdown Toolbar: Initialized.'); log(`Markdown Toolbar: Initialized for ${count} textareas.`);
} }
function addToolbarsToTextareas() { function addToolbarsToTextareas(): number {
// Grab all Markdown forms that don't have already have a toolbar. // Grab all Markdown forms that don't have already have a toolbar.
const markdownForms = querySelectorAll('.form-markdown:not(.trx-toolbar)'); const markdownForms = querySelectorAll('.form-markdown:not(.trx-toolbar)');
if (markdownForms.length === 0) { if (markdownForms.length === 0) {
return; return 0;
} }
for (const form of markdownForms) { for (const form of markdownForms) {
@ -118,6 +118,8 @@ function addToolbarsToTextareas() {
dropdownPlaceholder, dropdownPlaceholder,
); );
} }
return markdownForms.length;
} }
type Props = { type Props = {