|
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 | | - |
| 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 | + |
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++) { |
68 | 73 | key = key.substring(0, key.lastIndexOf('#')); |
69 | 74 | } |
70 | 75 | } |
71 | 76 | } |
| 77 | + |
72 | 78 | // PM'ing |
73 | 79 | //possible key formats |
74 | | - |
| 80 | + |
75 | 81 | //1 case |
76 | 82 | //./phpBB3/ucp.php?i=pm&mode=compose |
77 | | - //nothing to do here |
78 | | - |
| 83 | + //do nothing |
| 84 | + |
79 | 85 | //2 case |
80 | 86 | //./phpBB3/ucp.php?i=ucp_pm&mode=compose returns |
81 | 87 | //./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")) { |
83 | 89 | key = key.split("?")[0].concat("?i=pm&mode=compose"); |
84 | 90 | } |
85 | 91 |
|
86 | | - //3 case |
| 92 | + //3 case |
87 | 93 | //./phpBB3/ucp.php?i=pm&mode=compose&action=post&sid=sssssssssssssssssssssssssss returns |
88 | 94 | //./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")) { |
90 | 96 | key = key.split("?")[0].concat("?i=pm&mode=compose"); |
91 | 97 | } |
92 | 98 |
|
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=")) { |
97 | 110 | var fpos = key.indexOf("&f="), |
98 | 111 | ppos = key.indexOf("&p="); |
99 | 112 | if (fpos > -1 && ppos > fpos) { |
|
110 | 123 | //9th case |
111 | 124 | //./phpBB3/ucp.php?i=pm&mode=compose&action=quote&sid=sssssssssssssssssssssssssss&p=yyy returns |
112 | 125 | //./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=")) { |
114 | 127 | var sipos = key.indexOf("&sid="), |
115 | 128 | pipos = key.indexOf("&p="); |
116 | 129 | if (sipos > -1 && pipos > sipos) { |
117 | 130 | key = key.substr(0, sipos)+key.substr(pipos); |
118 | 131 | } |
119 | 132 | } |
120 | | - |
| 133 | + else { |
| 134 | + console.debug("no appropriate message key or pm key found"); |
| 135 | + } |
| 136 | + |
121 | 137 | /** |
122 | 138 | * Event name to be used for saving content on demand, when user switches pages. |
123 | 139 | * |
|
177 | 193 | } |
178 | 194 |
|
179 | 195 | /** |
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. |
181 | 197 | * |
182 | 198 | * It gets triggered by the "type" events on the input and textarea elements, |
183 | 199 | * @function updateStorage |
|
239 | 255 | * @type {number} |
240 | 256 | */ |
241 | 257 | 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. |
243 | 259 | console.debug("Date.now() in seconds is " + dateNow + " and expiry_time is " + expiry_time); |
244 | 260 |
|
245 | 261 | //the if statement for deleting local storage in PM'ing, because expiry_time = 0, it must be fixed |
|
249 | 265 | return; |
250 | 266 | } |
251 | 267 | } |
252 | | - |
253 | 268 | // Now remove the local storage on `Submit` — it'll get saved to the database as a post/PM, |
254 | 269 | // so we don't need it around any longer. |
255 | 270 | // ... except on Preview. We still want to keep the storage around during preview! |
256 | 271 | // 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 |
258 | 273 | message.localStorage.removeItem(key); |
259 | 274 | message.removeEventListener(unloadEvent, updateStorage); |
260 | 275 | console.debug("Text submitted (not in preview!); removed from localStorage"); |
|
0 commit comments