PageSourceSearch

https://hfc.dk/wp-content/plugins/rank-ai-by-morningscore/assets/js/rank-alt-tags.js?ver=1.0.0

js hfc.dk collected 2026-10-02 21:44:07 UTC 2,725 bytes, 72 lines download raw bytes

1/**
2 * Rank Alt Tags - Client-side processing for image alt tags
3 * This script runs after the page has loaded to minimize performance impact
4 */
5document.addEventListener('DOMContentLoaded', function() {
6    // Wait for the page to be fully loaded and rendered
7    // This ensures we don't impact critical rendering path
8    window.addEventListener('load', function() {
9        // Further delay processing to ensure it doesn't compete with critical resources
10        setTimeout(processAltTags, 200);
11    });
12    
13    function processAltTags() {
14        // Get all images without alt text or with empty alt
15        const images = document.querySelectorAll('img:not([alt]), img[alt=""]');
16        
17        // If no images need processing, exit early
18        if (images.length === 0) {
19            return;
20        }
21        
22        // Collect all image URLs that need alt tags
23        const imageUrls = [];
24        const imageMap = {}; // Map to track which elements correspond to which URLs
25        
26        images.forEach(function(img) {
27            const src = img.getAttribute('src');
28            if (src) {
29                imageUrls.push(src);
30                
31                // Store reference to this element for this URL
32                // (handles case where multiple img elements use same URL)
33                if (!imageMap[src]) {
34                    imageMap[src] = [];
35                }
36                imageMap[src].push(img);
37            }
38        });
39        
40        // Make a single AJAX request with all image URLs and the post ID
41        fetch(rankAltTags.ajaxUrl, {
42            method: 'POST',
43            headers: {
44                'Content-Type': 'application/x-www-form-urlencoded',
45            },
46            body: 'action=get_bulk_alt_tags&urls=' + encodeURIComponent(JSON.stringify(imageUrls)) +
47                  '&post_id=' + rankAltTags.postId
48        })
49        .then(response => response.json())
50        .then(data => {
51            if (data.success) {
52                let appliedCount = 0;
53                
54                // Apply alt tags to all matching images
55                Object.keys(data.alt_tags || {}).forEach(url => {
56                    const altText = data.alt_tags[url];
57                    
58                    if (altText && imageMap[url]) {
59                        // Apply to all elements with this URL
60                        imageMap[url].forEach(img => {
61                            img.setAttribute('alt', altText);
62                            appliedCount++;
63                        });
64                    }
65                });
66            }
67        })
68        .catch(error => {
69            console.error('Rank Alt Tags: Error in fetch:', error);
70        });
71    }
72});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.