User:Monster Domosed/common.js: Difference between revisions

Jump to navigation Jump to search
No edit summary
No edit summary
Line 160: Line 160:
             return char.toUpperCase();
             return char.toUpperCase();
         } );
         } );
    }
    /* ─── Extract templatestyles tags from HTML ─── */
    function extractTemplateStyles( html ) {
        var regex = /<link[^>]+href="[^"]*\/load\.php\?[^"]*modules=ext\.templateStyles[^"]*"[^>]*>/gi;
        var stylesheets = [];
        var match;
       
        // Try to find templatestyles link tags
        while ( ( match = regex.exec( html ) ) !== null ) {
            stylesheets.push( match[0] );
        }
       
        return stylesheets;
     }
     }


Line 224: Line 210:
             }
             }


             // Load the template styles first
             // Function to fetch and display the template
            var stylesheetToLoad = type === 'item' ? 'Template:Infobox item/styles.css' : 'Template:Ability card v2/styles.css';
             function fetchAndShowTemplate() {
           
             loadTemplateStyles( stylesheetToLoad, function () {
                // Now fetch the rendered template
                 new mw.Api().post( {
                 new mw.Api().post( {
                     action: 'parse',
                     action: 'parse',
Line 259: Line 242:
                     }
                     }
                 } );
                 } );
             } );
             }
 
            // Load template styles only for items (abilities use inline styles)
            if ( type === 'item' ) {
                loadTemplateStyles( 'Template:Infobox item/styles.css', fetchAndShowTemplate );
            } else {
                // For abilities, just fetch and show directly
                fetchAndShowTemplate();
            }


         }, SHOW_DELAY );
         }, SHOW_DELAY );