<commit_before>/* global Prism */
(function () {
    'use strict';

    const sourceHandler = require('../src/source-handler');

    const refinedBitbucket = {

        init() {
            this.INTERVAL = 50; // Interval in milliseconds.
            this.insertStyles();
            Promise.all([this.classifyDiffContainers(), this.transformPreElements()]).then(() => {
                Prism.highlightAll();
            });
        },

        insertStyles() {
            let head = document.getElementsByTagName('head')[0];
            let lastHeadElement = head.lastChild;
            let style = document.createElement('style');
            const styleArray = [];
            style.type = 'text/css';
            // Prism css
            styleArray.push('.token.comment,.token.prolog,.token.doctype,.token.cdata{color: slategray}.token.punctuation{color: #999}.namespace{opacity: .7}.token.property,.token.tag,.token.boolean,.token.number,.token.constant,.token.symbol,.token.deleted{color: #905}.token.selector,.token.attr-name,.token.string,.token.char,.token.builtin,.token.inserted{color: #690}.token.operator,.token.entity,.token.url,.language-css .token.string,.style .token.string{color: #a67f59;background: hsla(0, 0%, 100%, .5)}.token.atrule,.token.attr-value,.token.keyword{color: #07a}.token.function{color: #DD4A68}.token.regex,.token.important,.token.variable{color: #e90}.token.important,.token.bold{font-weight: bold}.token.italic{font-style: italic}.token.entity{cursor: help}');
            // Custom css to fix some layout problems because of the insertion of <code> element
            styleArray.push('pre>code{border-radius:initial;display:initial;line-height:initial;margin-left:initial;overflow-y:initial;padding:initial}code,tt{background:initial;border:initial}.refract-container .deletion pre.source {background-color: #fff1f2 !important;} .refract-container .addition pre.source { background-color: #e8ffe8;}');
            style.innerHTML = styleArray.join('');
            head.insertBefore(style, lastHeadElement);
            head = null;
            lastHeadElement = null;
            style = null;
        },

        /**
         * Waits some intervals until a specific element is displayed.
         * @return {Promise} Returns a promise that is fulfilled when it finds a specific element.
         */
        waitForRender(selector) {
            return new Promise(resolve => {
                const intervalId = setInterval(() => {
                    const element = document.querySelector(selector);
                    if (!element) {
                        return;
                    }

                    // If element is rendered, stop the interval and continue.
                    clearInterval(intervalId);
                    resolve();
                }, this.INTERVAL);
            });
        },

        classifyDiffContainers() {
            return this.waitForRender('.diff-container').then(() => {
                const containers = Array.from(document.querySelectorAll('.diff-container'));

                containers.forEach(container => {
                    const classifiedParent = sourceHandler.classify(container.parentNode);
                    container.setAttribute('class', classifiedParent.getAttribute('class'));
                });

                return Promise.resolve();
            });
        },

        transformPreElements() {
            return this.waitForRender('.source').then(() => {
                const sourceLines = Array.from(document.querySelectorAll('.source'));

                sourceLines.forEach(line => {
                    const transformedLine = sourceHandler.transformPreElement(line);
                    line.innerHTML = transformedLine.innerHTML;<commit_msg>Extracts Promise.all call to a separate method to reuse it for the listeners<commit_after>/* global Prism */
(function () {
    'use strict';

    const sourceHandler = require('../src/source-handler');

    const refinedBitbucket = {

        init() {
            this.INTERVAL = 50; // Interval in milliseconds.
            this.insertStyles();
            this.highlightAll();
        },

        insertStyles() {
            let head = document.getElementsByTagName('head')[0];
            let lastHeadElement = head.lastChild;
            let style = document.createElement('style');
            const styleArray = [];
            style.type = 'text/css';
            // Prism css
            styleArray.push('.token.comment,.token.prolog,.token.doctype,.token.cdata{color: slategray}.token.punctuation{color: #999}.namespace{opacity: .7}.token.property,.token.tag,.token.boolean,.token.number,.token.constant,.token.symbol,.token.deleted{color: #905}.token.selector,.token.attr-name,.token.string,.token.char,.token.builtin,.token.inserted{color: #690}.token.operator,.token.entity,.token.url,.language-css .token.string,.style .token.string{color: #a67f59;background: hsla(0, 0%, 100%, .5)}.token.atrule,.token.attr-value,.token.keyword{color: #07a}.token.function{color: #DD4A68}.token.regex,.token.important,.token.variable{color: #e90}.token.important,.token.bold{font-weight: bold}.token.italic{font-style: italic}.token.entity{cursor: help}');
            // Custom css to fix some layout problems because of the insertion of <code> element
            styleArray.push('pre>code{border-radius:initial;display:initial;line-height:initial;margin-left:initial;overflow-y:initial;padding:initial}code,tt{background:initial;border:initial}.refract-container .deletion pre.source {background-color: #fff1f2 !important;} .refract-container .addition pre.source { background-color: #e8ffe8;}');
            style.innerHTML = styleArray.join('');
            head.insertBefore(style, lastHeadElement);
            head = null;
            lastHeadElement = null;
            style = null;
        },

        highlightAll() {
            Promise.all([this.classifyDiffContainers(), this.transformPreElements()]).then(() => {
                Prism.highlightAll();
            });
        },

        classifyDiffContainers() {
            return this.waitForRender('.diff-container').then(() => {
                const containers = Array.from(document.querySelectorAll('.diff-container'));

                containers.forEach(container => {
                    const classifiedParent = sourceHandler.classify(container.parentNode);
                    container.setAttribute('class', classifiedParent.getAttribute('class'));
                });

                return Promise.resolve();
            });
        },

        /**
         * Waits some intervals until a specific element is displayed.
         * @return {Promise} Returns a promise that is fulfilled when it finds a specific element.
         */
        waitForRender(selector) {
            return new Promise(resolve => {
                const intervalId = setInterval(() => {
                    const element = document.querySelector(selector);
                    if (!element) {
                        return;
                    }

                    // If element is rendered, stop the interval and continue.
                    clearInterval(intervalId);
                    resolve();
                }, this.INTERVAL);
            });
        },

        transformPreElements() {
            return this.waitForRender('.source').then(() => {
                const sourceLines = Array.from(document.querySelectorAll('.source'));

                sourceLines.forEach(line => {
                    const transformedLine = sourceHandler.transformPreElement(line);
                    line.innerHTML = transformedLine.innerHTML;
{'fraction_non_alphanumeric': 0.13140398904966757, 'fraction_numerical': 0.008864554816842654, 'mean_word_length': 2.24809483488569, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '1112918', 'n_tokens_mistral': 1973, 'n_tokens_neox': 1873, 'n_words': 343}