User:Rusalkii/hideRelisted.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Rusalkii/hideRelisted. |
// <nowiki>
// This should be incorporated in XFDC
(function() {
let hidden = true; // Default to hidden
var debug = true;
function log(text) {
if (debug) {
console.log(text);
}
}
// Check if on XfD page
var venueHeadingLevel;
if (mw.config.get('wgPageName').match(/Wikipedia:Redirects_for_discussion/) ||
mw.config.get('wgPageName').match(/Wikipedia:Files_for_discussion/) ||
mw.config.get('wgPageName').match(/Wikipedia:Miscellany_for_deletion/) ||
mw.config.get('wgPageName').match(/Wikipedia:Templates_for_discussion/)) {
venueHeadingLevel = '.mw-heading.mw-heading4';
} else if (mw.config.get('wgPageName').match(/Wikipedia:Articles_for_deletion/) ||
mw.config.get('wgPageName').match(/Wikipedia:Categories_for_discussion/) ||
mw.config.get('wgPageName').match(/Commons:Deletion_requests/)) {
venueHeadingLevel = '.mw-heading.mw-heading3';
} else {
log('Not a deletion venue');
return; // Exit if not on XfD page
}
const button = document.createElement('button');
button.textContent = 'Show Relisted';
button.style.cssText = 'position:fixed;bottom:40px;left:10px;z-index:100;padding:5px 10px;background:rgba(248, 249, 250, 0.8);border: 1px solid #ccc;border-radius:4px;cursor:pointer;'
function addStyles() {
const css = `
.rfd-relisted {
}
.rfd-relisted.rfd-hidden {
display: none;
}
`;
$('<style>').text(css).appendTo('head');
}
function hideRelists() {
const $ = jQuery;
let relistedCount = 0;
const headers = $(venueHeadingLevel);
log(`Found ${headers.length} headers`);
headers.each(function(index) {
const header = $(this);
const content = header.nextUntil(venueHeadingLevel);
// Check if the relist symbol and text
const contentClone = content.clone();
const moveSymbol = contentClone.find('img[src*="Symbol_move_vote.svg"]');
if (moveSymbol.length !== 0) {
log(`Found relist at ${index} (header: ${header.text().substring(0, 30)}...)`);
// Add classes directly instead of wrapping
header.addClass('rfd-relisted');
content.addClass('rfd-relisted');
// Toggle visibility
if (hidden) {
header.addClass('rfd-hidden');
content.addClass('rfd-hidden');
} else {
header.removeClass('rfd-hidden');
content.removeClass('rfd-hidden');
}
relistedCount++;
}
});
log(`Processed ${relistedCount} relists`);
}
$(document).ready(function() {
addStyles();
hideRelists();
document.querySelector('#mw-content-text').prepend(button);
});
button.onclick = () => {
hidden = !hidden;
hideRelists();
button.textContent = hidden ? 'Show Relisted' : 'Hide Relisted';
};
})();
//</nowiki>