Skip to content

Instantly share code, notes, and snippets.

View danielcranney's full-sized avatar

Daniel Cranney danielcranney

View GitHub Profile
@danielcranney
danielcranney / CheckForEmptyValues.jsx
Last active April 20, 2021 19:32
Check Object for Empty Values
function checkEmptyValues(obj) {
for (var key in obj) {
if (obj[key] === "") {
// Do something
return;
} else {
// Do something else
}
}
}
@danielcranney
danielcranney / gist:331bafced577f83ee61ab3685fa3f328
Created September 21, 2021 20:14
Right/Left ScrollBy with Smooth Scroll
const handleSlideRight = () => {
document.getElementById("colorContent").scrollBy({
top: 0,
left: +150,
behavior: "smooth",
});
};
const handleSlideLeft = () => {
document.getElementById("colorContent").scrollBy({
@danielcranney
danielcranney / gist:a04155f899b753b39a8d59bbe2ac7d04
Created September 21, 2021 20:15
Left/Right ScrollTo with Smooth Scroll
const handleSlideRight = () => {
document.getElementById("colorContent").scrollTo({
top: 0,
left: Math.max(
(scrollAmount += 5),
document.getElementById("colorContent").clientWidth
),
behavior: "smooth",
});
};
@danielcranney
danielcranney / 01 - create logUnsubscribes().js
Created November 1, 2024 10:18
newsletter unsubscription tracker / 01 - create logUnsubscribes().js
// Logs emails from threads labeled "unsubscribed" to a Google Sheet
function logUnsubscribes() {
// Additional code will go here
}
@danielcranney
danielcranney / 02 - fetch unsubscribed label from gmail.js
Created November 1, 2024 10:18
newsletter unsubscription tracker / 02 - fetch unsubscribed label from gmail.js
// Logs emails from threads labeled "unsubscribed" to a Google Sheet
function logUnsubscribes() {
var label = GmailApp.getUserLabelByName('unsubscribed'); // Fetch the "unsubscribed" label from Gmail
}
@danielcranney
danielcranney / 03 - get threads with the unsubscribed label.js
Created November 1, 2024 10:18
newsletter unsubscription tracker / 03 - get threads with the unsubscribed label.js
// Logs emails from threads labeled "unsubscribed" to a Google Sheet
function logUnsubscribes() {
var label = GmailApp.getUserLabelByName('unsubscribed'); // Fetch the "unsubscribed" label from Gmail
var threads = label.getThreads(); // Get all threads with this label
}
@danielcranney
danielcranney / 04 - connect to Google sheet.js
Created November 1, 2024 10:19
newsletter unsubscription tracker / 04 - connect to Google sheet.js
// Logs emails from threads labeled "unsubscribed" to a Google Sheet
function logUnsubscribes() {
var label = GmailApp.getUserLabelByName('unsubscribed'); // Fetch the "unsubscribed" label from Gmail
var threads = label.getThreads(); // Get all threads with this label
var sheet = SpreadsheetApp.open(DriveApp.getFileById('REPLACE_WITH_GOOGLE_SHEET_ID')); // Open the target Google Sheet
}
@danielcranney
danielcranney / 05 - get all messages in thread.js
Created November 1, 2024 10:19
newsletter unsubscription tracker / 05 - get all messages in thread.js
// Logs emails from threads labeled "unsubscribed" to a Google Sheet
function logUnsubscribes() {
var label = GmailApp.getUserLabelByName('unsubscribed');
var threads = label.getThreads();
var sheet = SpreadsheetApp.open(DriveApp.getFileById('1v77gBSUzF7evN5Rlnvsz27LgoHgowiLivPpAGeTMgBQ'));
threads.forEach(function(thread) {
var messages = thread.getMessages(); // Get all messages in the thread
});
}
@danielcranney
danielcranney / 06 - read the contents of the emails.js
Created November 1, 2024 10:20
newsletter unsubscription tracker / 06 - read the contents of the emails.js
// Logs emails from threads labeled "unsubscribed" to a Google Sheet
function logUnsubscribes() {
var label = GmailApp.getUserLabelByName('unsubscribed');
var threads = label.getThreads();
var sheet = SpreadsheetApp.open(DriveApp.getFileById('1v77gBSUzF7evN5Rlnvsz27LgoHgowiLivPpAGeTMgBQ'));
threads.forEach(function(thread) {
var messages = thread.getMessages();
messages.forEach(function(message) {
var body = message.getBody(); // Get the body content of the email
@danielcranney
danielcranney / 07 - extractEmail() helper function.js
Created November 1, 2024 10:20
newsletter unsubscription tracker / 07 - extractEmail() helper function.js
// Helper function to extract the first email address found in a given text
function extractEmail(body) {
var emailPattern = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/; // Regex pattern to match an email address
var match = body.match(emailPattern); // Find the first email that matches the pattern
return match ? match[0] : null; // Return the email if found, otherwise return null
}