-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modernize and clean up scheduling functions config directory
The add-on no longer supports exporting and importing dynamic scheduling functions, so convert the ".slj" files into text files. Update the README.md file to account for that.
- Loading branch information
Showing
7 changed files
with
187 additions
and
130 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
Function name: DaysBeforeNthWeekday | ||
|
||
Author: Jonathan Kamens <[email protected]> | ||
|
||
Back story | ||
---------- | ||
|
||
A user on the send-later-users mailing list | ||
(https://groups.google.com/forum/#!forum/send-later-users) asked how to | ||
generate an email a certain number of days before a particular weekday of the | ||
month, e.g., "five days before the fourth Wednesday of the month." This | ||
function demonstrates how to do that. It can be configured by passing in | ||
arguments or by editing the defaults at the top of the function. | ||
|
||
Help text | ||
--------- | ||
|
||
Send an email n days before a specific day of the week on a specific week of | ||
the month, e.g., "9:00am five days before the 4th Wednesday of the month." | ||
Arguments: | ||
|
||
- Recurring -- true or false value indicating whether this is a recurring | ||
message (default false) | ||
- Weekday to look for (0 is Sunday, 1 is Monday, etc.); default is Wednesday | ||
(3) | ||
- Which week of the month to look for (first, second, third, etc.) (default is | ||
4th) | ||
- How many days in advance to send the message (default is 5) | ||
- Hour at which to send the message (default is 9) | ||
- Minutes after the hour at which to send the message (default is 0) | ||
|
||
Specifying "-" for any argument is the same as not specifying the argument at | ||
all. | ||
|
||
If today is the day the email should be sent, the message will be scheduled for | ||
today even if the specified hour and minute are earlier than the current time, | ||
which means that Send Later will send out today's late but if you've specified | ||
recurring then subsequent ones will be sent out on time. | ||
|
||
Code | ||
---- | ||
|
||
function getarg(num, deflt) { | ||
if (args[num] == '-' || args[num] === undefined) | ||
return deflt; | ||
return args[num]; | ||
} | ||
|
||
recurring = getarg(0, false); | ||
weekday = getarg(1, 3); | ||
week_number = getarg(2, 4); | ||
days_in_advance = getarg(3, 5); | ||
send_hour = getarg(5, 9); | ||
send_minute = getarg(5, 0); | ||
|
||
one_day_value = 24 * 60 * 60 * 1000; | ||
in_advance_value = one_day_value * days_in_advance; | ||
|
||
if (prev) | ||
now = new Date(prev.valueOf() + one_day_value); | ||
else | ||
now = new Date(); | ||
|
||
while (true) { | ||
then = new Date(now.valueOf() + in_advance_value); | ||
if (then.getDay() == weekday && | ||
Math.floor((then.getDate() - 1) / 7) == week_number - 1) { | ||
break; | ||
} | ||
now = new Date(now.valueOf() + one_day_value); | ||
} | ||
|
||
now.setHours(send_hour); | ||
now.setMinutes(send_minute); | ||
now.setSeconds(0); | ||
now.setMilliseconds(0); | ||
|
||
next = now; | ||
|
||
if (recurring) { | ||
nextspec = "function " + specname; | ||
nextargs = [true, weekday, week_number, days_in_advance, | ||
send_hour, send_minute]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Function name: FirstDaysOfEachMonth | ||
|
||
Author: Jonathan Kamens <[email protected]> | ||
|
||
Help text | ||
--------- | ||
|
||
Schedule a recurring message to be sent at 9:00am on the first days of every | ||
month. You can alter the behavior of the function with the following arguments | ||
in this order: hour at which to send the message (default 9), minutes after the | ||
hour to send the message (default 0), last day of each month to send the | ||
message (default 4). | ||
|
||
Code | ||
---- | ||
function getarg(idx, deflt) { | ||
if (args[idx] == null) | ||
return deflt; | ||
return args[idx]; | ||
}; | ||
|
||
if (! prev) { | ||
prev = new Date(); | ||
} | ||
hour = getarg(0, 9); | ||
minute = getarg(1, 0); | ||
lastDay = getarg(2, 4); | ||
dayOfMonth = prev.getDate() + 1; | ||
month = prev.getMonth(); | ||
year = prev.getFullYear(); | ||
if (dayOfMonth > lastDay) { | ||
dayOfMonth = 1; | ||
month++; | ||
if (month > 11) { // month in JavaScript Date objects is 0-based | ||
month = 0; | ||
year++; | ||
} | ||
} | ||
next = new Date(year, month, dayOfMonth, hour, minute); | ||
nextspec = "function " + specname; | ||
nextargs = args; | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
Function name: NextChol | ||
|
||
Author: Jonathan Kamens <[email protected]> | ||
|
||
Help text | ||
--------- | ||
|
||
Schedules the message to send a short time after the end of the current Sabbath | ||
or Jewish holiday, or the next Sabbath or Jewish Holiday if it isn't currently | ||
one (e.g., if you use this function on a regular Thursday the message will be | ||
scheduled to be sent Saturday night). Useful if you use email at these times | ||
but don't want to offend your Jewish friends who don't. | ||
|
||
Note that this function calls out to a little HTTP API endpoint I wrote to | ||
calculate the end time of the Sabbath or holiday. | ||
|
||
You will probably want to edit the function after importing it to specify what | ||
city you're in, so the times will be correct for you. See the API endpoint's | ||
help page (https://jewish-holidays.kamens.us/next-chol?help) for a list of | ||
supported cities. | ||
|
||
Code | ||
---- | ||
|
||
// See https://jewish-holidays.kamens.us/next-chol?help for supported cities. | ||
let city = 'Boston'; | ||
let url = 'https://jewish-holidays.kamens.us/next-chol?force&city=' + city; | ||
let req = new XMLHttpRequest(); | ||
req.open('GET', url, false); | ||
req.send(); | ||
if (req.readyState != 4) | ||
return; | ||
if (req.status != 200) { | ||
msg = 'Error fetching from ' + url; | ||
throw(msg); | ||
} | ||
let matches = req.responseText.match(/^\s*(\d+)/); | ||
if (matches.length < 1) { | ||
msg = url + ' did not return a number'; | ||
throw(msg); | ||
} | ||
let unix_time = matches[1]; | ||
next = new Date(); | ||
next.setTime(unix_time * 1000); | ||
next.setMinutes(next.getMinutes() + Math.floor(Math.random() * 15)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,25 @@ | ||
# Send Later dynamic scheduling function library | ||
|
||
This directory contains dynamic scheduling functions for use with the [Send Later Thunderbird add-on](https://addons.thunderbird.net/thunderbird/addon/send-later-3/). For more information about dynamic scheduling functions, see the [Send Later user guide](https://extended-thunder.github.io/send-later/#dynamic). | ||
This directory contains dynamic scheduling functions for use with the [Send | ||
Later Thunderbird add-on][atn]. For more information about dynamic scheduling | ||
functions, see the [Send Later user guide][guide]. | ||
|
||
The preferred method for contributing a new function to this library is to fork [Send Later on Github](https://github.com/Extended-Thunder/send-later), copy your function from the dynamic function editor into a new file in this directory. Name your new file with an ".slj" extension, and follow the format conventions used in the existing examples. Finally, update this file (README.md) to describe your function (following the format of the existing entries), and submit a pull request. | ||
The preferred method for contributing a new function to this library is: | ||
|
||
Alternatively, you can just [email me](mailto:[email protected]) your function as a plain text file attachment and let me know what it does. | ||
* Fork [Send Later on Github][github]. | ||
* Copy your function from the dynamic function editor into a new file in this | ||
directory formatted to look like the other files. | ||
* Commit your new file to the repository. | ||
* Submit a pull request. | ||
|
||
Alternatively, you can just [email me][email] your function as a plain text | ||
file attachment and let me know what it does. | ||
|
||
Thanks for your contributions! | ||
|
||
## Contributed functions | ||
|
||
### DaysBeforeNthWeekday.sjl | ||
|
||
By: Jonathan Kamens <[[email protected]](mailto:[email protected])> | ||
|
||
A user on the [send-later-users mailing list](https://groups.google.com/forum/#!forum/send-later-users) asked how to generate an email a certain number of days before a particular weekday of a particular weekday of the month, e.g., "five days before the fourth Wednesday of the month." This function demonstrates how to do that. It can be configured by passing in arguments or by editing the defaults at the top of the function. | ||
|
||
### FirstFourDaysOfEachMonth.slj | ||
|
||
By: Jonathan Kamens <[[email protected]](mailto:[email protected])> | ||
|
||
Schedules a recurring message that sends at 9:00am on the first four days of each month. | ||
|
||
You can use variables to control the send time as well as the last day of each month when the message is sent. See the documentation string for the function for details. | ||
|
||
### NextChol.slj | ||
|
||
By: Jonathan Kamens <[[email protected]](mailto:[email protected])> | ||
|
||
This function is useful if you are Jewish and use email on the Sabbath and Jewish holidays but you have some Jewish friends who don't, and you'd rather not annoy them by sending them emails when they're offline. | ||
|
||
The NextChol function will schedule your message to be sent shortly after the end of the current Sabbath or holiday, or after the end of the next one if it is not currently one. | ||
|
||
Note that this function calls out to a little HTTP API endpoint I wrote to calculate the end time of the Sabbath or holiday. | ||
|
||
You will probably want to edit the function after importing it to specify what city you're in, so the times will be correct for you. See the [API endpoint's help page](https://jewish-holidays.kamens.us/next-chol?help) for a list of supported cities. | ||
[atn]: https://addons.thunderbird.net/thunderbird/addon/send-later-3/ | ||
[guide]: https://extended-thunder.github.io/send-later/#dynamic | ||
[github]: https://github.com/Extended-Thunder/send-later | ||
[email]: mailto:[email protected] |