Skip to content

Commit 1a85820

Browse files
authored
Update postlocalstorage_functions.js
Minor changes
1 parent 5b6eb62 commit 1a85820

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

gwynethllewelyn/postlocalstorage/styles/all/template/postlocalstorage_functions.js

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,49 +51,62 @@
5151
* @type {string}
5252
*/
5353
var key = message.location.href;
54-
// Firefox seems to have an odd bug which affects clicking backspace in quick succession.
54+
// Firefox and Chrome seem to have an odd bug which affects clicking backspace in quick succession.
5555
// Kudos to @gvp9000 and for the fix below. (gwyneth 20240414)
5656
// @see https://www.phpbb.com/customise/db/extension/postlocalstorage/support/topic/246616?p=877489#p877489
57-
57+
//if key.includes (viewforum.php) then exit
58+
if (key.includes("viewforum.php")) {
59+
console.debug("viewforum, no message box");
60+
return;
61+
}
62+
5863
// POSTING
5964
//possible key formats
60-
//./phpBB3/posting.php?mode=edit&&p=xxxxx#preview#preview#preview#preview .......
65+
//./phpBB3/posting.php?mode=edit&p=xxxxx#preview#preview#preview#preview .......
6166
//./phpBB3/posting.php?mode=quote&p=xxxxx#preview#preview#preview#preview .......
6267
//./phpBB3/posting.php?mode=reply&t=yyyyy#preview#preview#preview#preview .......
6368
//Remove all "#preview" strings at the end
64-
if (key.includes("posting.php?mode=")) {
69+
else if (key.includes("posting.php?mode=")) {
6570
if (key.endsWith("#preview")) {
6671
var count_hash = key.split("#").length - 1;
6772
for (let i = 0; i < count_hash; i++) {
6873
key = key.substring(0, key.lastIndexOf('#'));
6974
}
7075
}
7176
}
77+
7278
// PM'ing
7379
//possible key formats
74-
80+
7581
//1 case
7682
//./phpBB3/ucp.php?i=pm&mode=compose
77-
//nothing to do here
78-
83+
//do nothing
84+
7985
//2 case
8086
//./phpBB3/ucp.php?i=ucp_pm&mode=compose returns
8187
//./phpBB3/ucp.php?i=pm&mode=compose
82-
if (key.includes("ucp.php?i=ucp_pm&mode=compose")) {
88+
else if (key.includes("ucp.php?i=ucp_pm&mode=compose")) {
8389
key = key.split("?")[0].concat("?i=pm&mode=compose");
8490
}
8591

86-
//3 case
92+
//3 case
8793
//./phpBB3/ucp.php?i=pm&mode=compose&action=post&sid=sssssssssssssssssssssssssss returns
8894
//./phpBB3/ucp.php?i=pm&mode=compose
89-
if (key.includes("ucp.php?i=pm&mode=compose&action=post")) {
95+
else if (key.includes("ucp.php?i=pm&mode=compose&action=post")) {
9096
key = key.split("?")[0].concat("?i=pm&mode=compose");
9197
}
9298

93-
//4 case ./phpBB3/ucp.php?i=pm&mode=compose&action=reply&f=xxx&p=yyy
94-
//5 case ./phpBB3/ucp.php?i=pm&mode=compose&action=forward&f=xxx&p=yyy
95-
//6 case ./phpBB3/ucp.php?i=pm&mode=compose&action=quote&f=xxx&p=yyy
96-
if (key.includes("ucp.php?i=pm&mode=compose&action=reply&f=") || key.includes("ucp.php?i=pm&mode=compose&action=forward&f=") || key.includes("ucp.php?i=pm&mode=compose&action=quote&f=")) {
99+
//4 case
100+
//./phpBB3/ucp.php?i=pm&mode=compose&action=reply&f=xxx&p=yyy returns
101+
//./phpBB3/ucp.php?i=pm&mode=compose&action=reply&p=yyy
102+
//5 case
103+
//./phpBB3/ucp.php?i=pm&mode=compose&action=forward&f=xxx&p=yyy returns
104+
//./phpBB3/ucp.php?i=pm&mode=compose&action=forward&p=yyy
105+
//6 case
106+
//./phpBB3/ucp.php?i=pm&mode=compose&action=quote&f=xxx&p=yyy returns
107+
//./phpBB3/ucp.php?i=pm&mode=compose&action=quote&p=yyy
108+
109+
else if (key.includes("ucp.php?i=pm&mode=compose&action=reply&f=") || key.includes("ucp.php?i=pm&mode=compose&action=forward&f=") || key.includes("ucp.php?i=pm&mode=compose&action=quote&f=")) {
97110
var fpos = key.indexOf("&f="),
98111
ppos = key.indexOf("&p=");
99112
if (fpos > -1 && ppos > fpos) {
@@ -110,14 +123,17 @@
110123
//9th case
111124
//./phpBB3/ucp.php?i=pm&mode=compose&action=quote&sid=sssssssssssssssssssssssssss&p=yyy returns
112125
//./phpBB3/ucp.php?i=pm&mode=compose&action=quote&p=yyy
113-
if (key.includes("ucp.php?i=pm&mode=compose&action=reply&sid=") || key.includes("ucp.php?i=pm&mode=compose&action=forward&sid=") || key.includes("ucp.php?i=pm&mode=compose&action=quote&sid=")) {
126+
else if (key.includes("ucp.php?i=pm&mode=compose&action=reply&sid=") || key.includes("ucp.php?i=pm&mode=compose&action=forward&sid=") || key.includes("ucp.php?i=pm&mode=compose&action=quote&sid=")) {
114127
var sipos = key.indexOf("&sid="),
115128
pipos = key.indexOf("&p=");
116129
if (sipos > -1 && pipos > sipos) {
117130
key = key.substr(0, sipos)+key.substr(pipos);
118131
}
119132
}
120-
133+
else {
134+
console.debug("no appropriate message key or pm key found");
135+
}
136+
121137
/**
122138
* Event name to be used for saving content on demand, when user switches pages.
123139
*
@@ -177,7 +193,7 @@
177193
}
178194

179195
/**
180-
* This function will store the current value of the textarea in localStorage (or delete it if the textarea is blank) with a timestamp.
196+
* This function will store the current value of the textarea in localStorage with a timestamp or delete it if the textarea is blank.
181197
*
182198
* It gets triggered by the "type" events on the input and textarea elements,
183199
* @function updateStorage
@@ -239,7 +255,7 @@
239255
* @type {number}
240256
*/
241257
const expiry_time = parseInt(document.getElementById('expiry-time').innerText.trim(), 10);
242-
const dateNow = Math.floor(Date.now() / 1000); // we get milliseconds, so we need to convert to seconds.
258+
const dateNow = Math.floor(Date.now() / 1000); // we get milliseconds, so we need to convert to seconds.
243259
console.debug("Date.now() in seconds is " + dateNow + " and expiry_time is " + expiry_time);
244260

245261
//the if statement for deleting local storage in PM'ing, because expiry_time = 0, it must be fixed
@@ -249,12 +265,11 @@
249265
return;
250266
}
251267
}
252-
253268
// Now remove the local storage on `Submit` — it'll get saved to the database as a post/PM,
254269
// so we don't need it around any longer.
255270
// ... except on Preview. We still want to keep the storage around during preview!
256271
// Kudos to @kylesands for this (gwyneth 20240416)
257-
if (document.activeElement.tagName.toLowerCase() == "input" && document.activeElement.value.toLowerCase() == 'submit') { // Added to only clear on Input button with Submit value
272+
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
258273
message.localStorage.removeItem(key);
259274
message.removeEventListener(unloadEvent, updateStorage);
260275
console.debug("Text submitted (not in preview!); removed from localStorage");

0 commit comments

Comments
 (0)