Page 2 of 3

Re: how to jump to #unread anchor

Posted: Sun Nov 29, 2020 12:20 am
by axew3
the way was easy, but there is a problem:
class unreadpost, when the forum page display, do not exist anymore, because reversing things i see that this happen:
when the overall_header.html added code fire, that reload pointing to wordpress page, and that run because direct link to board detected, at this point, phpBB already processed all the code that then, set as read the post, and then when iframe load in WP page, class unreadpost is not existent anymore on DOM. So at moment, i think that better than the proposed solution, there is no solution.

... a solution ever exist.
So may let overall_header.html to not fire, when unread detected, leaving the page to follow to the overall_footer.html code, where hash then is possible to be grabbed: then get the value, assign it to a var, that when passed (with the redirect that will fire at this point), will scroll the page forum to the iframe position, exactly where it need to be. It seem to me there is no other possible solution (without changing something into phpBB php code that process the part on top of all this, that's really not a convenient reliable solution, even if maybe there is a listener that could be used for the scope). The page forum code need to be changed to accomplish with this, to scroll it to the passed value.

The problem is that this solution let the phpbb forum display for a while, because the js redirect done on footer and not header.

Re: how to jump to #unread anchor

Posted: Sun Nov 29, 2020 10:32 am
by axew3
I've try out all the thing, since it is the unique way to resolve this issue:
It scroll to last post, but should instead scroll to, the last unread post, which could be not the last one inserted on thread, when there are more new replies? Do not know how it work, not checked deeply in true, so i will check asap how phpBB execute this task, and how to mimic it.
subsequent my assertion:
page-forum need to be changed to accomplish with this
not true.

This is the solution that mimic, may that appear little complicate, but it is not, and works fine.
I will not go to add at moment into online V5 code, since it is an on-fly working code, that i will check on how to add properly into next V6 code, may obscuring with a trick the part where the page reload happen, and shortening code lines, since instructions can be unified. This is extended, to easily understand how the joke work. And it work fine.

Here we go with snippet example

on the js overall_header.html added code, just after
// END MANDATORY CHANGES line,
ADD this:

Code: Select all

 if(/view=unread#unread/ig.exec(window.location.href) !== null && /viewtopic.php\?/ig.exec(window.location.href) !== null)
 { 
 	 var w3allUnreadTopic = 1;
 }
then change/replace this line:
document.location.replace(href0);
into this:

Code: Select all

    if(typeof w3allUnreadTopic == 'undefined'){
     document.location.replace(href0);
    }
Save.
(so avoid code to redirect here, if unread detected: let follow to the overall_footer js code, redirect after, when grabbed what needed (read previous post to know why))

Now open overall_footer.html
on added js code, just after this comment:

Code: Select all

///////////////////////////////////////////////////////////////////////////
// w3all UPDATES for phpBB events
add the follow:

Code: Select all

if(window.self == window.top){
 if(typeof w3allUnreadTopic != 'undefined'){
  var hash = window.location.hash.substr(1);
 if( hash == 'unread' ){

  var w3postN = 1000000; // it's assumed that will never exists 1000000 unread posts x topic's page, isn't it?
  var w3lh,w3ns,w3Rhash;
  
 $( ".unreadpost" ).each(function (e) {

  var hpid = $(this).attr('id');
  w3ns = hpid.split('p');
  
   if(  w3ns[1] != 'undefined' ){
   	if(w3ns[1] < w3postN){  // detect when lower and assign
	   w3lh = w3postN = w3ns[1];
	   w3Rhash = "p" + w3lh;
	  }
	 }
 })

   if(  w3Rhash != 'undefined' ){ 
    // build url and redirect now, with common phpBB url, that point to the right post/hash on thread
    // Ex: https://localhost-subdomain.w3host.com/phpbb3/viewtopic.php?p=138#p138
   	var w3redirToUnread = boardU + 'viewtopic.php?p=' + w3lh + '#' + w3Rhash;
   	document.location.replace(w3redirToUnread);
   }
}
}
} // END if(window.self == window.top){
Save and remember to recompile stale template
This is it

[EDITED]

Re: how to jump to #unread anchor

Posted: Mon Nov 30, 2020 3:38 pm
by zawin
Hello,
I found two issues with latest code snippet:
1) if I loading forum topic page with this link /viewtopic.php?f=16&t=45554&view=unread#unread and in this topic have not any unread posts then page tries to redirect to this page: /viewtopic.php?p=undefined#undefined
2) I had to a renamed hash variable to hash1 variable because some conflict appears in the console, and code doesn't work.

