Destiny 2 LFG improvements

Fixes some poor design choices on the Destiny 2 LFG page and filters out spam

当前为 2022-12-22 提交的版本,查看 最新版本

// ==UserScript==
// @name         Destiny 2 LFG improvements
// @namespace    http://tampermonkey.net/
// @version      1.05
// @description  Fixes some poor design choices on the Destiny 2 LFG page and filters out spam
// @author       Richard "mindphlux" Kämmerer
// @match        https://www.bungie.net/en/ClanV2/FireteamSearch*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=bungie.net
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    var clanAdverts = /КЛАН|клан|reclut[a|o]|reclutiamo|recrute|recherche|recruiting/;
    var spamStrings = /help-d2.com|mycarry.net|d2-sherpa.com|d2xur.com|game-job.ru|skygold.gg/;
    var defaultTitle = /(.*)\/\/(.*)/;

    // remove bungie advert

    document.querySelector('.promo').remove();

    var platformSelect = document.querySelector('select[name=platform]');
    var activitySelect = document.querySelector('select[name=activityType]');
    var languageSelect = document.querySelector('select[name=lang]');

    // to prevent the browser from entering an endless loop of page reloads we're using a hash to see if we already reloaded

    function ReloadPage(page) {
        if(window.location.hash == page || window.location.hash == null) return;
        location.href = "https://www.bungie.net/en/ClanV2/FireteamSearch?platform=" +
            platformSelect[platformSelect.selectedIndex].value +
            "&activityType=" +
            activitySelect[activitySelect.selectedIndex].value +
            "&lang=" + languageSelect[languageSelect.selectedIndex].value +
            "#" +
            page;
    }

    // reroute dropdowns to our own function so the userscript still works after using the select boxes

    platformSelect.onchange = (e) => {
        e.preventDefault();
        e.stopPropagation();
        ReloadPage("platform");
    }

    activitySelect.onchange = (e) => {
        e.preventDefault();
        e.stopPropagation();
        ReloadPage("activity");
    }

    languageSelect.onchange = (e) => {
        e.preventDefault();
        e.stopPropagation();
        ReloadPage("language");
    }

    // add textual description of the activity to the post title
    // so people who can't remember dozens of icons can actually understand what's going on

    function TranslateIcons() {

        var activitySelect = {
            0: "Anything",
            2: "Crucible",
            3: "Trials of Osiris",
            4: "Nightfall",
            5: "Anything",
            6: "Gambit",
            7: "Blind Well",
            12: "Nightmare Hunt",
            14: "Altar of Sorrow",
            20: "Raid: Last Wish",
            21: "Raid: Garden of Salvation",
            22: "Dungeon: Deep Stone Crypt",
            23: "Exo Challenge",
            25: "Empire Hunt",
            27: "Exotic Quest",
            28: "Raid: Vault of Glass",
            33: "Dungeon: Shattered Throne",
            34: "Dungeon: Prophecy",
            35: "Dungeon: Pit of Heresy",
            36: "Dares of Eternity",
            37: "Dungeon: Grasp of Avarice",
            38: "Raid: Vow of the Disciple",
            39: "Campaign",
            40: "The Wellspring",
            41: "S16: Battlegrounds",
            43: "Dungeon: Duality",
            44: "S17: Nightmare Containment",
            45: "S17: Sever",
            47: "S18: Ketchcrash",
            48: "S18: Expedition",
            49: "S18: Pirate Hideout",
            50: "Raid: King's Fall",
            51: "Battlegrounds",
            52: "Dungeon: Spire of the Watcher",
            53: "S19: Operations",
        };

        var lis = document.getElementById('clansList').querySelectorAll('li');
        lis.forEach((item, index) => {
            var activityId = item.querySelector('.activity-icon').getAttribute('data-activity');
            var title = item.querySelector('.title');

            // removes the post if it's spam or a clan ad
            if(spamStrings.test(title.innerHTML.toLowerCase()) || clanAdverts.test(title.innerHTML.toLowerCase())) {
                item.remove();
                return;
            }

            // remove the original post title if it was left blank (which is then replaced by Bungie with the same info we already added)
            var newTitle = (activitySelect[activityId] != null ? activitySelect[activityId] : "N/A");
            if(!defaultTitle.test(title.innerHTML)) {
                newTitle += " | " + title.innerHTML;
            }
            title.innerHTML = newTitle;
        });
    }

    TranslateIcons();

})();