<commit_before>(function() {
    var element = null;
    var nav_elements = document.querySelectorAll('.nav-item-container');

    for (var i = 0; i < nav_elements.length; i++) {
        var current = nav_elements[i];
        if (current.innerHTML == 'My Library') {
            element = current;
            break;
        }
    }

    if (element != null) {
        chrome.storage.sync.get({'gpmDefaultLibraryView': 'albums'}, function(item) {
            element.setAttribute('data-type', item.gpmDefaultLibraryView);
        });
    } else {
        console.error('No element found; did Google change the page?');
    }
})();<commit_msg>Handle dynamic insertion of page elements<commit_after>(function() {

    function findTarget(element) {
        if (element.nodeType === 1) {
            var candidates = element.querySelectorAll('.nav-item-container');
            for (var i = 0; i < candidates.length; i++) {
                if (candidates[i].textContent == 'My Library') {
                    return candidates[i];
                }
            }
        }
    }

    function modifyTarget(element) {
        chrome.storage.sync.get({'gpmDefaultLibraryView': 'albums'}, function(item) {
            element.setAttribute('data-type', item.gpmDefaultLibraryView);
        });
    }

    var observer = new MutationObserver(function(mutations, observer) {
        mutations.forEach(function(mutation) {
            for (var i = 0; i < mutation.addedNodes.length; i++) {
                var element = findTarget(mutation.addedNodes[i]);
                if (element) {
                    modifyTarget(element);
                    observer.disconnect();
                }
            }
        });
    });
    observer.observe(document.body, {
        childList: true,
        subtree: true,
        attributes: false,
        characterData: false
    });

})();
{'fraction_non_alphanumeric': 0.13148049171566006, 'fraction_numerical': 0.002137894174238375, 'mean_word_length': 1.9667194928684628, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '305770', 'n_tokens_mistral': 515, 'n_tokens_neox': 497, 'n_words': 104}