Greasy Fork is available in English.
Filter out tier-restricted content on Alienware Arena
当前为
// ==UserScript==
// @name Alienware Arena Filters
// @namespace http://updownleftdie.com/
// @version 1.0
// @description Filter out tier-restricted content on Alienware Arena
// @author UpDownLeftDie
// @match https://*.alienwarearena.com/*
// @grant GM_setValue
// @grant GM_getValue
// @license AGPL
// ==/UserScript==
(function() {
'use strict';
// Settings management
const defaultSettings = {
hideClosedGiveaways: true,
hideTierRestricted: true,
hideOutOfStock: true
};
function getSettings() {
const savedSettings = GM_getValue('filterSettings');
return savedSettings ? JSON.parse(savedSettings) : defaultSettings;
}
function saveSettings(settings) {
GM_setValue('filterSettings', JSON.stringify(settings));
}
// Function to extract tier number from text
function extractTier(text) {
const match = text.match(/Tier\s*(\d+)/i);
return match ? parseInt(match[1]) : null;
}
// Function to check and store user's tier on control center page
function checkAndStoreTier() {
const tierImg = document.querySelector('img[src*="/images/content/tier-tags/"]');
if (tierImg) {
const tierMatch = tierImg.src.match(/tier-tags\/(\d+)\.png/);
if (tierMatch) {
const userTier = parseInt(tierMatch[1]);
GM_setValue('userTier', userTier);
console.log('Stored user tier:', userTier);
}
}
}
// Function to filter community giveaways
function filterGiveaways() {
const settings = getSettings();
const userTier = GM_getValue('userTier', 99);
const giveaways = document.querySelectorAll('div.mb-3.community-giveaways__listing__row');
giveaways.forEach(giveaway => {
const text = giveaway.textContent;
if (settings.hideClosedGiveaways && text.includes('Closed')) {
giveaway.style.display = 'none';
return;
}
if (settings.hideTierRestricted) {
const tierNumber = extractTier(text);
if (tierNumber && tierNumber > userTier) {
giveaway.style.display = 'none';
}
}
});
}
// Function to filter marketplace items
function filterMarketplace() {
const settings = getSettings();
const userTier = GM_getValue('userTier', 99);
const items = document.querySelectorAll('.pointer.marketplace-game-small, .pointer.marketplace-game-large');
items.forEach(item => {
const text = item.textContent;
if (settings.hideOutOfStock && text.toLowerCase().includes('out of stock')) {
item.style.display = 'none';
return;
}
if (settings.hideTierRestricted) {
const tierNumber = extractTier(text);
if (tierNumber && tierNumber > userTier) {
item.style.display = 'none';
}
}
});
}
// Function to create settings menu
function createSettingsMenu() {
const settings = getSettings();
const menuHTML = `
<div id="alienware-filter-settings" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
background: #1a1a1a; padding: 20px; border-radius: 8px; z-index: 10000; min-width: 300px; box-shadow: 0 0 10px rgba(0,0,0,0.5);">
<h3 style="color: #fff; margin-bottom: 15px;">Filter Settings</h3>
<div style="margin-bottom: 10px;">
<label style="color: #fff; display: block; margin-bottom: 5px;">
<input type="checkbox" id="hideClosedGiveaways" ${settings.hideClosedGiveaways ? 'checked' : ''}>
Hide Closed Giveaways
</label>
</div>
<div style="margin-bottom: 10px;">
<label style="color: #fff; display: block; margin-bottom: 5px;">
<input type="checkbox" id="hideTierRestricted" ${settings.hideTierRestricted ? 'checked' : ''}>
Hide Higher Tier Content
</label>
</div>
<div style="margin-bottom: 15px;">
<label style="color: #fff; display: block; margin-bottom: 5px;">
<input type="checkbox" id="hideOutOfStock" ${settings.hideOutOfStock ? 'checked' : ''}>
Hide Out of Stock Items
</label>
</div>
<div style="text-align: right;">
<button id="saveFilterSettings" style="background: #00bc8c; color: #fff; border: none; padding: 5px 15px; border-radius: 4px; cursor: pointer;">
Save
</button>
<button id="closeFilterSettings" style="background: #e74c3c; color: #fff; border: none; padding: 5px 15px; border-radius: 4px; margin-left: 10px; cursor: pointer;">
Close
</button>
</div>
</div>
`;
// Add menu to page
document.body.insertAdjacentHTML('beforeend', menuHTML);
// Add event listeners
document.getElementById('saveFilterSettings').addEventListener('click', () => {
const newSettings = {
hideClosedGiveaways: document.getElementById('hideClosedGiveaways').checked,
hideTierRestricted: document.getElementById('hideTierRestricted').checked,
hideOutOfStock: document.getElementById('hideOutOfStock').checked
};
saveSettings(newSettings);
document.getElementById('alienware-filter-settings').style.display = 'none';
location.reload(); // Reload to apply new settings
});
document.getElementById('closeFilterSettings').addEventListener('click', () => {
document.getElementById('alienware-filter-settings').style.display = 'none';
});
}
// Function to add settings button to menu
function addSettingsButton() {
const menuList = document.querySelector('.nav-item-mus .dropdown-menu.dropdown-menu-end');
if (menuList) {
const settingsItem = document.createElement('a');
settingsItem.className = 'dropdown-item';
settingsItem.href = '#';
settingsItem.textContent = 'Filter Settings';
settingsItem.addEventListener('click', (e) => {
e.preventDefault();
document.getElementById('alienware-filter-settings').style.display = 'block';
});
menuList.insertBefore(settingsItem, menuList.lastElementChild);
}
}
// Initialize everything based on current page
const currentPath = window.location.pathname;
// Add settings menu to all pages
createSettingsMenu();
addSettingsButton();
if (currentPath === '/control-center') {
checkAndStoreTier();
} else if (currentPath === '/community-giveaways') {
// Add mutation observer for dynamic content loading
const observer = new MutationObserver((mutations, obs) => {
filterGiveaways();
});
observer.observe(document.body, {
childList: true,
subtree: true
});
} else if (currentPath === '/marketplace/game-vault') {
// Add mutation observer for dynamic content loading
const observer = new MutationObserver((mutations, obs) => {
filterMarketplace();
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
})();