Note that there are some explanatory texts on larger screens.

plurals
  1. POUser Script for Displaying Tooltip is not working
    primarykey
    data
    text
    <p>I have developed the following user script which will show the html element under mouse on mouseover in the tooltip.</p> <p>Earlier I was using the same script as a content script in a Chrome Extension and it is working absolutely fine there.</p> <p>I am getting the following error:</p> <p><strong>Uncaught TypeError: Cannot read property 'timer' of undefined</strong></p> <pre><code>// ==UserScript== // @name Tooltip // @author Saurabh Saxena // @version 1.0 // ==/UserScript== var id = 'tt'; var top = 3; var left = 3; var maxw = 300; var speed = 10; var timer = 20; var endalpha = 95; var alpha = 0; var tt, t, c, b, h; var ie = document.all ? true : false; document.onmouseover = function(e,w) { var link = document.location.toString(); link = link.split('.'); if(!link[1].match(/facebook/) &amp;&amp; !link[1].match(/google/) &amp;&amp; !link[1].match(/youtube/) &amp;&amp; !link[2].match(/google/)) { if (tt == null) { tt = document.createElement('div'); tt.setAttribute('id', id); t = document.createElement('div'); t.setAttribute('id', id + 'top'); c = document.createElement('div'); c.setAttribute('id', id + 'cont'); b = document.createElement('div'); b.setAttribute('id', id + 'bot'); tt.appendChild(t); tt.appendChild(c); tt.appendChild(b); document.body.appendChild(tt); tt.style.opacity = 0; tt.style.zIndex = 10000000;/*Important Dont Change it or the tooltip will move below the stack*/ tt.style.filter = 'alpha(opacity=0)'; document.onmousemove = function(e) { var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY; var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX; tt.style.top = (u - h) + 'px'; tt.style.left = (l + left) + 'px';}; } tt.style.display = 'block'; var str = ""; var currenttag = ""; var parenttag = ""; var tooltip = ""; var flag = 0; var chk = e.srcElement.parentNode; /*creating contents of parent tag if it exists*/ if(chk != null) { var parenttag = "&lt;" + chk.nodeName; for (var i = 0; i &lt; chk.attributes.length; i++) { var attrib = chk.attributes[i]; if(attrib.value == "") parenttag = parenttag + " " + attrib.name; else parenttag = parenttag + " " + attrib.name + ' ="' + attrib.value + '"'; parenttag = parenttag + " "; } parenttag = trim(parenttag); tooltip = parenttag + "&gt;" + "\n\n"; } /*creating contents of current tag*/ currenttag = "&lt;" + e.srcElement.nodeName; if(e.srcElement.attributes.length == 0) flag = 0; for (var i = 0; i &lt; e.srcElement.attributes.length; i++) { var attrib = e.srcElement.attributes[i]; if(attrib.value == "") currenttag = currenttag + " " + attrib.name; else { flag = 1; currenttag = currenttag + " " + attrib.name + ' ="' + attrib.value + '"'; currenttag = currenttag + " "; } } currenttag = trim(currenttag); currenttag = currenttag + "&gt;"; currenttag = currenttag + e.srcElement.innerHTML; currenttag = currenttag + "&lt;/" ; currenttag = currenttag + e.srcElement.nodeName; currenttag = currenttag + "&gt;"; tooltip = tooltip + currenttag; tooltip = tooltip.toLowerCase(); if(currenttag == "" || flag == 0) return; c.innerText = tooltip; tt.style.width = w ? w + 'px' : 'auto'; tt.style.width = tt.offsetWidth; t.style.display = 'block'; b.style.display = 'block'; if (tt.offsetWidth &gt; maxw) { tt.style.width = maxw + 'px' } h = parseInt(tt.offsetHeight); clearInterval(tt.timer); tt.timer = setInterval(function () { var a = alpha; var d = 1; if ((a != endalpha &amp;&amp; d == 1) || (a != 0 &amp;&amp; d == -1)) { var i = speed; if (endalpha - a &lt; speed &amp;&amp; d == 1) { i = endalpha - a; } else if (alpha &lt; speed &amp;&amp; d == -1) { i = a; } alpha = a + (i * d); tt.style.opacity = alpha * .01; tt.style.filter = 'alpha(opacity=' + alpha + ')'; } else { clearInterval(tt.timer); if (d == -1) { tt.style.display = 'none' } } }, timer); } }//end onmousedown document.onmouseout = function() { clearInterval(tt.timer); tt.timer = setInterval(function () { var a = alpha; var d = -1; if ((a != endalpha &amp;&amp; d == 1) || (a != 0 &amp;&amp; d == -1)) { var i = speed; if (endalpha - a &lt; speed &amp;&amp; d == 1) { i = endalpha - a; } else if (alpha &lt; speed &amp;&amp; d == -1) { i = a; } alpha = a + (i * d); tt.style.opacity = alpha * .01; tt.style.filter = 'alpha(opacity=' + alpha + ')'; } else { clearInterval(tt.timer); if (d == -1) { tt.style.display = 'none'; } } }, timer); } function trim(s) { s = s.replace(/(^\s*)|(\s*$)/gi,""); s = s.replace(/[ ]{2,}/gi," "); s = s.replace(/\n /,"\n"); return s; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload