From 9bc0be75ed8b334f7f8dab6b9cad56af2412d9a1 Mon Sep 17 00:00:00 2001 From: Patrick Joyce Date: Wed, 26 Nov 2025 09:53:22 -0500 Subject: [PATCH] Added localStorage support --- nacc-wordpress-plugin.php | 2 +- nacc2/README.md | 6 +++++- nacc2/nacc.js | 29 +++++++++++++++++++++++++++-- readme.txt | 6 +++++- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/nacc-wordpress-plugin.php b/nacc-wordpress-plugin.php index d959909..448fce6 100644 --- a/nacc-wordpress-plugin.php +++ b/nacc-wordpress-plugin.php @@ -6,7 +6,7 @@ * Install: Drop this directory in the "wp-content/plugins/" directory and activate it. You need to specify "[NACC]" in the code section of a page or a post. * Contributors: BMLTGuy, pjaudiomv, bmltenabled * Authors: bmltenabled - * Version: 5.0.0 + * Version: 5.1.0 * Requires PHP: 8.0 * Requires at least: 5.3 * License: GPL v2 or later diff --git a/nacc2/README.md b/nacc2/README.md index bbf0e87..bcfe956 100644 --- a/nacc2/README.md +++ b/nacc2/README.md @@ -175,6 +175,10 @@ You should have received a copy of the GNU General Public License along with the CHANGELIST ========== +***Version 2.0.1* ** *-November 26, 2025* + +- Added localStorage support to automatically save and restore the user's clean date + ***Version 2.0.0* ** *-TBD* -- Initial Version \ No newline at end of file +- Initial Version diff --git a/nacc2/nacc.js b/nacc2/nacc.js index 7aa3bc1..a5180db 100644 --- a/nacc2/nacc.js +++ b/nacc2/nacc.js @@ -551,7 +551,22 @@ function NACC(inContainerElementID, inStyle, inLang, inTagLayout, inShowSpecialT if ( !day ) { year = parseInt(inDay); }; - + + // Try to load from localStorage if no parameters were supplied + if ( !year && !month && !day && typeof(Storage) !== 'undefined' ) { + var savedDate = localStorage.getItem('nacc_clean_date'); + if ( savedDate ) { + try { + var dateObj = JSON.parse(savedDate); + year = parseInt(dateObj.year); + month = parseInt(dateObj.month); + day = parseInt(dateObj.day); + } catch(e) { + // Invalid saved data, ignore it + } + } + }; + // We have to have all 3 to do an immediate calculation. if ( year && month && day ) { // Set up the popups to reflect the given date. @@ -773,7 +788,17 @@ NACC.prototype.calculateCleantime = function(inObject) { if ( inObject == owner.m_calculation_results_show_special_tags_checkbox ) { owner.m_keytag_special = !owner.m_keytag_special; }; - + + // Save the clean date to localStorage when calculate button is clicked + if ( inObject == owner.m_calculate_button && typeof(Storage) !== 'undefined' ) { + var dateToSave = { + year: year, + month: month + 1, // Store as 1-12 for consistency + day: day + }; + localStorage.setItem('nacc_clean_date', JSON.stringify(dateToSave)); + }; + owner.calculate(year, month, day); }; diff --git a/readme.txt b/readme.txt index 2181414..5bc1a99 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Plugin URI: https://wordpress.org/plugins/nacc-wordpress-plugin/ Tags: na, cleantime calculator, nacc, recovery, addiction Requires PHP: 8.0 Tested up to: 6.8 -Stable tag: 5.0.0 +Stable tag: 5.1.0 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -30,6 +30,10 @@ That text will be replaced with this cleantime calculator. == Changelog == += 5.1.0 = + +* Added localStorage support to automatically save and restore the user's clean date. + = 5.0.0 = * BREAKING CHANGE: Renamed the `lang` shortcode parameter to `language`. If you are currently using the `lang` parameter in your shortcodes, you will need to update them to use `language` instead.