function removeIPv4Domain(e,n){var t=e.parent(),a=e.data("index");var i=t.find(".input-group[data-index]:last").data("index");e.remove();if(i==a){return}var r="DNSServices["+n+"][IPv4Domains][";resortDomain(t,r)}function removeIPv6Domain(e,n){var t=e.parent(),a=e.data("index");var i=t.find(".input-group[data-index]:last").data("index");e.remove();if(i==a){return}var r="DNSServices["+n+"][IPv6Domains][";resortDomain(t,r)}function resortDomain(e,a){e.find(".input-group[data-index]").each(function(n){var e=$(this);var t=e.data("index");if(n==t)return;e.attr("data-index",n).data("index",n);e.find('[name^="'+a+'"]').each(function(){var e=$(this).attr("name");e=e.substring(a.length);e=e.replace(/^[0-9]+/,n);e=a+e;$(this).attr("name",e)})})}function addIPv4Domain(e,n,t){var a=e.find(".input-group[data-index]:last").data("index");var i=a===undefined?0:a+1;var r=template("tmpl-domain-row",{k:n,domainK:i,supportLine:t,ipVer:4});e.append(r)}function addIPv6Domain(e,n,t){var a=e.find(".input-group[data-index]:last").data("index");var i=a===undefined?0:a+1;var r=template("tmpl-domain-row",{k:n,domainK:i,supportLine:t,ipVer:6});e.append(r)}function addWebhook(){var e=$("#ddns-form .ddns-webhook:last").data("index");var n=e===undefined?0:e+1;var t=template("tmpl-webhook-row",{k:n});$("#ddns-form-submit-group").before(t)}function syncWebhookName(e){var n=$(e).data("index");$("#ddns-webhook-name-"+n).text($(e).val()||App.t("未命名")+"("+n+")")}function removeWebhook(e){var n=$(e).closest("div.ddns-webhook"),t=n.data("index");if(confirm("确定要删除Webhook“"+$("#ddns-webhook-name-"+t).text()+"”吗？")){var a=$("#ddns-form .ddns-webhook:last").data("index");n.remove();if(a==t){return}resortWebhook()}}function resortWebhook(){var a="Webhooks[";$("#ddns-form .ddns-webhook").each(function(n){var e=$(this);var t=e.data("index");if(n==t)return;e.attr("data-index",n).data("index",n);e.find("[data-index]").attr("data-index",n).data("index",n);e.find('[name^="'+a+'"]').each(function(){var e=$(this).attr("name");e=e.substring(a.length);e=e.replace(/^[0-9]+/,n);e=a+e;$(this).attr("name",e)});e.attr("id","ddns-webhook-"+n);e.find("#ddns-webhook-name-"+t).attr("id","ddns-webhook-name-"+n)})}var ipv4NetInterfaceIPRule="IPv4[NetInterface][Filter][Include]",ipv6NetInterfaceIPRule="IPv6[NetInterface][Filter][Include]";function insertNetIfaceRegexpTag(e){var n=e==6?ipv6NetInterfaceIPRule:ipv4NetInterfaceIPRule;var t=$('#ddns-form input[name="'+n+'"]').val();if(/^regexp:/.test(t))return;$('#ddns-form input[name="'+n+'"]').val("regexp:"+t)}$(function(){$("#ddns-form").off().on("submit",function(e){e.preventDefault();$.post(window.location.href,$(this).serialize(),function(e){if(e.Code!=1){App.message({text:e.Info,type:"error"});return}var n=$("#ddns-running-status");if(e.Data.isRunning){if(!n.hasClass("running"))n.addClass("running")}else{n.removeClass("running")}App.message({text:e.Info,type:"success"})},"json")});$('input[name="IPv6[Type]"],input[name="IPv4[Type]"]').on("click",function(){var e=$(this).attr("name");$('#ddns-form div[rel="'+this.id+'"]').show();$('#ddns-form input[name="'+e+'"]:not(:checked)').each(function(){$('#ddns-form div[rel="'+this.id+'"]').hide()})});$('input[name="IPv6[Type]"]:checked,input[name="IPv4[Type]"]:checked').trigger("click");$('input[name="IPv6[Enabled]"],input[name="IPv4[Enabled]"]').on("click",function(){var e=$(this).closest("div.form-group").siblings("div.form-group");if(this.value=="1"){e.removeClass("hide")}else{e.addClass("hide")}});$('input[name="IPv6[Enabled]"]:checked,input[name="IPv4[Enabled]"]:checked').trigger("click");$("#ddns-form .provider-switch-onoff").on("click",function(){var e=$(this).attr("rel"),n=$(this).val()=="1";if(n){$("#"+e).removeClass("hide");$("#"+e).find("[data-required]").prop("required",true);return}$("#"+e+":not(.hide)").addClass("hide");$("#"+e).find(":required").attr("data-required","1").prop("required",false)});$("#ddns-form .provider-switch-onoff:checked").trigger("click");var e="NotifyTemplate[html]";$('textarea[name="NotifyTemplate[html]"],textarea[name="NotifyTemplate[markdown]"]').on("focus",function(){e=$(this).attr("name")});$("#notify-template-tag-values code").on("click",function(){App.insertAtCursor($('textarea[name="'+e+'"]')[0],$(this).text())});$("#ddns-form").on("click",".webhook-content-tag-values code",function(){App.insertAtCursor($(this).closest(".help-block").prev("textarea")[0],$(this).text())});$('input[name="IPv4[NetInterface][Filter][Include]"],input[name="IPv4[NetInterface][Filter][Exclude]"]').on("focus",function(){ipv4NetInterfaceIPRule=$(this).attr("name")});$('input[name="IPv6[NetInterface][Filter][Include]"],input[name="IPv6[NetInterface][Filter][Exclude]"]').on("focus",function(){ipv6NetInterfaceIPRule=$(this).attr("name")})});