Moby Credits Textifier 2024

extract credits from mobygames - I'm using a temporary email for this greasyfork so don't expect updates <3

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Moby Credits Textifier 2024
// @namespace    http://tampermonkey.net/
// @version      0.2
// @copyright    https://en.wikipedia.org/wiki/WTFPL
// @license      WTFPL
// @description  extract credits from mobygames - I'm using a temporary email for this greasyfork so don't expect updates <3
// @author       Curious, aren't we?
// @match        https://www.mobygames.com/game/*/*/credits/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=mobygames.com
// @require      https://code.jquery.com/jquery-3.7.1.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...

    function waitForElm(selector) {
    return new Promise(resolve => {
        if (document.querySelector(selector)) {
            return resolve(document.querySelector(selector));
        }

        const observer = new MutationObserver(mutations => {
            if (document.querySelector(selector)) {
                observer.disconnect();
                resolve(document.querySelector(selector));
            }
        });

        // If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    });
}

    waitForElm('main#main').then((elm) => {
        var $ = window.jQuery;
        $('h1').after('<textarea style="background-color: LemonChiffon;" id="mobyex-txt"></textarea><button id="mobyex-btn">allText</button>');
        $('#mobyex-btn').click(function(){
            var txtCredits = '';
            $('table.table-credits > tbody > tr').each(function(){
                $(this).find('th h4').each(function(){
                    txtCredits += '\n\n' + $(this).text();
                });
                if ( $(this).find('td').length ) {
                    $(this).find('td:nth-child(1)').each(function(){
                        txtCredits += '\n\n' + $(this).text();
                    });
                    //$(this).find('td:nth-child(2) ul li').each(function(){ // not since 2024-03-14 or so
                    $(this).find('td:nth-child(2)').text().split(', ').forEach(function(item, index){
                        //txtCredits += '\n' + $(this).text();
                        txtCredits += '\n' + item;
                    });
                }
            });
            $('#mobyex-txt').text(txtCredits.trim());
        });
    });
})();