Douban Username Alias Modifier

Modify Douban usernames in-script CSV format data. Limitations: (1) Only works on PC Douban (https://www.douban.com), and (2) Supports in-script CSV format data only, as Tampermonkey cannot access local files due to security restrictions.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

// ==UserScript==
// @name         Douban Username Alias Modifier
// @namespace    http://tampermonkey.net/
// @version      1.0
// @author       momobitesthedust
// @match        https://www.douban.com/*
// @description  Modify Douban usernames in-script CSV format data. Limitations: (1) Only works on PC Douban (https://www.douban.com), and (2) Supports in-script CSV format data only, as Tampermonkey cannot access local files due to security restrictions.
// @license      MIT
// ==/UserScript==


(function() {
    'use strict';

    const userCsvData = `
user_id,alias
123,abc
// Add more user ids and aliases as needed
`;

    const userAliasMap = parseCSV(userCsvData);
    modifyUsernameAlias(userAliasMap);

    function parseCSV(data) {
        const lines = data.trim().split('\n');
        const result = {};
        lines.slice(1).forEach(line => {
            const [user_id, alias] = line.split(',');
            if (user_id && alias) {
                result[user_id.trim()] = alias.trim();
            }
        });
        return result;
    }

    function modifyUsernameAlias(userAliasMap) {
        const anchors = document.querySelectorAll('a[href*="https://www.douban.com/people/"]');
        anchors.forEach(anchor => {
            if (anchor.querySelector('img')) {
                return;
            }
            const userIdMatch = anchor.href.match(/people\/([^\/]+)\//);
            if (userIdMatch && userAliasMap[userIdMatch[1]]) {
                const alias = userAliasMap[userIdMatch[1]];
                anchor.textContent = `${anchor.textContent} [${alias}]`;
            }
        });
    }

})();