Skip to content

Commit 2d016c6

Browse files
authored
chore: update dist
1 parent ab011c3 commit 2d016c6

File tree

1 file changed

+106
-78
lines changed

1 file changed

+106
-78
lines changed

dist/AdvancedFlagging.user.js

Lines changed: 106 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,9 @@
5050
Configuration: {
5151
key: "Configuration",
5252
openOnHover: "openOnHover",
53-
defaultNoFlag: "defaultNoFlag",
54-
defaultNoComment: "defaultNoComment",
55-
defaultNoDownvote: "defaultNoDownvote",
56-
defaultNoDelete: "defaultNoDelete",
5753
watchFlags: "watchFlags",
5854
watchQueues: "watchQueues",
55+
allowComments: "allowComments",
5956
linkDisabled: "linkDisabled",
6057
addAuthorName: "addAuthorName",
6158
debug: "debug"
@@ -72,7 +69,7 @@
7269
// cache-related helpers/values
7370
// Some information from cache is stored on the variables as objects to make editing easier and simpler
7471
// Each time something is changed in the variables, update* must also be called to save the changes to the cache
75-
static config = _Store.get(Cached.Configuration.key) ?? {};
72+
static config = _Store.get(Cached.Configuration.key) ?? { default: {} };
7673
static categories = _Store.get(Cached.FlagCategories) ?? [];
7774
static flagTypes = _Store.get(Cached.FlagTypes) ?? [];
7875
static updateConfiguration = () => _Store.set(Cached.Configuration.key, this.config);
@@ -805,6 +802,12 @@
805802
'a[href^="/users/"] div[title]'
806803
)?.title ?? "";
807804
var popupDelay = 4 * 1e3;
805+
var configBoxes = [
806+
["Leave comment", "comment"],
807+
["Flag", "flag"],
808+
["Downvote", "downvote"],
809+
["Delete", "delete"]
810+
];
808811
var getIconPath = (name) => {
809812
const element = GM_getResourceText(name);
810813
const parsed = new DOMParser().parseFromString(element, "text/html");
@@ -1081,12 +1084,10 @@
10811084
name;
10821085
id;
10831086
sanitisedName;
1084-
cacheKey;
10851087
progress = null;
10861088
constructor(name, id) {
10871089
this.name = name;
1088-
this.sanitisedName = this.name.replace(/\s/g, "");
1089-
this.cacheKey = `defaultNo${this.sanitisedName}`;
1090+
this.sanitisedName = this.name.replace(/\s/g, "").toLowerCase();
10901091
this.id = id;
10911092
}
10921093
wasReported() {
@@ -1704,7 +1705,7 @@
17041705
}
17051706
getIcon() {
17061707
return this.createBotIcon(
1707-
this.wasReported() ? `//logs.sobotics.org/Natty/${this.id}.html` : ""
1708+
this.wasReported() ? `//sentinel.sobotics.org/posts/aid/${this.id}` : ""
17081709
);
17091710
}
17101711
getProgressMessage(feedback) {
@@ -1975,9 +1976,8 @@
19751976
const newEntries = Object.entries(this.reporters).filter(([name, instance]) => {
19761977
return instance.showOnPopover() && (!Page.isLqpReviewPage || (name !== "Smokey" || instance.wasReported()));
19771978
}).map(([, instance]) => {
1978-
const botName = instance.sanitisedName.toLowerCase();
1979+
const botName = instance.sanitisedName;
19791980
const botNameId = `advanced-flagging-send-feedback-to-${botName}-${this.id}`;
1980-
const defaultNoCheck = Store.config[instance.cacheKey];
19811981
const iconHtml = instance.getIcon().outerHTML;
19821982
const checkbox = {
19831983
// on post page, the id is not unique!
@@ -1986,7 +1986,7 @@
19861986
text: `${isFlagOrReview ? "" : "Feedback to"} ${iconHtml}`,
19871987
classes: [isFlagOrReview ? "mb4" : "fs-body1"]
19881988
},
1989-
selected: !defaultNoCheck
1989+
selected: Store.config.default[botName]
19901990
};
19911991
return [instance.name, checkbox];
19921992
});
@@ -2378,10 +2378,15 @@
23782378

23792379
// src/modals/config.ts
23802380
function saveChanges() {
2381-
document.querySelectorAll("#advanced-flagging-configuration-section-general > div > input").forEach((element) => {
2382-
const id = element.id.split("-").pop();
2381+
document.querySelectorAll("#advanced-flagging-configuration-section-general input").forEach((element) => {
2382+
const id = element.id;
2383+
const key = id.split("-").pop();
23832384
const checked = element.checked;
2384-
Store.config[id] = checked;
2385+
if (id.startsWith("advanced-flagging-default")) {
2386+
Store.config.default[key] = checked;
2387+
} else {
2388+
Store.config[key] = checked;
2389+
}
23852390
});
23862391
Store.updateConfiguration();
23872392
displayStacksToast("Configuration saved", "success");
@@ -2400,7 +2405,7 @@
24002405
"advanced-flagging-configuration-modal",
24012406
{
24022407
title: {
2403-
text: "AdvancedFlagging configuration"
2408+
text: "Advanced Flagging configuration"
24042409
},
24052410
body: {
24062411
bodyHtml: getConfigModalBody()
@@ -2460,76 +2465,94 @@
24602465
{
24612466
text: "Open dropdown on hover",
24622467
configValue: Cached.Configuration.openOnHover,
2463-
tooltipText: "Open the dropdown on hover and not on click"
2468+
description: "Opens the dropdown on hover and not on click"
24642469
},
24652470
{
24662471
text: "Watch for manual flags",
24672472
configValue: Cached.Configuration.watchFlags,
2468-
tooltipText: "Send feedback when a flag is raised manually"
2473+
description: "Sends feedback when a flag is raised manually"
24692474
},
24702475
{
24712476
text: "Watch for queue responses",
24722477
configValue: Cached.Configuration.watchQueues,
2473-
tooltipText: "Send feedback after a Looks OK or Recommend Deletion review in the Low Quality Answers queue"
2474-
},
2475-
{
2476-
text: "Disable AdvancedFlagging link",
2477-
configValue: Cached.Configuration.linkDisabled
2478-
},
2479-
{
2480-
text: "Uncheck 'Leave comment' by default",
2481-
configValue: Cached.Configuration.defaultNoComment
2482-
},
2483-
{
2484-
text: "Uncheck 'Flag' by default",
2485-
configValue: Cached.Configuration.defaultNoFlag
2486-
},
2487-
{
2488-
text: "Uncheck 'Downvote' by default",
2489-
configValue: Cached.Configuration.defaultNoDownvote
2490-
},
2491-
{
2492-
text: "Uncheck 'Delete' by default",
2493-
configValue: Cached.Configuration.defaultNoDelete
2478+
description: "Sends feedback after a Looks OK or Recommend Deletion review in the Low Quality Answers queue"
24942479
},
24952480
{
24962481
text: "Add author's name before comments",
24972482
configValue: Cached.Configuration.addAuthorName,
2498-
tooltipText: "Add the author's name before every comment to make them friendlier"
2499-
},
2500-
{
2501-
text: "Don't send feedback to Smokey by default",
2502-
configValue: new Reporter("Smokey", 0).cacheKey
2483+
description: "Adds the author's name before every comment to make it friendlier"
25032484
},
25042485
{
2505-
text: "Don't send feedback to Natty by default",
2506-
configValue: new Reporter("Natty", 0).cacheKey
2486+
text: 'Enable "Leave comment" on all Stack Exchange sites',
2487+
configValue: Cached.Configuration.allowComments,
2488+
description: 'Shows the "Leave comment" checkbox and the answer-related dropdown options on every Stack Exchange site'
25072489
},
25082490
{
2509-
text: "Don't send feedback to Guttenberg by default",
2510-
configValue: new Reporter("Guttenberg", 0).cacheKey
2511-
},
2512-
{
2513-
text: "Don't send feedback to Generic Bot by default",
2514-
configValue: new Reporter("Generic Bot", 0).cacheKey
2491+
text: "Disable Advanced Flagging link",
2492+
configValue: Cached.Configuration.linkDisabled
25152493
},
25162494
{
25172495
text: "Enable dry-run mode",
25182496
configValue: Cached.Configuration.debug
25192497
}
2520-
].map(({ text, configValue, tooltipText }) => {
2498+
].map(({ text, configValue, description }) => {
25212499
const selected = Store.config[configValue];
25222500
return {
25232501
id: `advanced-flagging-${configValue}`,
25242502
labelConfig: {
25252503
text,
2526-
description: tooltipText
2504+
description
2505+
},
2506+
selected
2507+
};
2508+
});
2509+
const botBoxes = ["Smokey", "Natty", "Generic Bot", "Guttenberg"].map((name) => {
2510+
const reporter = new Reporter(name, 0);
2511+
const sanitised = reporter.sanitisedName;
2512+
const selected = Store.config.default[sanitised];
2513+
return {
2514+
id: `advanced-flagging-default-${sanitised}`,
2515+
labelConfig: {
2516+
text: name
25272517
},
25282518
selected
25292519
};
25302520
});
2521+
const [defaultFeedback] = checkbox_exports.makeStacksCheckboxes(
2522+
botBoxes,
2523+
{
2524+
horizontal: true,
2525+
classes: ["fs-body2"]
2526+
}
2527+
);
2528+
const botDescription = document.createElement("div");
2529+
botDescription.classList.add("flex--item");
2530+
botDescription.innerText = "Send feedback by default to:";
2531+
defaultFeedback.prepend(botDescription);
2532+
const optionBoxes = configBoxes.map(([name, sanitised]) => {
2533+
const selected = Store.config.default[sanitised];
2534+
return {
2535+
id: `advanced-flagging-default-${sanitised}`,
2536+
labelConfig: {
2537+
text: name
2538+
},
2539+
selected
2540+
};
2541+
});
2542+
const [defaultCheck] = checkbox_exports.makeStacksCheckboxes(
2543+
optionBoxes,
2544+
{
2545+
horizontal: true,
2546+
classes: ["fs-body2"]
2547+
}
2548+
);
2549+
const optionDescription = document.createElement("div");
2550+
optionDescription.classList.add("flex--item");
2551+
optionDescription.innerText = "Check the following by default:";
2552+
defaultCheck.prepend(optionDescription);
25312553
const [fieldset] = checkbox_exports.makeStacksCheckboxes(checkboxes);
25322554
fieldset.id = "advanced-flagging-configuration-section-general";
2555+
fieldset.append(defaultFeedback, defaultCheck);
25332556
return fieldset;
25342557
}
25352558
function getAdminConfigItems() {
@@ -3186,7 +3209,7 @@
31863209
"advanced-flagging-comments-modal",
31873210
{
31883211
title: {
3189-
text: "AdvancedFlagging: edit comments and flags"
3212+
text: "Advanced Flagging: edit comments and flags"
31903213
},
31913214
body: {
31923215
bodyHtml: getCommentsModalBody()
@@ -3288,8 +3311,25 @@
32883311
cachedFlag.reportType = "PlagiarizedContent" /* Plagiarism */;
32893312
});
32903313
Store.updateFlagTypes();
3291-
if (!("defaultNoDelete" in Store.config)) {
3292-
Store.config.defaultNoDelete = true;
3314+
if (!(Cached.Configuration.allowComments in Store.config)) {
3315+
Store.config.allowComments = false;
3316+
Store.updateConfiguration();
3317+
}
3318+
if ("defaultNoSmokey" in Store.config) {
3319+
Store.config.default = {};
3320+
[
3321+
["defaultNoComment", "comment"],
3322+
["defaultNoFlag", "flag"],
3323+
["defaultNoDownvote", "downvote"],
3324+
["defaultNoSmokey", "smokey"],
3325+
["defaultNoNatty", "natty"],
3326+
["defaultNoGuttenberg", "guttenberg"],
3327+
["defaultNoGenericBot", "genericbot"],
3328+
["defaultNoDelete", "delete"]
3329+
].forEach(([oldName, newName]) => {
3330+
Store.config.default[newName] = !Store.config[oldName];
3331+
delete Store.config[oldName];
3332+
});
32933333
Store.updateConfiguration();
32943334
}
32953335
}
@@ -3318,17 +3358,11 @@
33183358
);
33193359
if (!propertyDoesNotExist) return;
33203360
displayStacksToast(
3321-
"Please set up AdvancedFlagging before continuing.",
3361+
"Please set up Advanced Flagging before continuing.",
33223362
"info",
33233363
true
33243364
);
3325-
setTimeout(() => {
3326-
Stacks.showModal(configModal);
3327-
const checkbox = document.querySelector(
3328-
"#advanced-flagging-defaultNoDownvote"
3329-
);
3330-
checkbox.checked = true;
3331-
});
3365+
setTimeout(() => Stacks.showModal(configModal));
33323366
}
33333367

33343368
// src/popover.ts
@@ -3375,6 +3409,7 @@
33753409
const { copypastorId, repost, targetUrl } = copypastor ?? {};
33763410
const categories = Store.categories.filter((item) => item.appliesTo?.includes(this.post.type)).map((item) => ({ ...item, FlagTypes: [] }));
33773411
Store.flagTypes.filter(({ reportType, id, belongsTo, enabled }) => {
3412+
if (belongsTo === "Answer-related" && (Page.isStackOverflow || Store.config.allowComments)) return true;
33783413
const isGuttenbergItem = isSpecialFlag(reportType, false);
33793414
const showGutReport = Boolean(copypastorId) && (id === 4 ? repost : !repost);
33803415
const showOnSo = ["Red flags", "General"].includes(belongsTo) || Page.isStackOverflow;
@@ -3415,18 +3450,12 @@
34153450
// Section #2: Leave comment, Flag, Downvote
34163451
getOptionsRow() {
34173452
const comments = this.post.element.querySelector(".comment-body");
3418-
const config = [
3419-
["Leave comment", Cached.Configuration.defaultNoComment],
3420-
["Flag", Cached.Configuration.defaultNoFlag],
3421-
["Downvote", Cached.Configuration.defaultNoDownvote],
3422-
["Delete", Cached.Configuration.defaultNoDelete]
3423-
];
3424-
return config.filter(([text]) => {
3425-
if (text === "Leave comment") return Page.isStackOverflow;
3453+
return configBoxes.filter(([text]) => {
3454+
if (text === "Leave comment") return Store.config.allowComments || Page.isStackOverflow;
34263455
else if (text === "Delete") return this.post.canDelete(true);
34273456
return true;
34283457
}).map(([text, cacheKey]) => {
3429-
const uncheck = Store.config[cacheKey] || text === "Leave comment" && comments;
3458+
const selected = Store.config.default[cacheKey] && (text === "Leave comment" ? Boolean(comments) : true);
34303459
const idified = text.toLowerCase().replace(" ", "-");
34313460
const id = `advanced-flagging-${idified}-checkbox-${this.post.id}`;
34323461
return {
@@ -3436,8 +3465,7 @@
34363465
text,
34373466
classes: ["pt1", "fs-body1"]
34383467
},
3439-
// !uncheck => whether the checkbox should be checked :)
3440-
selected: !uncheck
3468+
selected
34413469
}
34423470
};
34433471
});
@@ -3468,7 +3496,7 @@
34683496
const flagName = getFlagToRaise(reportType, this.post.qualifiesForVlq());
34693497
let reportTypeHuman = reportType === "NoFlag" || !this.post.deleted ? getHumanFromDisplayName(flagName) : "";
34703498
if (reportType !== flagName) {
3471-
reportTypeHuman += " (VLQ criteria weren't met)";
3499+
reportTypeHuman += " (VLQ criteria aren't met)";
34723500
}
34733501
const popoverParent = document.createElement("div");
34743502
Object.entries({
@@ -3847,6 +3875,7 @@
38473875
}
38483876
var isDone = false;
38493877
function Setup() {
3878+
setupConfiguration();
38503879
void Promise.all([
38513880
MetaSmokeAPI.setup(),
38523881
MetaSmokeAPI.queryMetaSmokeInternal(),
@@ -3855,7 +3884,6 @@
38553884
]).then(() => {
38563885
setupPostPage();
38573886
setupStyles();
3858-
setupConfiguration();
38593887
addXHRListener(() => {
38603888
setupPostPage();
38613889
setTimeout(setupPostPage, 55);

0 commit comments

Comments
 (0)