').append(
$('
').prop('checked', true),
$('
')
);
enhancementsSection.append(enhancementsTitle, removeNewsMatchesCheckbox, changeUpvoteStyleCheckbox);
modal.append(title, checkboxes, enhancementsSection, saveButton);
$('body').append(modal);
GM.getValue('selectedForums', []).then(selectedForums => {
checkboxes.find('input').each(function() {
if (selectedForums.includes($(this).val())) {
$(this).prop('checked', true);
}
});
updateCheckboxStates(checkboxes);
});
GM.getValue('removeNewsMatches', true).then(savedRemoveNewsMatches => {
$('#removeNewsMatches').prop('checked', savedRemoveNewsMatches);
applyEnhancements(savedRemoveNewsMatches);
});
GM.getValue('changeUpvoteStyle', true).then(savedChangeUpvoteStyle => {
$('#changeUpvoteStyle').prop('checked', savedChangeUpvoteStyle);
applyEnhancements(undefined, savedChangeUpvoteStyle);
});
return modal;
}
function applyEnhancements(removeNewsMatches, changeUpvoteStyle) {
if (removeNewsMatches) {
removeNewsMatchesScript();
}
if (changeUpvoteStyle) {
changeUpvoteStyleScript();
}
}
function removeNewsMatchesScript() {
(function() {
'use strict';
function cleanRecentActivity() {
const recentActivityLinks = document.querySelectorAll('.activitylist a');
recentActivityLinks.forEach(link => {
if (link.href.match(/\/matches\/|\/news\//)) {
link.style.display = 'none';
}
});
}
window.addEventListener('load', cleanRecentActivity);
const observer = new MutationObserver(cleanRecentActivity);
observer.observe(document.querySelector('.activitylist'), { childList: true, subtree: true });
})();
}
function changeUpvoteStyleScript() {
(function() {
'use strict';
let styledElements = new Set();
function changeStyles() {
let elements = document.querySelectorAll('.plus-button.active');
elements.forEach(element => {
if (!styledElements.has(element)) {
element.style.backgroundColor = 'darkgreen';
element.style.color = 'lightgreen';
element.style.fontWeight = 'bold';
styledElements.add(element);
}
});
styledElements.forEach(element => {
if (!element.classList.contains('active')) {
element.style.backgroundColor = '';
element.style.color = '';
element.style.fontWeight = '';
styledElements.delete(element);
}
});
}
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
changeStyles();
}
});
});
observer.observe(document.documentElement, {
attributes: true,
subtree: true,
attributeFilter: ['class']
});
window.addEventListener('load', changeStyles);
})();
}
function createCogwheel() {
const cogwheel = $('
').addClass('nav-cogwheel').css({
position: 'relative',
display: 'inline-block',
cursor: 'pointer',
marginLeft: '20px',
color: '#ffae00'
}).html('');
cogwheel.on('click', () => {
$('.preferences-modal').fadeIn();
});
$('#navBarContainerFull .user-wrap').append(cogwheel);
$(document).on('click', function(event) {
const modal = $('.preferences-modal');
if (!$(event.target).closest(modal).length && !$(event.target).closest(cogwheel).length) {
modal.fadeOut();
}
});
const closeButton = $('').html('×').css({
position: 'absolute',
top: '10px',
right: '15px',
fontSize: '20px',
color: '#fff',
cursor: 'pointer'
}).on('click', function() {
$('.preferences-modal').fadeOut();
});
$('.preferences-modal').prepend(closeButton);
}
async function main() {
console.log("Starting main function");
const preferencesModal = createPreferencesModal();
createCogwheel();
await waitForSidebar();
console.log("Sidebar is available, fetching posts...");
const selectedForums = await GM.getValue('selectedForums', []);
for (const forum of selectedForums) {
const { doc, url } = await fetchPosts(forum);
addPostsToSidebar(doc, url);
}
}
main();
(function() {
'use strict';
function sortForums(order) {
let forumContainer = document.querySelector('.col-box-con .activitylist');
if (!forumContainer) return;
let forums = Array.from(forumContainer.querySelectorAll('a'));
if (order === 'type') {
forums.sort((a, b) => {
let typeA = a.getAttribute('href').split('/')[1];
let typeB = b.getAttribute('href').split('/')[1];
let numA = parseInt(a.getAttribute('href').match(/\d+/)[0]);
let numB = parseInt(b.getAttribute('href').match(/\d+/)[0]);
if (typeA === typeB) {
return numB - numA;
} else {
let typeOrder = { 'news': 1, 'matches': 2, 'forums': 3 };
return typeOrder[typeA] - typeOrder[typeB];
}
});
} else {
forums.sort((a, b) => {
let commentsA = extractCommentCount(a);
let commentsB = extractCommentCount(b);
return commentsB - commentsA;
});
}
forumContainer.innerHTML = '';
forums.forEach(forum => forumContainer.appendChild(forum));
}
function extractCommentCount(element) {
let text = element.innerHTML.trim();
let match = text.match(/<\/span>(\d+)$/);
return match ? parseInt(match[1]) : 0;
}
function resetForums() {
location.reload();
}
function createToggleButton() {
let recentActivityTitle = document.querySelector('.recent-activity h1');
if (!recentActivityTitle) return;
let toggleButton = document.createElement('button');
toggleButton.style.marginRight = '10px';
toggleButton.style.border = 'none';
toggleButton.style.background = 'none';
toggleButton.style.cursor = 'pointer';
toggleButton.title = 'Sort order: Default';
let icon = document.createElement('span');
icon.innerHTML = '💬';
icon.style.color = '';
toggleButton.appendChild(icon);
let currentState = localStorage.getItem('forumSortOrder') || 'default';
updateButtonIcon(currentState, icon);
toggleButton.addEventListener('click', () => {
let newState;
if (currentState === 'default') {
newState = 'high';
} else if (currentState === 'high') {
newState = 'type';
} else {
newState = 'default';
}
currentState = newState;
localStorage.setItem('forumSortOrder', newState);
updateButtonIcon(newState, icon);
setTimeout(() => {
if (newState === 'high') {
sortForums('high');
} else if (newState === 'type') {
sortForums('type');
} else {
resetForums();
}
}, 500);
});
recentActivityTitle.insertBefore(toggleButton, recentActivityTitle.firstChild);
}
function updateButtonIcon(state, icon) {
if (state === 'high') {
icon.innerHTML = '🔽';
icon.style.color = '';
icon.title = 'Sort order: High to Low';
} else if (state === 'type') {
icon.innerHTML = '📅';
icon.style.color = '';
icon.title = 'Sort order: Creation Time (New to Old)';
} else {
icon.innerHTML = '💬';
icon.style.color = '';
icon.title = 'Sort order: Default (Posts with New Comments First)';
}
}
window.addEventListener('load', () => {
createToggleButton();
let savedOrder = localStorage.getItem('forumSortOrder');
setTimeout(() => {
if (savedOrder === 'high') {
sortForums('high');
} else if (savedOrder === 'type') {
sortForums('type');
}
}, 1000);
});
document.addEventListener('click', (event) => {
let modal = document.querySelector('.forum-preferences-modal');
let menuWrap = document.querySelector('.forum-preferences-menu-wrap');
if (modal && !modal.contains(event.target) && !menuWrap.contains(event.target)) {
modal.classList.add('hidden');
}
});
})();
})();