<commit_before>// ==UserScript==
// @name         MusicBrainz: Show discid count
// @author       loujine
// @version      2015.10.10
// @downloadURL  https://bitbucket.org/loujine/musicbrainz-scripts/raw/default/mbz-showcountdiscid.user.js
// @updateURL    https://bitbucket.org/loujine/musicbrainz-scripts/raw/default/mbz-showcountdiscid.user.js
// @supportURL   https://bitbucket.org/loujine/musicbrainz-scripts
// @icon         https://bitbucket.org/loujine/musicbrainz-scripts/raw/default/icon.png
// @description  musicbrainz.org: Show discid number on main release pages
// @compatible   firefox+greasemonkey  quickly tested
// @licence      CC BY-NC-SA 3.0 (https://creativecommons.org/licenses/by-nc-sa/3.0/)
// @include      http*://*musicbrainz.org/release/*
// @exclude      http*://*musicbrainz.org/release/add
// @exclude      http*://*musicbrainz.org/release/add?artist*
// @exclude      http*://*musicbrainz.org/release/add?release-group*
// @exclude      http*://*musicbrainz.org/release/*annotation*
// @exclude      http*://*musicbrainz.org/release/*cover-art*
// @exclude      http*://*musicbrainz.org/release/*/relationships
// @exclude      http*://*musicbrainz.org/release/*/discids
// @exclude      http*://*musicbrainz.org/release/*/tags
// @exclude      http*://*musicbrainz.org/release/*/details
// @exclude      http*://*musicbrainz.org/release/*/edit
// @grant        none
// @run-at       document-end
// ==/UserScript==

'use strict';

// adapted from jesus2099  mb. INLINE STUFF

function fetchDiscids(mbid, tab, callback) {
    var url = '/ws/2/release/' + encodeURIComponent(mbid) + '/?inc=discids',
        xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4) {
            if (xhr.status === 200 && xhr.responseText != null) {
                callback(xhr.responseXML, tab);
            } else {
                console.log('Error: ', xhr.status);
            }
        }
    };
    xhr.open('GET', url, true);
    xhr.timeout = 5000;
    xhr.ontimeout = function() {
        console.error('The request for ' + url + ' timed out.');
        };
    xhr.send(null);
}

function showCountDiscid() {
    var tab = document.querySelector("div.tabs > ul.tabs > li > a[href$='/discids']"),
        mbid = document.URL.split('/')[4];
    var callback = function(xml, tab) {
        var cnt = xml.documentElement.querySelector('disc-list');
        cnt = parseInt(cnt.attributes.count.textContent, 10);
        if (cnt > 0) {
            tab.style.setProperty('background-color', '#6f9');
        }
        tab.textContent += ' (' + cnt + ')';
    };
    fetchDiscids(mbid, tab, callback);
}

showCountDiscid();<commit_msg>[discid] Fix for multi-medium releases<commit_after>// ==UserScript==
// @name         MusicBrainz: Show discid count
// @author       loujine
// @version      2015.10.10
// @downloadURL  https://bitbucket.org/loujine/musicbrainz-scripts/raw/default/mbz-showcountdiscid.user.js
// @updateURL    https://bitbucket.org/loujine/musicbrainz-scripts/raw/default/mbz-showcountdiscid.user.js
// @supportURL   https://bitbucket.org/loujine/musicbrainz-scripts
// @icon         https://bitbucket.org/loujine/musicbrainz-scripts/raw/default/icon.png
// @description  musicbrainz.org: Show discid number on main release pages
// @compatible   firefox+greasemonkey  quickly tested
// @licence      CC BY-NC-SA 3.0 (https://creativecommons.org/licenses/by-nc-sa/3.0/)
// @include      http*://*musicbrainz.org/release/*
// @exclude      http*://*musicbrainz.org/release/add
// @exclude      http*://*musicbrainz.org/release/add?artist*
// @exclude      http*://*musicbrainz.org/release/add?release-group*
// @exclude      http*://*musicbrainz.org/release/*annotation*
// @exclude      http*://*musicbrainz.org/release/*cover-art*
// @exclude      http*://*musicbrainz.org/release/*/relationships
// @exclude      http*://*musicbrainz.org/release/*/discids
// @exclude      http*://*musicbrainz.org/release/*/tags
// @exclude      http*://*musicbrainz.org/release/*/details
// @exclude      http*://*musicbrainz.org/release/*/edit
// @grant        none
// @run-at       document-end
// ==/UserScript==

'use strict';

// adapted from jesus2099  mb. INLINE STUFF

function fetchDiscids(mbid, tab, callback) {
    var url = '/ws/2/release/' + encodeURIComponent(mbid) + '/?inc=discids',
        xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4) {
            if (xhr.status === 200 && xhr.responseText != null) {
                callback(xhr.responseXML, tab);
            } else {
                console.log('Error: ', xhr.status);
            }
        }
    };
    xhr.open('GET', url, true);
    xhr.timeout = 5000;
    xhr.ontimeout = function() {
        console.error('The request for ' + url + ' timed out.');
        };
    xhr.send(null);
}

function showCountDiscid() {
    var tab = document.querySelector("div.tabs > ul.tabs > li > a[href$='/discids']"),
        mbid = document.URL.split('/')[4];
    var callback = function(xml, tab) {
        var cnts = xml.documentElement.querySelectorAll('disc-list'),
            cnt = 0,
            idx;
        for (idx = 0; idx < cnts.length; idx++) {
            cnt += parseInt(cnts[idx].attributes.count.textContent, 10);
        }
        if (cnt > 0) {
            tab.style.setProperty('background-color', '#6f9');
        }
        tab.textContent += ' (' + cnt + ')';
    };
    fetchDiscids(mbid, tab, callback);
}

showCountDiscid();
{'fraction_non_alphanumeric': 0.17220216606498195, 'fraction_numerical': 0.011552346570397111, 'mean_word_length': 2.522568340750159, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 11, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6013805', 'n_tokens_mistral': 1954, 'n_tokens_neox': 1827, 'n_words': 300}