Skip to content

Instantly share code, notes, and snippets.

@salsalabs
salsalabs / wrap_script_for_thank_you_page.js
Created June 22, 2020 19:30
Put a wrapper around a script so that it only runs on thank you pages with a donation_KEY and an amount.
// Put this text on a new line just after the <script> tag (https://prnt.sc/t4j44d).
var isThankYouPage = document.location.href.indexOf("thank_you") != -1;
var hasDonationKEY = /donate_page_KEY=\d+/.test(document.location.href);
var hasAmount = /amount=\d+/.test(document.location.href);
if (isThankYouPage && hasDonationKey && hasAmount) {
// Put this text just before the </script> tag (https://prnt.sc/t4j4il).
}
@salsalabs
salsalabs / change_country_names.html
Last active June 9, 2020 21:52
Change displayed names for selected countries.
<!-- BEGIN Change displayed names for selected countries. -->
<script type="text/javascript">
(function() {
// This object maps country abbreviations to text.
// - The keys are ISO-3166 Alpha 2 abbreviations for countries.
// - The values are the countries names to display.
// You can find the abbreviations by viewing the HTML source
// of any page that has a country field.
countries = {
"LY": "Libya",
@salsalabs
salsalabs / move_first_name_before_last_name.html
Created May 21, 2020 15:02
Demonstration script for moving the first name in a donation page before the last name.
<script type="text/javascript">
// Script to move the last name before the first name on a donation page.
// Only run this script on donation pages. This should work for both
// regular pages and pages with a Salsa shortcut.
if (window.location.href.indexOf('/salsa/donation/') != -1) {
// Wait for the page to be loaded.
$(document).ready(function() {
@salsalabs
salsalabs / secure_actions.html
Last active May 6, 2020 14:14
Script to find public-facing pages with HTTP (non-secure) URLs and change the URL to HTTPS (secure).
<!-- BEGIN Change non-secure action URLs to secure. -->
<script type="text/javascript">
if (/^http:/.test(window.location.href)) {
window.location.href = window.location.href.replace('http', 'https');
}
</script>
<!-- END Change non-secure action URLs to secure. -->
@salsalabs
salsalabs / hide_petition_signatures.html
Last active February 4, 2020 15:40
Provide a way to hide or show the Location information on a Salsa Classic petition that displays signatures.
<!-- BEGIN Script to remove the city and state from petitions.
To remove cities and states from the petition, add the following HTML to the petition header.
<div style="display: none;" id="remove-petition-cities-and-states"></div>
To restore cities and states to a petition, remove the HTML.
-->
<script type="text/javascript">
(function($) {
$(function() {
var e = $('#remove-petition-cities-and-states');
if (e.length == 0) {
@salsalabs
salsalabs / event_change_optional_group_header.html
Last active January 22, 2020 22:30
Change the description for the optional groups on an Classic event page.
<script type="text/javascript">
(function($) {
$(document).ready(function() {
if (window.location.href.indexOf('event_KEY=89503') != -1) {
var e = $('#regForm2 > strong:nth-child(21)');
if (e.length > 0) {
e.html('Add me to the email subscriptions below to be notified of important alerts:');
}
}
});
@salsalabs
salsalabs / submit_a_request_anchor_fix.js
Last active January 8, 2020 20:56
Zendesk "submit a request" mod to make suggestions appear in their own windows. Avoids a scan of the doc hijacking the "submit a request" window where someone may have typed something. Put this into script.js in the Zendesk theme.
//Wait for suggestion links on a submit a request page. Called after DOM is loaded.
function modifySuggestionLinks() {
if (!RegExp('/requests(/new)*$').test(window.location.href)) {
return
}
const target = document.querySelector('div.suggestion-list');
if (target == null) {
return
}
//Create and configure a mutuation observer. Observe changes in div.suggestion-list's structure.
@salsalabs
salsalabs / action_swap_header_content.html
Last active September 10, 2019 15:15
Use a modification observer to show one set of content on the first (address) page of a targeted action, and another set of content on the second (letter/legislators) page.
<!-- BEGIN Hide/show parts of the action header based on the workflow step being viewed. -->
<script type="text/javascript">
// NOTE: The basis for this script is described in exquisite detail on this page:
// https://gist.github.com/salsalabs/fa7cdd9d27f955bdc10e9cbac522cec5
// The body of the script is copied as-is. The only real changes are modify()
// and the parameters to waitForElement.
(() => {
// Function to change an element on a targeted action page.
//
// If the current page is not a targeted action, then the desired element already appears on
@salsalabs
salsalabs / credit_card_year_update.html
Created September 5, 2019 16:58
Script to replace the contents of a credit card year dropdown with a current list of years. Particularly helpful on Salsa storefront checkout pages, where the year ranges from 2013 to 2023.
<!-- BEGIN: Replace the credit card year dropdown with a current list of years. -->
<script type="text/javascript">
$(document).ready(function() {
var e = $('select[name="ccExpYear"]');
if (e.length != 0) {
$("option", e).remove();
e.append("<option>Year</option>");
var year = new Date().getFullYear();
for (var i = 0; i < 16; i++) {
var v = year + i;
@salsalabs
salsalabs / donation_summary_for_donation_page.html
Last active September 3, 2019 17:32
SalsaScript to summary the count and total donations made by a single donation page. The results are stored as variables donationCount and donationAmount as Javascript global variables.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Mules</title>