User:Rusalkii/hideOrHighlightInvolvedRfDs.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. |
![]() | This user script seems to have a documentation page at User:Rusalkii/hideOrHighlightInvolvedRfDs. |
/** This script highlights XfD discussions where the current user has
* participated in, or hides them. It should probably be incorporated into XFCD.
*/
(function() {
'use strict';
var debug = false;
function log(text) {
if (debug) {
console.log(text);
}
}
// Only run on supported XfD pages, and set corresponding headings
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;
}
// Get the current username
const currentUser = mw.config.get('wgUserName');
function addStyles() {
const css = `
.rfd-user-participated {
background-color: rgba(255, 255, 100, 0.15);
= }
.rfd-user-participated.rfd-hidden {
display: none;
}
#rfd-toggle {
position: fixed;
bottom: 10px;
left: 10px;
z-index: 1000;
background: rgba(248, 249, 250, 0.8);
border: 1px solid #ccc;
padding: 5px 10px;
cursor: pointer;
border-radius: 4px;
}
`;
$('<style>').text(css).appendTo('head');
}
// Add button to hide/unhide
let hideParticipated = false;
function addToggle() {
const toggle = $('<button id="rfd-toggle">Hide my discussions</button>');
$('body').append(toggle);
$('#rfd-toggle').click(function() {
hideParticipated = !hideParticipated;
$(this).text(hideParticipated ? 'Show my discussions' : 'Hide my discussions');
$('.rfd-user-participated').toggleClass('rfd-hidden', hideParticipated);
});
}
// Highlight discussions the user has participated in
function highlightDiscussions() {
// Looking at headers and content between them
let highlightedCount = 0;
const headers = $(venueHeadingLevel);
log(`Found ${headers.length} headers`);
headers.each(function(index) {
const header = $(this);
const content = header.nextUntil(venueHeadingLevel);
// Check if the user's name appears in the discussion anywhere other than relists
const userLink = '/wiki/User:' + currentUser;
log(userLink);
const contentClone = content.clone();
contentClone.find('.xfd_relist').remove();
const cloneLinks = contentClone.find('a[href*="' + userLink + '"]');
if (cloneLinks.length !== 0) {
log(`Found user participation in discussion ${index} (header: ${header.text().substring(0, 30)}...)`);
// Wrap the discussion in a div and highlight that
const wrapper = $('<div class="rfd-user-participated"></div>');
header.before(wrapper);
wrapper.append(header).append(content);
highlightedCount++;
}
});
log(`Highlighted ${highlightedCount} discussions`);
const finalHighlightCount = $('.rfd-user-participated').length;
log(`Highlighting complete. Total elements highlighted: ${finalHighlightCount}`);
}
$(document).ready(function() {
addStyles();
addToggle();
setTimeout(function() {
highlightDiscussions();
}, 200);
});
})();