subscribe_button = document.getElementById("subscribe"); if (subscribe_button.getAttribute('onclick')) { subscribe_button["href"] = "javascript:void(0)"; } function subscribe() { var url = "/subscription_ajax?action_create_subscription_to_channel=1&c=<%= ucid %>&referer=<%= env.get("current_page") %>"; var xhr = new XMLHttpRequest(); xhr.responseType = "json"; xhr.timeout = 20000; xhr.open("GET", url, true); xhr.send(); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { if (xhr.status == 200) { subscribe_button = document.getElementById("subscribe"); subscribe_button.onclick = unsubscribe; subscribe_button.innerHTML = '<%= translate(locale, "Unsubscribe") %> | <%= sub_count_text %>' } } } } function unsubscribe() { var url = "/subscription_ajax?action_remove_subscriptions=1&c=<%= ucid %>&referer=<%= env.get("current_page") %>"; var xhr = new XMLHttpRequest(); xhr.responseType = "json"; xhr.timeout = 20000; xhr.open("GET", url, true); xhr.send(); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { if (xhr.status == 200) { subscribe_button = document.getElementById("subscribe"); subscribe_button.onclick = subscribe; subscribe_button.innerHTML = '<%= translate(locale, "Subscribe") %> | <%= sub_count_text %>' } } } }