Skip to content

Instantly share code, notes, and snippets.

@bgwaltney
Last active December 4, 2019 19:51
Show Gist options
  • Select an option

  • Save bgwaltney/0902f51311025b84cfafa6df118fae78 to your computer and use it in GitHub Desktop.

Select an option

Save bgwaltney/0902f51311025b84cfafa6df118fae78 to your computer and use it in GitHub Desktop.
Hides email subscriptions on the Hubspot unsubscribe page.
var whitelist = [ //List of subscription ids you want to show.
// "7613268", //Forward Coaching Events
// "7614033", //Forward Coaching Promotions
// "7613655", //Forward Coaching Custom Communication
// "7613269", //Forward Coaching One to One Communication
// "7614034", //Forward Coaching Customer Service
// "7613270" //Forward Coaching One to One
"7209878", //BKTO Events
"6952826", //Brivity Promotions
"7073704", //Brivity Customer Communications
"7176915", //Brivity One to One Communication
"6954235", //Brivity Customer Service Communication
"6954236" //Brivity One to One
];
$(document).ready(function() { //wait for the page to be fully loaded
cleanOptions();
unsub();
});
function cleanOptions() {
$('input[name="subscription_ids"]').val(whitelist.join()); //update the list of subscription ids to only contain the whitelisted ones
$(".email-prefs .item").each(function() {
var id = $(this)
.find('input[type="checkbox"]')
.attr("id")
.replace("id_", "");
$(this).data("id", id);
});
$(".email-prefs .item").each(function() {
if ($.inArray($(this).data("id"), whitelist) == -1) {
//$(this).remove();
$(this).hide(); //this seems to work better than removing the element
}
});
}
function unsub() {
$('label[for="globalunsub"]').hide(); //hide their checkbox
$(".subscribe-options").append(`<p>
<label for="custom-unsub">
<input name="custom-unsub" id="custom-unsub" type="checkbox">
<span>
Unsubscribe me from all Forward Coaching mailing lists.
</span>
</label>
</p>`);
$("#custom-unsub").click(function() {
for (sub of whitelist) {
$("#id_" + sub).prop("checked", false);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment