Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unsubscribe scrubber developed for Public Citizen. A standard Salsa unsubscribe page with only an "everything" radio button is reduced to a statement and an unsubscribe button. Very cool. Good job, Rebecca!
<script type="text/javascript">
// If the only radion button on an unsubscribe is the "everything"
// radio, then hide it.
function removeUnsubLonelyEverything() {
var e = document.getElementById('remove-some');
if (e != null) return;
e = document.getElementById('remove-forever');
if (e == null) return;
e.parentNode.style.display = 'none';
};
// Remove the Cancel button from unsubscribe pages.
function removeUnsubCancelButton() {
var list = document.getElementsByClassName('cancel');
for (var i = 0; i < list.length; i++) {
list[i].parentNode.removeChild(list[i]);
}
};
// Replace the "Unsubscribe EMAIL..." with a custom string.
function replaceUnsubText() {
var target = document.getElementById('unsubscribe-type');
if (target != null) {
var m = /\s+((.+?)@(.+?)\.(\w+))/.exec(target.innerHTML);
if (m != null) {
var email = m[1];
var source = document.getElementById('unsub-replacement-text');
if (source != null) {
var text = source.innerHTML;
text = text.replace(/{{email}}/g, email);
target.innerHTML = text;
}
}
}
};
document.addEventListener('DOMContentLoaded', function() {
removeUnsubLonelyEverything();
removeUnsubCancelButton();
replaceUnsubText();
});
</script>
<!-- This is the text that will replace the "Unsubscribe EMAIL..." message.
put {{email}} where you want the suporter's email address to appear. -->
<div style="display: none;" id="unsub-replacement-text">
To stop getting email alerts and solicitations from YOUR ORGANIZATION at
<b>{{email}}</b>, click the "Unsubscribe" button below. Note: If
you get email from us at any other address, click the "Unsubscribe"
link in one of those emails to separately unsubscribe that address, too.
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.