gazza911 / TVMaze Shows Country Filter

// ==UserScript==
// @name         TVMaze Shows Country Filter
// @version      1.2
// @description  Filters the Network dropdown on the show page
// @include      /^https?:\/\/www\.tvmaze\.com\/shows[^\/]*$/
// @updateURL https://openuserjs.org/meta/gazza911/TVMaze_Shows_Country_Filter.meta.js
// @license     MIT
// @grant        none
// ==/UserScript==

$(document).ready(function(){
    $("#show-country_enum").change(function(){
        var cName = $(this).find("option:selected").text();
        $("#show-network_id optgroup, #show-webchannel_id optgroup").each(function(){
            if ($(this).attr("label") === cName || cName === "") {
                $(this).css("display", "block");
            }
            else {
                $(this).css("display", "none");
            }
        });

        if (cName !== "") {
            if ($("#show-network_id option:selected").parent().attr("label") !== cName) {
                $("#show-network_id").val("");
            }
            if ($("#show-webchannel_id option:selected").parent().attr("label") !== cName) {
                $("#show-webchannel_id").val("");
            }
        }

    });

    $("#show-country_enum").trigger("change");
});