Skip to content

Commit a11002c

Browse files
Merge pull request #6 from gvp9000/master
Update postlocalstorage_functions.js
2 parents 55690f9 + cdb11cf commit a11002c

File tree

1 file changed

+57
-37
lines changed

1 file changed

+57
-37
lines changed

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

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,22 @@
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+
//if key.includes (viewforum.php) then exit
58+
if (key.includes("viewforum.php")) {
59+
console.debug("viewforum, no message box");
60+
return;
61+
}
5762

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++) {
@@ -73,52 +78,64 @@
7378
// PM'ing
7479
//possible key formats
7580

76-
//1 case
81+
//1 case
7782
//./phpBB3/ucp.php?i=pm&mode=compose
78-
//nothing to do here
83+
//do nothing
7984

80-
//2 case
85+
//2 case
8186
//./phpBB3/ucp.php?i=ucp_pm&mode=compose returns
8287
//./phpBB3/ucp.php?i=pm&mode=compose
83-
if (key.includes("ucp.php?i=ucp_pm&mode=compose")) {
84-
key = key.split("?")[0].concat("?i=pm&mode=compose");
88+
else if (key.includes("ucp.php?i=ucp_pm&mode=compose")) {
89+
key = key.split("?")[0].concat("?i=pm&mode=compose");
8590
}
8691

8792
//3 case
8893
//./phpBB3/ucp.php?i=pm&mode=compose&action=post&sid=sssssssssssssssssssssssssss returns
8994
//./phpBB3/ucp.php?i=pm&mode=compose
90-
if (key.includes("ucp.php?i=pm&mode=compose&action=post")) {
91-
key = key.split("?")[0].concat("?i=pm&mode=compose");
95+
else if (key.includes("ucp.php?i=pm&mode=compose&action=post")) {
96+
key = key.split("?")[0].concat("?i=pm&mode=compose");
9297
}
9398

94-
//4 case ./phpBB3/ucp.php?i=pm&mode=compose&action=reply&f=xxx&p=yyy
95-
//5 case ./phpBB3/ucp.php?i=pm&mode=compose&action=forward&f=xxx&p=yyy
96-
//6 case ./phpBB3/ucp.php?i=pm&mode=compose&action=quote&f=xxx&p=yyy
97-
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=")) {
98-
var fpos = key.indexOf("&f="),
99-
ppos = key.indexOf("&p=");
100-
if (fpos > -1 && ppos > fpos) {
101-
key = key.substring(0, fpos) + key.substring(ppos);
102-
}
103-
}
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
104108

105-
//7 case
106-
//./phpBB3/ucp.php?i=pm&mode=compose&action=reply&sid=sssssssssssssssssssssssssss&p=yyy returns
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=")) {
110+
var fpos = key.indexOf("&f="),
111+
ppos = key.indexOf("&p=");
112+
if (fpos > -1 && ppos > fpos) {
113+
key = key.substr(0, fpos) + key.substr(ppos);
114+
}
115+
}
116+
117+
//7 case
118+
//./phpBB3/ucp.php?i=pm&mode=compose&action=reply&sid=sssssssssssssssssssssssssss&p=yyy returns
107119
//./phpBB3/ucp.php?i=pm&mode=compose&action=reply&p=yyy
108-
//8th case
109-
//./phpBB3/ucp.php?i=pm&mode=compose&action=forward&sid=sssssssssssssssssssssssssss&p=yyy returns
120+
//8th case
121+
//./phpBB3/ucp.php?i=pm&mode=compose&action=forward&sid=sssssssssssssssssssssssssss&p=yyy returns
110122
//./phpBB3/ucp.php?i=pm&mode=compose&action=forward&p=yyy
111-
//9th case
112-
//./phpBB3/ucp.php?i=pm&mode=compose&action=quote&sid=sssssssssssssssssssssssssss&p=yyy returns
123+
//9th case
124+
//./phpBB3/ucp.php?i=pm&mode=compose&action=quote&sid=sssssssssssssssssssssssssss&p=yyy returns
113125
//./phpBB3/ucp.php?i=pm&mode=compose&action=quote&p=yyy
114-
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=")) {
115-
var sipos = key.indexOf("&sid="),
116-
pipos = key.indexOf("&p=");
117-
if (sipos > -1 && pipos > sipos) {
118-
key = key.substring(0, sipos) + key.substring(pipos);
119-
}
126+
else if (key.includes("ucp.php?i=pm&mode=compose&action=reply&sid=")
127+
|| key.includes("ucp.php?i=pm&mode=compose&action=forward&sid=")
128+
|| key.includes("ucp.php?i=pm&mode=compose&action=quote&sid=")) {
129+
var sipos = key.indexOf("&sid="),
130+
pipos = key.indexOf("&p=");
131+
if (sipos > -1 && pipos > sipos) {
132+
key = key.substr(0, sipos) + key.substr(pipos);
133+
}
120134
}
121-
135+
else {
136+
console.debug("no appropriate message key or pm key found");
137+
}
138+
122139
/**
123140
* Event name to be used for saving content on demand, when user switches pages.
124141
*
@@ -178,7 +195,7 @@
178195
}
179196

180197
/**
181-
* This function will store the current value of the textarea in localStorage (or delete it if the textarea is blank) with a timestamp.
198+
* This function will store the current value of the textarea in localStorage with a timestamp or delete it if the textarea is blank.
182199
*
183200
* It gets triggered by the "type" events on the input and textarea elements,
184201
* @function updateStorage
@@ -242,16 +259,19 @@
242259
const expiry_time = parseInt(document.getElementById('expiry-time').innerText.trim(), 10);
243260
const dateNow = Math.floor(Date.now() / 1000); // we get milliseconds, so we need to convert to seconds.
244261
console.debug("Date.now() in seconds is " + dateNow + " and expiry_time is " + expiry_time);
245-
if (dateNow > expiry_time) {
262+
263+
//the if statement for deleting local storage in PM'ing, because expiry_time = 0, it must be fixed
264+
if (!key.includes("ucp.php")) {
265+
if (dateNow > expiry_time) {
246266
// We won't clear anything if the session already expired, so return.
247267
return;
268+
}
248269
}
249-
250270
// Now remove the local storage on `Submit` — it'll get saved to the database as a post/PM,
251271
// so we don't need it around any longer.
252272
// ... except on Preview. We still want to keep the storage around during preview!
253273
// Kudos to @kylesands for this (gwyneth 20240416)
254-
if (document.activeElement.tagName.toLowerCase() == "input" && document.activeElement.value.toLowerCase() == 'submit') { // Added to only clear on Input button with Submit value
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
255275
message.localStorage.removeItem(key);
256276
message.removeEventListener(unloadEvent, updateStorage);
257277
console.debug("Text submitted (not in preview!); removed from localStorage");

0 commit comments

Comments
 (0)