how to jump to #unread anchor

Post a reply


This question is a means of preventing automated form submissions by spambots.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

If you wish to attach one or more files enter the details below.

Maximum filesize per attachment: 1 MiB.

Expand view Topic review: how to jump to #unread anchor

Re: how to jump to #unread anchor

by oferlaor » Fri Feb 05, 2021 1:41 pm

my proposal for overall_footer.php

Code: Select all

			if( hash == 'unread' ){
				var hash_unread = true; //let's keep in mind we have unread hash
				var postN = 1;
				if ( $("#unread").length > 0) {
					hash= "unread";
				} else {
					$( "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' ){
						hash = "p" + w3lh;
					}
				}
			}

Re: how to jump to #unread anchor

by axew3 » Sun Jan 17, 2021 10:40 am

I've give a re-look into this joke, and fixed working into any user (logged or not).
The unique things that 'intentionally' do not will match with default behavior, because it has been intentionally changed to be this way, is the fact that if an user is not logged in and present a link like this:

Code: Select all

https://subdomain.w3host.com/phpbb3/viewtopic.php?f=2&t=15&e=1&view=unread#unread
the code do not redirect the user to the login page, but to the last post on topic.

Resuming all the procedure, that at moment will not be added into v6 code by default, but that work fine, is as follow:



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.

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

 	var hash = window.location.hash.substr(1);
 
  if( hash == 'unread'){
  	
  	if("{S_USER_LOGGED_IN}" < 1){
  		var usp = window.location.href;
  		w3ns = usp.split('&e=1');
  		document.location.replace(w3ns[0]);
  	}
 
 if("{S_USER_LOGGED_IN}" > 0){ 
  var w3postN = 1000000;
  var w3lh,w3ns,w3nsLowN;

 $( ".unreadpost" ).each(function (e) { 
  var hpid = $(this).attr('id');
  w3ns = hpid.split('p');
   if(  w3ns[1] != 'undefined' ){
   	if(w3ns[1] < w3postN){ // reset to the lower if found
	   w3lh = w3postN = w3ns[1]; // set to actual
	   w3nsLowN = w3ns[1];
	   w3Rhash = "p" + w3nsLowN;
	  }
	 }
 })

 // 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 && typeof w3lh == 'undefined'){
	      w3lh = ns[1];
	     }
	    }
     })

     if( typeof w3lh != 'undefined' ){
      var w3redirToLast = boardU + 'viewtopic.php?p=' + w3lh + '#p' + w3lh;
       if(/adm\/index\.php/ig.exec(w3all_r) == null){
         document.location.replace(w3redirToLast);
       }
      }
     }
     
   } // END	if("{S_USER_LOGGED_IN}" > 0){  
     
  }
 }
} // END if(window.self == window.top){
cheers!

Re: how to jump to #unread anchor

by axew3 » Mon Dec 21, 2020 2:53 pm

i'm taking a look for v6 code and looking to this solution, the short and easy:
https://www.axew3.com/w3/forums/viewtop ... 4932#p4932

this part:

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){
where
// detect when lower and assign
it is clear to me now, that all the joke can be done in this exact point:
why to iterate until the highest, and do not stop to the first?
Isn't it?! This is the solution.

Just a remind for the coming v6 code release, many parts of the v5 code needs to be properly fixed.

Also page-forum.php has been updated, but still not committed. It will be together with all nice fixes coming on v6!

Re: how to jump to #unread anchor

by axew3 » Wed Dec 02, 2020 11:42 pm

This error appear if I don't rename hash variable.
What it mean? What kind of url you try to load to get the error?

Should not because if/when there are no unread, the code should redirect to last one, passing urls like

Code: Select all

https://localhost-subdomain.w3host.com/phpbb3/viewtopic.php?f=2&t=26&e=1&view=unread#unread
AND NOTE that as code is
this line need to match on DOM or as you see, it will return error after, because the code search for unread, and if not found, search for the last one inserted, and if not found again, it make fail the code as before was, so it is mandatory that these elements match on DOM
$( "h3 > a" ).each(function (e) { // need to match on DOM!

The error mean that hash var do not contain a valid value, so when the js search for value based on this it return error. Of course the code can be fixed to avoid this in any case: anyway if no unread found, we should want to redirect to the last one inserted

going to repeat steps to resume:

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.

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

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

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

  var hpid = $(this).attr('id');
  w3ns = hpid.split('p');
   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){
Remember to recompile stale template.
It is tested working into any browser here, so let know if still in trouble

Re: how to jump to #unread anchor

by zawin » Wed Dec 02, 2020 8:34 am

Hello,
thank you for code update. This error appear if I don't rename hash variable.

Image

Re: how to jump to #unread anchor

by axew3 » Tue Dec 01, 2020 12:49 am

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%" })

Top