|
242 | 242 | }, { once: true } |
243 | 243 | ); |
244 | 244 |
|
245 | | - // When the form is submitted, delete the localStorage key/value pair. |
| 245 | + // When the form is submitted via clicking on the 'Submit' built-in button, |
| 246 | + // delete the localStorage key/value pair. |
246 | 247 | textarea.form.addEventListener( |
247 | 248 | "submit", |
248 | 249 | /** |
|
254 | 255 | * Retrieve the session expiry time that was stamped on the post submit page. |
255 | 256 | * Force it to a number! |
256 | 257 | * |
| 258 | + * Note: 1) if the div element does not exist, expiryTime becomes `NaN` |
| 259 | + * 2) if it exists but has not been properly initialised, expiryTime becomes `0` |
| 260 | + * In both cases, we will skip the test for expiryTime |
257 | 261 | * @type {number} |
258 | 262 | */ |
259 | | - const expiryTime = parseInt(document.getElementById('expiry-time').innerText.trim(), 10); |
| 263 | + const expiryTime = parseInt(document.getElementById('expiry-time')?.innerText.trim(), 10); |
260 | 264 | const dateNow = Math.floor(Date.now() / 1000); // we get milliseconds, so we need to convert to seconds. |
261 | 265 | console.debug("Date.now() in seconds is " + dateNow + " and expiryTime is " + expiryTime); |
262 | 266 |
|
263 | 267 | //the if statement for deleting local storage in PM'ing, because expiryTime = 0, it must be fixed |
264 | | - if (!key.includes("ucp.php")) { |
265 | | - if (dateNow > expiryTime) { |
| 268 | + //if (!key.includes("ucp.php")) { |
| 269 | + // |
| 270 | + // Now we do 2 things: |
| 271 | + // - the error came from an event not being fired for PMs; |
| 272 | + // - just to be absolutely sure, do first an extra check for expiryTime being non-zero |
| 273 | + // (gwyneth 20240425) |
| 274 | + if ((expiryTime) && (dateNow > expiryTime)) { |
266 | 275 | // We won't clear anything if the session already expired, so return. |
267 | 276 | return; |
268 | | - } |
269 | 277 | } |
| 278 | + //} |
270 | 279 | // Now remove the local storage on `Submit` — it'll get saved to the database as a post/PM, |
271 | 280 | // so we don't need it around any longer. |
272 | | - // ... except on Preview. We still want to keep the storage around during preview! |
| 281 | + // ... except on Preview (or draft, or whatever). We still want to keep the storage around during preview! |
273 | 282 | // Kudos to @kylesands for this (gwyneth 20240416) |
274 | | - if (document.activeElement.tagName.toLowerCase() == "input" && document.activeElement.value.toLowerCase() == ("submit") || document.activeElement.value.toLowerCase() == ("υποβολή")) { // Added to only clear on Input button with Submit value |
| 283 | + // Fixed lack of translation issue by using the 'name' value instead, but if either does |
| 284 | + // not exist, localStorage will remain untouched. |
| 285 | + if (document.activeElement.tagName?.toLowerCase() == "input" && document.activeElement.name?.toLowerCase() == "post") { // Added to only clear on Input button with Submit value |
275 | 286 | message.localStorage.removeItem(key); |
276 | 287 | message.removeEventListener(unloadEvent, updateStorage); |
277 | 288 | console.debug("Text submitted (not in preview!); removed from localStorage"); |
|
0 commit comments