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

Tools page customization #508

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
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
24 changes: 24 additions & 0 deletions sox.features.info.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,30 @@
"meta": "",
"match": "*://*/questions/*",
"exclude": "*://*/questions/ask,*://*/questions/tagged*,*://*/questions/greatest-hits*"
}, {
"name": "customizeToolsPageLists",
"desc": "Customize the appearance of the /tools page on all sites",
"extended_description": "This feature will allow you to filter what posts are shown on the /tools page, which is accessible to all users with >10k reputation on a site.",
"meta": "",
"match": "https://*/tools",
"exclude": "",
"settings": [{
"id": "listCount",
"type": "text",
"desc": "Number of items to show in delete/undelete vote lists"
}, {
"id": "filterInvalid",
"type": "checkbox",
"desc": "Exclude items you are unable to vote on from delete/undelete lists"
}, {
"id": "filterTypeQuestions",
"type": "checkbox",
"desc": "Exclude questions from delete/undelete lists"
}, {
"id": "filterTypeAnswers",
"type": "checkbox",
"desc": "Exclude answers from delete/undelete lists"
}]
}],
"Comments": [{
"name": "autoShowCommentImages",
Expand Down
24 changes: 23 additions & 1 deletion sox.features.js
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@
// Description: Hides the Community Bulletin module from the sidebar

const element = document.querySelector('#sidebar .s-sidebarwidget');
if (element.innerText.contains('The Overflow Blog')) element.remove();
if (element?.innerText.contains('The Overflow Blog')) element.remove();
},

hideJustHotMetaPosts: function() {
Expand Down Expand Up @@ -2620,6 +2620,28 @@
const answers = document.querySelector("#answers-header h2").innerText.split(' ')[0];
const toInsert = '<div class="grid--cell ws-nowrap mb8 ml16"><span class="fc-light mr4">Answers</span> ' + answers + '</div>';
document.querySelector(".d-flex.fw-wrap").insertAdjacentHTML("beforeEnd", toInsert);
},

customizeToolsPageLists: function(settings) {
const trimLists = function(table) {
if (settings.filterInvalid) {
table.querySelectorAll("td.tagged-ignored").forEach(cell => cell.parentNode.remove());
}
if (settings.filterTypeQuestions) {
table.querySelectorAll("a.question-hyperlink").forEach(cell => cell.parentNode.parentNode.remove());
}
if (settings.filterTypeAnswers) {
table.querySelectorAll("a.answer-hyperlink").forEach(cell => cell.parentNode.parentNode.remove());
}
const listCount = settings.listCount || 3;
const rows = table.querySelectorAll("tr");
rows.forEach((row, i) => row.classList.toggle("collapsing", i >= listCount));
};
// tables are populated by XHR after page loads

sox.helpers.observe(Array.from(document.querySelectorAll("div.island")), "table.summary-table", trimLists);
// just in case we come in after a table has been loaded already
document.querySelectorAll("table.summary-table").forEach(table => trimLists(table));
}
};
miken32 marked this conversation as resolved.
Show resolved Hide resolved
})(window.sox = window.sox || {}, jQuery);