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

Added support for comments on other sites than SO, added placeholders, fixed some bugs #281

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion src/UserscriptTools/sotools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function getPostType(element: HTMLElement): PostType {
// - if it's an answer, anchor will have the answer-hyperlink class
// (ask SE why)
return element.classList.contains('question')
|| element.querySelector('.question-hyperlink, .s-link')
|| element.querySelector('.question-hyperlink, .s-link:not([href^="/collectives"])')
? 'Question'
: 'Answer';
}
Expand Down
19 changes: 14 additions & 5 deletions src/popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,16 @@ function getCommentText(
const { addAuthorName: AddAuthorName } = cachedConfiguration;

const commentType = (opReputation || 0) > 50 ? 'high' : 'low';
const comment = comments?.[commentType] || comments?.low;
let comment = comments?.[commentType] || comments?.low;

if (comment){
const sitename = StackExchange.options.site.name || '';
const siteurl = window.location.hostname;

comment = comment.replace(/%SITENAME%/, sitename);
comment = comment.replace(/%SITEURL%/, siteurl);
comment = comment.replace(/%OP%/, opName);
fastnlight0 marked this conversation as resolved.
Show resolved Hide resolved
}

return (
comment && AddAuthorName
Expand Down Expand Up @@ -390,9 +399,9 @@ function getReportLinks(
// id === 4 => Duplicate Answer
&& (id === 4 ? repost : !repost);

// show the red flags and general items on every site,
// show the red flags, general, and answer-related items on every site,
// restrict the others to Stack Overflow
const showOnSo = ['Red flags', 'General'].includes(belongsTo) || isStackOverflow;
const showOnSo = ['Red flags', 'General', 'Answer-related'].includes(belongsTo) || isStackOverflow;

return enabled && (isGuttenbergItem ? showGutReport : showOnSo);
})
Expand Down Expand Up @@ -472,7 +481,7 @@ function getOptionsRow(
// ['label test', globals.cacheKey]
return config
// don't leave comments on non-SO sites
.filter(([ text ]) => text === 'Leave comment' ? isStackOverflow : true)
// .filter(([ text ]) => text === 'Leave comment' ? isStackOverflow : true)
.map(([text, cacheKey]) => {
const uncheck = cachedConfiguration[cacheKey]
// extra requirement for the leave comment option:
Expand Down Expand Up @@ -583,4 +592,4 @@ export function makeMenu(
setTimeout(() => increaseTooltipWidth(menu));

return menu;
}
}