<commit_before>$(document).ready(function () {
    
    /* TODO: make this a jQuery plugin */

    window.loadAstroBinImages = function (fragment) {
        var tries = {};

        $(fragment).find('img.astrobin-image').each(function (index) {
            var $img = $(this),
                random_timeout = Math.floor(Math.random() * 100) + 100, // 100-200 ms
                id = $img.data('id'),
                revision = $img.data('revision'),
                alias = $img.data('alias'),
                url = $img.data('get-thumb-url'),
                enhanced_thumbnail_url = $img.data('enhanced-thumb-url'),
                get_enhanced_thumbnail_url = $img.data('get-enhanced-thumb-url'),
                loaded = $img.data('loaded'),
            key = getKey(id, revision, alias);
            if (!loaded) {
                setTimeout(function () {
                    load(url, id, revision, alias, tries, false);
                }, random_timeout);
            } else if (enhanced_thumbnail_url || get_enhanced_thumbnail_url) {
                loadHighDPI($img);
            }
        });
    };

    function getKey(id, revision, alias) {
        return id + '.' + revision + '.' + alias;
    }

    function loadHighDPI($img) {
        var tries = {},
            devicePixelRatio = window.devicePixelRatio,
            random_timeout = Math.floor(Math.random() * 100) + 100, // 100-200 ms
            id = $img.data('id'),
            revision = $img.data('revision'),
            alias = $img.data('alias'),
            url = $img.data('get-thumb-url'),
            enhanced_thumbnail_url = $img.data('enhanced-thumb-url'),
            get_enhanced_thumbnail_url = $img.data('get-enhanced-thumb-url'),
            key = getKey(id, revision, alias);
    
        if (devicePixelRatio > 1) {
            if (enhanced_thumbnail_url !== undefined) {
                $img.attr('data-hires-loaded', true);
                $img.attr('src', enhanced_thumbnail_url);
            } else if (!(get_enhanced_thumbnail_url === undefined)) {
                url = get_enhanced_thumbnail_url;
                $img.attr('data-hires-loaded', false);
                setTimeout(function () {
                    load(get_enhanced_thumbnail_url, id, revision, alias, tries, true);
                }, random_timeout);
            }
        }
    }

    function load(url, id, revision, alias, tries, hires) {       
        if (url !== "") {
            key = getKey(id, revision, alias);
            if (tries[key] === undefined) {
                tries[key] = 0;
            }
            if (tries[key] >= 10) {
                img
                    .attr(
                        'src',
                        'https://placehold.jp/222/e0e0e0/' + img.width() + 'x' + img.height() +
                        '.png?text=%E2%8F%B3')
                    .attr('data-loaded', 'true');
                return;
            }
    
            $.ajax({
                dataType: 'json',
                cache: true,
                context: [id, revision, alias, hires, tries],
                url: url,
                timeout: 60000,
                success: function (data, status, request) {
                    var id = this[0],
                        revision = this[1],
                        alias = this[2],
                        hires = this[3],
                        tries = this[4],
                        key = getKey(id, revision, alias);
                    tries[key] += 1;
                    if (data.url === undefined || data.url === null || data.url.indexOf("placeholder") > -1) {
                        setTimeout(function () {
                            load();
                        }, random_timeout * Math.pow(2, tries[key]));<commit_msg>(images) Fix image loading bug when placeholder is present (#908)<commit_after>$(document).ready(function () {
    
    /* TODO: make this a jQuery plugin */

    window.loadAstroBinImages = function (fragment) {
        var tries = {};

        $(fragment).find('img.astrobin-image').each(function (index) {
            var $img = $(this),
                random_timeout = Math.floor(Math.random() * 100) + 100, // 100-200 ms
                id = $img.data('id'),
                revision = $img.data('revision'),
                alias = $img.data('alias'),
                url = $img.data('get-thumb-url'),
                enhanced_thumbnail_url = $img.data('enhanced-thumb-url'),
                get_enhanced_thumbnail_url = $img.data('get-enhanced-thumb-url'),
                loaded = $img.data('loaded'),
            key = getKey(id, revision, alias);
            if (!loaded) {
                setTimeout(function () {
                    load(url, id, revision, alias, tries, false, random_timeout);
                }, random_timeout);
            } else if (enhanced_thumbnail_url || get_enhanced_thumbnail_url) {
                loadHighDPI($img);
            }
        });
    };

    function getKey(id, revision, alias) {
        return id + '.' + revision + '.' + alias;
    }

    function loadHighDPI($img) {
        var tries = {},
            devicePixelRatio = window.devicePixelRatio,
            random_timeout = Math.floor(Math.random() * 100) + 100, // 100-200 ms
            id = $img.data('id'),
            revision = $img.data('revision'),
            alias = $img.data('alias'),
            url = $img.data('get-thumb-url'),
            enhanced_thumbnail_url = $img.data('enhanced-thumb-url'),
            get_enhanced_thumbnail_url = $img.data('get-enhanced-thumb-url'),
            key = getKey(id, revision, alias);
    
        if (devicePixelRatio > 1) {
            if (enhanced_thumbnail_url !== undefined) {
                $img.attr('data-hires-loaded', true);
                $img.attr('src', enhanced_thumbnail_url);
            } else if (get_enhanced_thumbnail_url !== undefined) {
                url = get_enhanced_thumbnail_url;
                $img.attr('data-hires-loaded', false);
                setTimeout(function () {
                    load(get_enhanced_thumbnail_url, id, revision, alias, tries, true, random_timeout);
                }, random_timeout);
            }
        }
    }

    function load(url, id, revision, alias, tries, hires, random_timeout) {       
        if (url !== "") {
            key = getKey(id, revision, alias);
            if (tries[key] === undefined) {
                tries[key] = 0;
            }
            if (tries[key] >= 10) {
                img
                    .attr(
                        'src',
                        'https://placehold.jp/222/e0e0e0/' + img.width() + 'x' + img.height() +
                        '.png?text=%E2%8F%B3')
                    .attr('data-loaded', 'true');
                return;
            }
    
            $.ajax({
                dataType: 'json',
                cache: true,
                context: [url, id, revision, alias, hires, tries, random_timeout],
                url: url,
                timeout: 60000,
                success: function (data, status, request) {
                    var url = this[0],
                        id = this[1],
                        revision = this[2],
                        alias = this[3],
                        hires = this[4],
                        tries = this[5],
                        random_timeout = this[6],
                        key = getKey(id, revision, alias);
                    tries[key] += 1;
                    if (data.url === undefined || data.url === null || data.url.indexOf("placeholder") > -1) {
                        setTimeout(function () {
                            load(url, id, revision, alias, tries, hires, random_timeout);
                        }, random_timeout * Math.pow(2, tries[key]));
{'fraction_non_alphanumeric': 0.13703371362645814, 'fraction_numerical': 0.013459812844507115, 'mean_word_length': 1.3852033017425864, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2145953', 'n_tokens_mistral': 2239, 'n_tokens_neox': 2060, 'n_words': 421}