2323
2424 // If there is no localStorage support, give up
2525 if ( ! message . localStorage ) {
26- console . debug ( "no local storage support" ) ;
26+ console . debug ( "[phpBB3 postlocalstorage] no local storage support" ) ;
2727 return ;
2828 }
2929 /**
3333 const textarea = document . querySelector ( 'textarea[name="message"]' ) ;
3434 // no point in being around if this is nil; also: avoids crashing below (gwyneth 20220303)
3535 if ( ! textarea ) {
36- console . debug ( "no phpBB3 content body textarea found, skipping" ) ;
36+ console . debug ( "[phpBB3 postlocalstorage] no phpBB3 content body textarea found, skipping" ) ;
3737 return ;
3838 }
3939 /**
4242 */
4343 const subject = document . querySelector ( 'input[name="subject"]' ) ;
4444 if ( ! subject ) {
45- console . debug ( "no phpBB3 subject line found" ) ;
45+ console . debug ( "[phpBB3 postlocalstorage] no phpBB3 subject line found" ) ;
4646 // I have not decided what to do in this case! Possibly just:
4747 // subject = "(no subject)";
4848 }
5656 // @see https://www.phpbb.com/customise/db/extension/postlocalstorage/support/topic/246616?p=877489#p877489
5757 //if key.includes (viewforum.php) then exit
5858 if ( key . includes ( "viewforum.php" ) ) {
59- console . debug ( "viewforum, no message box" ) ;
59+ // console.debug("[phpBB3 postlocalstorage] viewforum, no message box");
6060 return ;
6161 }
6262
63- // POSTING
64- //possible key formats
65- //./phpBB3/posting.php?mode=edit&p=xxxxx#preview#preview#preview#preview .......
66- //./phpBB3/posting.php?mode=quote&p=xxxxx#preview#preview#preview#preview .......
67- //./phpBB3/posting.php?mode=reply&t=yyyyy#preview#preview#preview#preview .......
68- //Remove all "#preview" strings at the end
63+ // ## POSTING
64+ // possible key formats
65+ // ./phpBB3/posting.php?mode=edit&p=xxxxx#preview#preview#preview#preview .......
66+ // ./phpBB3/posting.php?mode=quote&p=xxxxx#preview#preview#preview#preview .......
67+ //. /phpBB3/posting.php?mode=reply&t=yyyyy#preview#preview#preview#preview .......
68+ // Remove all "#preview" strings at the end
6969 else if ( key . includes ( "posting.php?mode=" ) ) {
7070 if ( key . endsWith ( "#preview" ) ) {
7171 var count_hash = key . split ( "#" ) . length - 1 ;
7575 }
7676 }
7777
78- // PM'ing
79- //possible key formats
78+ // ## PM'ing
79+ // possible key formats
8080
81- //1st case
82- //./phpBB3/ucp.php?i=pm&mode=compose
83- //do nothing
81+ // - 1st case
82+ // ./phpBB3/ucp.php?i=pm&mode=compose
83+ // do nothing
8484
85- //2nd case
86- //./phpBB3/ucp.php?i=ucp_pm&mode=compose returns
87- //./phpBB3/ucp.php?i=pm&mode=compose
85+ // - 2nd case
86+ // ./phpBB3/ucp.php?i=ucp_pm&mode=compose returns
87+ // ./phpBB3/ucp.php?i=pm&mode=compose
8888 else if ( key . includes ( "ucp.php?i=ucp_pm&mode=compose" ) ) {
8989 key = key . split ( "?" ) [ 0 ] . concat ( "?i=pm&mode=compose" ) ;
9090 }
9191
92- //3rd case
93- //./phpBB3/ucp.php?i=pm&mode=compose&action=post&sid=sssssssssssssssssssssssssss returns
94- //./phpBB3/ucp.php?i=pm&mode=compose
92+ // - 3rd case
93+ // ./phpBB3/ucp.php?i=pm&mode=compose&action=post&sid=sssssssssssssssssssssssssss returns
94+ // ./phpBB3/ucp.php?i=pm&mode=compose
9595 else if ( key . includes ( "ucp.php?i=pm&mode=compose&action=post" ) ) {
9696 key = key . split ( "?" ) [ 0 ] . concat ( "?i=pm&mode=compose" ) ;
9797 }
9898
99- //4th 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- //5th 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- //6th 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=" ) ) {
99+ // - 4th 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+ // - 5th 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+ // - 6th 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+ else if (
109+ key . includes ( "ucp.php?i=pm&mode=compose&action=reply&f=" )
110+ || key . includes ( "ucp.php?i=pm&mode=compose&action=forward&f=" )
111+ || key . includes ( "ucp.php?i=pm&mode=compose&action=quote&f=" ) ) {
110112 var fpos = key . indexOf ( "&f=" ) ,
111113 ppos = key . indexOf ( "&p=" ) ;
112114 if ( fpos > - 1 && ppos > fpos ) {
113115 key = key . substring ( 0 , fpos ) + key . substring ( ppos ) ;
114116 }
115117 }
116118
117- //7th case
118- //./phpBB3/ucp.php?i=pm&mode=compose&action=reply&sid=sssssssssssssssssssssssssss&p=yyy returns
119- //./phpBB3/ucp.php?i=pm&mode=compose&action=reply&p=yyy
120- //8th case
121- //./phpBB3/ucp.php?i=pm&mode=compose&action=forward&sid=sssssssssssssssssssssssssss&p=yyy returns
122- //./phpBB3/ucp.php?i=pm&mode=compose&action=forward&p=yyy
123- //9th case
124- //./phpBB3/ucp.php?i=pm&mode=compose&action=quote&sid=sssssssssssssssssssssssssss&p=yyy returns
125- //./phpBB3/ucp.php?i=pm&mode=compose&action=quote&p=yyy
126- else if ( key . includes ( "ucp.php?i=pm&mode=compose&action=reply&sid=" )
119+ // - 7th case
120+ // ./phpBB3/ucp.php?i=pm&mode=compose&action=reply&sid=sssssssssssssssssssssssssss&p=yyy returns
121+ // ./phpBB3/ucp.php?i=pm&mode=compose&action=reply&p=yyy
122+ // - 8th case
123+ // ./phpBB3/ucp.php?i=pm&mode=compose&action=forward&sid=sssssssssssssssssssssssssss&p=yyy returns
124+ // ./phpBB3/ucp.php?i=pm&mode=compose&action=forward&p=yyy
125+ // - 9th case
126+ // ./phpBB3/ucp.php?i=pm&mode=compose&action=quote&sid=sssssssssssssssssssssssssss&p=yyy returns
127+ // ./phpBB3/ucp.php?i=pm&mode=compose&action=quote&p=yyy
128+ else if (
129+ key . includes ( "ucp.php?i=pm&mode=compose&action=reply&sid=" )
127130 || key . includes ( "ucp.php?i=pm&mode=compose&action=forward&sid=" )
128- || key . includes ( "ucp.php?i=pm&mode=compose&action=quote&sid=" ) ) {
131+ || key . includes ( "ucp.php?i=pm&mode=compose&action=quote&sid=" )
132+ ) {
129133 var sipos = key . indexOf ( "&sid=" ) ,
130134 pipos = key . indexOf ( "&p=" ) ;
131135 if ( sipos > - 1 && pipos > sipos ) {
132136 key = key . substring ( 0 , sipos ) + key . substring ( pipos ) ;
133137 }
134138 }
135139 else {
136- console . debug ( "no appropriate message key or pm key found" ) ;
140+ console . debug ( "[phpBB3 postlocalstorage] no appropriate post message key or PM key found" ) ;
137141 }
138142
139143 /**
172176 if ( Date . now ( ) - data . timestamp > FRESHNESS_INTERVAL ) {
173177 // Remove stale data. A new item will be added as soon as the user clicks a key.
174178 message . localStorage . removeItem ( key ) ;
175- console . debug ( "stale data found; removing from localStorage" ) ;
179+ console . debug ( "[phpBB3 postlocalstorage] stale data found; removing from localStorage" ) ;
176180 return ;
177181 }
178182 // Data is still considered "fresh" enough, so we replace the value of the textarea with
179183 // what we have on the localStorage.
180184 textarea . value = data ?. content ?? "" ;
181185 // same checking for subject.
182186 subject . value = data ?. subject ?? "" ;
183- console . debug ( "textarea content successfully restored" ) ;
187+ console . debug ( "[phpBB3 postlocalstorage] textarea content successfully restored" ) ;
184188 } else {
185189 // We don't know if the existing data is stale or not, since it comes from pre-1.1.0 times.
186190 // So, upgrade object to the new format, i.e. add a timestamp to existing content.
205209 // Note: if the visibilitychange event is being used, one should check to see if the visibilityState
206210 // is 'hidden' or 'visible'; but we're going to save to storage in both cases.
207211 if ( message . visibilityState === "hidden" ) {
208- console . debug ( "Saving existing text before moving tab to background" ) ;
212+ console . debug ( "[phpBB3 postlocalstorage] Saving existing text before moving tab to background" ) ;
209213 }
210214 if ( textarea . value ) {
211215 item = JSON . stringify ( { "content" : textarea . value , "subject" : ( subject ?. value ?? "" ) , "timestamp" : Date . now ( ) } ) ;
212216 message . localStorage . setItem ( key , item ) ;
213- console . debug ( "Existing subject & content saved to localStorage" ) ;
217+ // console.debug("[phpBB3 postlocalstorage] Existing subject & content saved to localStorage");
214218 } else {
215219 message . localStorage . removeItem ( key ) ;
216- console . debug ( "Empty textarea -- remove existing content & subject in localStorage" ) ;
220+ console . debug ( "[phpBB3 postlocalstorage] Empty textarea -- remove existing content & subject in localStorage" ) ;
217221 }
218222 }
219223 // When the user presses a key just *once* inside the textarea, run the storage function when the page is unloaded.
262266 */
263267 const expiryTime = parseInt ( document . getElementById ( 'expiry-time' ) ?. innerText . trim ( ) , 10 ) ;
264268 const dateNow = Math . floor ( Date . now ( ) / 1000 ) ; // we get milliseconds, so we need to convert to seconds.
265- console . debug ( "Date.now() in seconds is " + dateNow + " and expiryTime is " + expiryTime ) ;
269+ // console.debug("[phpBB3 postlocalstorage] ` Date.now()` in seconds is " + dateNow + " and ` expiryTime` is " + expiryTime);
266270
267271 //the if statement for deleting local storage in PM'ing, because expiryTime = 0, it must be fixed
268272 //if (!key.includes("ucp.php")) {
282286 // Kudos to @kylesands for this (gwyneth 20240416)
283287 // Fixed lack of translation issue by using the 'name' value instead, but if either does
284288 // 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
289+ if (
290+ document . activeElement . tagName ?. toLowerCase ( ) == "input"
291+ && document . activeElement . name ?. toLowerCase ( ) == "post"
292+ ) { // Added to only clear on Input button with Submit value
286293 message . localStorage . removeItem ( key ) ;
287294 message . removeEventListener ( unloadEvent , updateStorage ) ;
288- console . debug ( "Text submitted (not in preview!); removed from localStorage" ) ;
295+ // console.debug("[phpBB3 postlocalstorage] Text submitted (not in preview!); removed from localStorage");
289296 }
290297 }
291298 ) ;
292- } ) ( this , this . document ) ;
299+ } ) ( this , this . document ) ;
0 commit comments