Thank you for your help.

Re: how to jump to #unread anchor

Posted: Mon Nov 30, 2020 4:48 pm
by axew3
Ok, thank for report, let check, i will reply with the easy and improved solution asap

Re: how to jump to #unread anchor

Posted: Mon Nov 30, 2020 9:20 pm
by axew3
To me, it was not throwing any error, anyway, when no unread post class found, due to a subsequent click into those kind of unread links, may clicked into notification email, after the topic already visited, what happen was that the code do not follow on redirect.
To complete the task, and make it redirect even when no unread found, redirecting to the last inserted, that obviously is the right one we want to be redirected to in this case, the complete code is little different, using both above snippets like this:

overall_header.html, leave code as is ( as explained here https://www.axew3.com/w3/forums/viewtop ... 4932#p4932 )

while remove completely the previous code into
overall_footer.html, and as before, just after this code comment:

Code: Select all

///////////////////////////////////////////////////////////////////////////
// w3all UPDATES for phpBB events
add this code
(and do you remember the line to change into very first snippet where it say need to match on DOM! ? Change also here like you did before, this line $( "h3 > a" ).each(function (e) { // need to match on DOM!
that need to match to elements a inside h3 as above:

Code: Select all

if(window.self == window.top){

 if(typeof w3allUnreadTopic != 'undefined'){
 	
 	var hash = window.location.hash.substr(1);
 
  if( hash == 'unread' ){

  var w3postN = 1000000; // it's assumed that will be never 1000000 posts x page, isn't it?
  var w3lh,w3ns,w3nsLowN;

  $( ".unreadpost" ).each(function (e) { 

  var hpid = $(this).attr('id');
  w3ns = hpid.split('p');
      	console.log(w3ns[1]);
   if(  w3ns[1] != 'undefined' ){
   	if(w3ns[1] < w3postN){
   //console.log('w3ns[1] AND w3postN -> '+w3ns[1]+' - '+w3postN);
	   w3lh = w3postN = w3ns[1];
	   w3nsLowN = w3ns[1];
	   w3Rhash = "p" + w3lh;
	  }
	 }
   //console.log('hash is ' + hash);
 })
 
 // https://localhost-subdomain.w3host.com/phpbb3/viewtopic.php?p=138#p138
   if( typeof w3ns != 'undefined' && typeof w3Rhash != 'undefined' ){ 
   	var redirToUnread = boardU + 'viewtopic.php?p=' + w3lh + '#' + w3Rhash;
   	document.location.replace(redirToUnread);
   } else {
 	   var postN = 1;
     $( "h3 > a" ).each(function (e) { // need to match on DOM!
       ns = this.href.split('#p'); 
      if( typeof ns != 'undefined' && /viewtopic.php\?p=/ig.exec(this.href) != null ){
   	   if(ns[1] > postN){
	      w3lh = ns[1];
	     }
	    }
     })

     if( typeof w3lh != 'undefined' ){
      var w3redirToLast = boardU + 'viewtopic.php?p=' + w3lh + '#p' + w3lh;
        var w3all_r = w3all0Normalize_phpBBUrl(w3redirToLast);
       if(/adm\/index\.php/ig.exec(w3all_r) == null){
       var hrefEn = window.btoa(unescape(encodeURIComponent(w3all_r)));
        var hre =  wordpress_url_page_f + '/?'+ w3all_custom_wp_w3fancyurl + '=' + hrefEn;
         document.location.replace(hre);
       }
      }
     }
  }
 }
} // END if(window.self == window.top){
it still lack of a sort of trick, that should obscure things, where time latency until redirect happen

Re: how to jump to #unread anchor

Posted: Tue Dec 01, 2020 12:49 am
by axew3
p.s at very late night

to obscure phpBB content before the redirect happen as fast example (could be done better) :

on added js code, just after this line:

Code: Select all

  if( hash == 'unread' ){
add the follow:

Code: Select all

 $( "body" ).prepend( "<div class=\"preUnreadRedirectBG\"></div>" );
 $(".preUnreadRedirectBG").css({ "position":"fixed","top":"0%","bottom":"0%","left":"0%","right":"0%","background": "rgba(0,0,0,1)","z-index": "99999","width":"100%" })