|
51 | 51 | * @type {string} |
52 | 52 | */ |
53 | 53 | 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. |
55 | 55 | // Kudos to @gvp9000 and for the fix below. (gwyneth 20240414) |
56 | 56 | // @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 | + } |
57 | 62 |
|
58 | 63 | // POSTING |
59 | 64 | //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 ....... |
61 | 66 | //./phpBB3/posting.php?mode=quote&p=xxxxx#preview#preview#preview#preview ....... |
62 | 67 | //./phpBB3/posting.php?mode=reply&t=yyyyy#preview#preview#preview#preview ....... |
63 | 68 | //Remove all "#preview" strings at the end |
64 | | - if (key.includes("posting.php?mode=")) { |
| 69 | + else if (key.includes("posting.php?mode=")) { |
65 | 70 | if (key.endsWith("#preview")) { |
66 | 71 | var count_hash = key.split("#").length - 1; |
67 | 72 | for (let i = 0; i < count_hash; i++) { |
|
73 | 78 | // PM'ing |
74 | 79 | //possible key formats |
75 | 80 |
|
76 | | - //1 case |
| 81 | + //1 case |
77 | 82 | //./phpBB3/ucp.php?i=pm&mode=compose |
78 | | - //nothing to do here |
| 83 | + //do nothing |
79 | 84 |
|
80 | | - //2 case |
| 85 | + //2 case |
81 | 86 | //./phpBB3/ucp.php?i=ucp_pm&mode=compose returns |
82 | 87 | //./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"); |
85 | 90 | } |
86 | 91 |
|
87 | 92 | //3 case |
88 | 93 | //./phpBB3/ucp.php?i=pm&mode=compose&action=post&sid=sssssssssssssssssssssssssss returns |
89 | 94 | //./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"); |
92 | 97 | } |
93 | 98 |
|
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 |
104 | 108 |
|
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 |
107 | 119 | //./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 |
110 | 122 | //./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 |
113 | 125 | //./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 | + } |
120 | 134 | } |
121 | | - |
| 135 | + else { |
| 136 | + console.debug("no appropriate message key or pm key found"); |
| 137 | + } |
| 138 | + |
122 | 139 | /** |
123 | 140 | * Event name to be used for saving content on demand, when user switches pages. |
124 | 141 | * |
|
178 | 195 | } |
179 | 196 |
|
180 | 197 | /** |
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. |
182 | 199 | * |
183 | 200 | * It gets triggered by the "type" events on the input and textarea elements, |
184 | 201 | * @function updateStorage |
|
242 | 259 | const expiry_time = parseInt(document.getElementById('expiry-time').innerText.trim(), 10); |
243 | 260 | const dateNow = Math.floor(Date.now() / 1000); // we get milliseconds, so we need to convert to seconds. |
244 | 261 | 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) { |
246 | 266 | // We won't clear anything if the session already expired, so return. |
247 | 267 | return; |
| 268 | + } |
248 | 269 | } |
249 | | - |
250 | 270 | // Now remove the local storage on `Submit` — it'll get saved to the database as a post/PM, |
251 | 271 | // so we don't need it around any longer. |
252 | 272 | // ... except on Preview. We still want to keep the storage around during preview! |
253 | 273 | // 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 |
255 | 275 | message.localStorage.removeItem(key); |
256 | 276 | message.removeEventListener(unloadEvent, updateStorage); |
257 | 277 | console.debug("Text submitted (not in preview!); removed from localStorage"); |
|
0 commit comments