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 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 Stack Overflow",
miken32 marked this conversation as resolved.
Show resolved Hide resolved
"extended_description": "This page is accessible to users who have earned 10 000 reputation on Stack Overflow",
miken32 marked this conversation as resolved.
Show resolved Hide resolved
"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: 22 additions & 2 deletions 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,26 @@
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could replace this with sox.helpers.addAjaxListener like this:

      // tables are populated by XHR after page loads
      sox.helpers.addAjaxListener("\\/tools\\?tab=", () => {
        document.querySelectorAll("table.summary-table").forEach(trimLists);
      });
      // just in case we come in after a table has been loaded already
      document.querySelectorAll("table.summary-table").forEach(trimLists);

we found that the advantage of doing it this way is we stop adding so many mutation observers to the page, which seemed to have negative performance effects when there were too many.

This method instead just triggers your function whenever an xhr response from the given URL is received, after which we can query for the table once

// 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);