R3v hover-tips for Chrome - v0.2 - Updated 3/2/13

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fourbanger
    Grease Monkey
    • Jul 2011
    • 335

    #1

    R3v hover-tips for Chrome - v0.2 - Updated 3/2/13

    I've been working on a hover-preview Tampermonkey script. It's always bugged me that r3v doesn't even have title attribute tooltips.




    You can has. Just install Tampermonkey and paste it in.



    Version 0.2 - 3/2/13 - Features added:
    • Smart hover placement
    • Image scaling
    • Ability to flip through current page of posts (N and P keys)
    • "Last post" view (hover over the arrow image)


    Code:
    // ==UserScript==
    // @name       r3vlimited hover tips
    // @namespace  http://www.r3vlimited.com/
    // @version    0.2
    // @description  does neat things
    // @match      http://www.r3vlimited.com/board/*
    // @copyright  2013+, Fourbanger
    // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
    // ==/UserScript==
    
    var scaleFactor = .75;
    var delay = 375;
    
    $(document).ready(function(){
    	var html = '\
    	<div id="hoverBoundary">\
    		<div id="hoverContainer">\
    		</div>\
    	<div>';
    	var styles = '<style>\
    		#hoverBoundary {\
    			-webkit-touch-callout: none;\
    			-webkit-user-select: none;\
    			user-select: none;\
    			pointer-events: none;\
    			position: fixed;\
    			top: 0;\
    			left: 0;\
    			height: auto;\
    			width: 50%;\
    			border-radius: 25px;\
    			display: none;\
    			z-index: 999;\
    			/*border: 1px solid red;*/\
    		}\
    		#hoverContainer{\
    			width: '+ ((1/scaleFactor)*100) +'%;\
    			-webkit-transform: scale(' + scaleFactor + ');\
    			-webkit-transform-origin: 0 0 0;\
    		}\
    		#hoverContainer table {\
    			table-layout: fixed;\
    			overflow: hidden;\
    		}\
    		#hoverContainer table td:first-of-type{\
    			width: 20%;\
    			overflow: hidden;\
    		}\
    		#hoverContainer .bigusername {\
    			font-size: 115%;\
    		}\
    		#hoverContainer .page > div,\
    		#hoverContainer .page > div > div {\
    			padding: 0 !important;\
    		}\
    		#hoverContainer .page img {\
    			max-width: 100%;\
    		}\
    	</style>';
      $('body').append(html);
    	$('head').append(styles);
    	var hoverBoundary = $('#hoverBoundary');
    	var hoverContainer = $('#hoverContainer');
    	
    	$(document).mousemove(function(event){
    		mouseX = event.pageX;
      	mouseY = event.pageY;
        if ($(hoverBoundary).is(':visible')) {
    			positionHover();
        }
     	});
    
    	$(document).on('keyup', function(event){
    		if ($(hoverBoundary).is(':visible')) {
    			event.preventDefault();
    			switch (event.which) {
    				case 78:
    					if ($(hoverContainer).find('> div:visible').next().length > 0 && !$(hoverContainer).find('div').is(':animated')) {
    						$(hoverContainer).find('> div:visible').next().slideDown();
    						$(hoverContainer).find('> div:visible:first').slideUp();
    					}
    				break;
    				case 80:
    					if ($(hoverContainer).find('> div:visible').prev().length > 0 && !$(hoverContainer).find('div').is(':animated')) {
    						$(hoverContainer).find('> div:visible').prev().slideDown();
    						$(hoverContainer).find('> div:visible:last').slideUp();
    					}
    				break;
    			}
    		}
    	});
    
    	function positionHover(){
    		var scrollPos = $('body').scrollTop();
    		if ((mouseY - scrollPos) + ($(hoverBoundary).height() * scaleFactor) > $(window).height()) {
    			var top = $(window).height() - ($(hoverBoundary).height() * scaleFactor);
    			if (top < 0) var top = 0;
    		}
    		else {
    			var percentY = (mouseY - scrollPos) / $(window).height();
    			var offsetY = percentY * $(hoverBoundary).height() * scaleFactor;
    			var top = Math.round((mouseY - scrollPos) - offsetY);
    		}
    		var percentX = mouseX / $(window).width();
    		var offsetX = percentX * $(hoverBoundary).width();
    		var left = Math.round(mouseX - offsetX);
      	$(hoverBoundary).css({'top':top, 'left':left});
    	}
    	
    	var hoverDelay = null;
    	var request;
    	$('a[href*="showthread.php"]').not('[href*="page="]').hover(function(){
    		var context = $(this);
    		hoverDelay = setTimeout(function(){
    			var href = $(context).attr('href');
    			var last = false;
    			if (href.indexOf('#post') !== -1 || href.indexOf('goto=newpost') !== -1) var last = true;
    			/*var post = href.match(/\#(.*)/)[1];*/
    			request = $.ajax({
    	      	type: "GET",
    	      	url: href,
    	      	dataType: 'html',
    	      	success: function(data){
    						$(hoverContainer).empty();
    						var scripts = '<script>function vbmenu_register(){return null;}</script>'
    	        	var content = scripts + $(data).filter('#posts').html().replace('<div id="lastpost"></div>', '');
    						$(hoverContainer).html(content);
    						if (!last) $(hoverContainer).find('> div:not(:first-of-type)').hide();
    						else $(hoverContainer).find('> div:not(:last-of-type)').hide();
    						$(hoverBoundary).show().promise().done(function(){
    							positionHover();
    						});
    						$(hoverContainer).find('img').load(function(){positionHover();});
    					}
    	  	});
    		}, delay);
    	}, function(){
    		if (request) request.abort();
    		clearTimeout(hoverDelay);
    		$(hoverBoundary).hide();
    	});
    });
    Last edited by Fourbanger; 03-03-2013, 10:59 PM.
  • slammin.e28
    שמע ישראל
    • May 2010
    • 12054

    #2
    One complaint....you had to use the thread with that...thing... in it.
    1974.5 Jensen Healey : 2003 330i/5

    Comment

    • nickflic3
      No R3VLimiter
      • Sep 2009
      • 3564

      #3
      Sweet! I love it haha
      Bronzit 4-door Swap Drifting somewhere
      Cammed B25 Swap Daily Driver
      Updated 10/1

      Originally posted by StereoInstaller1
      Maybe 300 CANADIAN HP, thats like 225 US HP.

      Comment

      • decay
        R3V Elite
        • Oct 2003
        • 5637

        #4
        Originally posted by slammin.e28guy
        One complaint....you had to use the thread with that...thing... in it.
        agree. you did not use the This Is Hot Chicks thread, and for that you are Wrong.

        i kid. cool beans, using it.
        past:
        1989 325is (learner shitbox)
        1986 325e (turbo dorito)
        1991 318ic (5-lug ITB)
        1985 323i baur
        current:
        1995 M3 (suspension, 17x9/255-40, borla)

        Comment

        • tonerrrr
          E30 Modder
          • Jul 2011
          • 935

          #5
          Great job!

          instagram: @tonerrrr
          High resolution E30 Fuse Box 300dpi PNG

          Comment

          • Fourbanger
            Grease Monkey
            • Jul 2011
            • 335

            #6
            Thanks for being my testers, ya'lls. Any feedback is welcome. The ability to flip through posts is coming soon...

            It'll probably work with Firefox/Greasemonkey with minimal modification, as well.

            Comment

            • nickflic3
              No R3VLimiter
              • Sep 2009
              • 3564

              #7
              No complaints really, but if it's at all possible improvements could include:
              -Little bit bigger preview (I'm using a 19" widescreen and struggle to make out the words; pix work fine) Size is fine for pix but text not so much
              -Maybe make it follow the mouse as you move around the link? Hovering over topics on the main forums page sometimes puts the preview off the screen to the right and I quickly realized that some people have their sig pics hyper linked to their threads



              (full size)
              Last edited by nickflic3; 02-27-2013, 08:33 PM.
              Bronzit 4-door Swap Drifting somewhere
              Cammed B25 Swap Daily Driver
              Updated 10/1

              Originally posted by StereoInstaller1
              Maybe 300 CANADIAN HP, thats like 225 US HP.

              Comment

              • PeteD
                E30 Modder
                • Mar 2011
                • 982

                #8
                I noticed this luxury on another forum and thought about that here...however that other forum also had ads everywhere... and those f-ing link ads! The (lack) of advertising on R3V is one of the main reasons I like this forum..second to the entertainment of course.

                Thanks!

                Comment

                • Albuquerque30
                  E30 Fanatic
                  • Oct 2010
                  • 1349

                  #9
                  I like it so far. One tip would be to have the hover image show at a defaulted spot on the page. If you hover over a link towards the side or bottom of your screen, it can be cut off almost entirely.

                  Other than that, no complaints here!

                  WTB NorCal: Z4 shifter + misc. parts

                  Comment

                  • Fourbanger
                    Grease Monkey
                    • Jul 2011
                    • 335

                    #10
                    Good suggestions, everyone.

                    [snip]
                    Last edited by Fourbanger; 03-03-2013, 10:53 PM.

                    Comment

                    • Fourbanger
                      Grease Monkey
                      • Jul 2011
                      • 335

                      #11
                      I've made a bunch of updates. It is now much more usable so I recommend updating. See the original post.

                      As always, let me know if you find any bugs/weirdness.




                      Originally posted by nickflic3
                      -Little bit bigger preview (I'm using a 19" widescreen and struggle to make out the words; pix work fine) Size is fine for pix but text not so much
                      I've made it a bit larger but if this is still an issue then just edit the "scaleFactor" variable at the top.
                      Last edited by Fourbanger; 03-03-2013, 11:03 PM.

                      Comment

                      • nickflic3
                        No R3VLimiter
                        • Sep 2009
                        • 3564

                        #12
                        Originally posted by Fourbanger
                        I've made a bunch of updates. It is now much more usable so I recommend updating. See the original post.

                        As always, let me know if you find any bugs/weirdness.






                        I've made it a bit larger but if this is still an issue then just edit the "scaleFactor" variable at the top.
                        Gotcha, I'll check it out!

                        Also I tried out your previous edit, not bad at all!

                        Edit: v 0.2 is phenominally bettert, I will never turn it off haha
                        Bronzit 4-door Swap Drifting somewhere
                        Cammed B25 Swap Daily Driver
                        Updated 10/1

                        Originally posted by StereoInstaller1
                        Maybe 300 CANADIAN HP, thats like 225 US HP.

                        Comment

                        Working...