Advertisement
rdsedmundo

Find in page (Finder)

Sep 11th, 2011
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function finder(){var date = (new Date() - 0);var name = "finding" + date;var wrap = "wrapper" + date;var find = function(s){s = (prompt("\u2605 Finder\u2605", s || "") || "").replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");if (!s) return;if (s.length == 1 && !confirm("\"" + s + "\" muito pequeno - vai achar muitas coisas. Tem certeza?")){find(s); return;}find.s = s;init();var r = new RegExp("("+s.split("").map(function(c){return "\\u"+("0000"+c.charCodeAt(0).toString(16)).slice(-4);}).join("")+")", "gi");var p = '<' + name + ' style="background-color:yellow;">$1</' + name + '>';var x = document.evaluate('.//text()[normalize-space(.) != ""]', document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);for (var i = 0, n = x.snapshotLength; i < n; i++){var t = x.snapshotItem(i);if (t.data.search(r) == -1) continue;var e = document.createElement(wrap);e.innerHTML = t.data.replace(r, p);t.parentNode.replaceChild(e, t);}var pn, _pn, _iv;for (var y = document.getElementsByTagName(name), i = 0, n = y.length; i < n; i++) {var e = y.item(i);if (!e) continue;pn = e.parentNode;if (!(_pn && _pn.isSameNode(pn))) {_pn = pn;_iv = (!pn.offsetWidth || !pn.offsetHeight || window.getComputedStyle(pn, null).visibility == "hidden");}if (!_iv) find.a.push(e);}if (find.a.length === 0) {if (confirm("Nada encontrado para \"" + s + "\".\nQuer tentar novamente??")) find(s);} else {alert("Achados " + find.a.length + " match" + (find.a.length == 1 ? "" : "es") + " para \"" + s + "\"");move();}};find.s = "";find.a = [];find.i = 0;var init = function(){var a = [];for (var y = document.getElementsByTagName(wrap), i = 0, n = y.length; i < n; i++) {var e = y.item(i); if (e) a.push(e);}for (var i = 0, n = a.length; i < n; i++) a[i].parentNode.replaceChild(document.createTextNode(a[i].textContent), a[i]);find.a = [];find.i = 0;};var info = function(){if (find.a.length === 0) {find(); return;}alert("\nAchados " + (find.i + 1) + " of " + find.a.length + " for \"" + find.s + "\"\n\n\u2605 Finder \u2605\n\u00A92011");};var move = function(){var e = find.a[find.i];e.scrollIntoView(true);e.style.backgroundColor = "orange";stalk();};var next = function(){if (find.a.length === 0) {find(); return;}find.a[find.i].style.backgroundColor = "yellow";if (find.i + 1 == find.a.length) {if (confirm("Chegou ao fim da pรกgina\nContinuar do topo?")) find.i = 0;} else {find.i++;}move();};var prev = function(){if (find.a.length === 0) {find(); return;}find.a[find.i].style.backgroundColor = "yellow";if (find.i === 0) {if (confirm("Chegou ao topo da pรกgina.\nContinuar do final?")) find.i = find.a.length - 1;} else {find.i--;}move();};var stalk;(function(){var W = window.screen.width;var H = 50;var b = document.createElement("canvas");var s = b.style;s.margin = 0;s.padding = 0;s.border = "none";s.background = "none";s.display = "block";s.visibility = "visible";s.opacity = 1;s.position = "absolute";s.zIndex = 2147483647;s.left = s.top = 0;s.width  = W + "px";s.height = H + "px";b.width  = W;b.height = H;s.webkitTransitionProperty = "-webkit-transform, opacity";s.webkitTransitionDuration = "0.3s, 1s";s.webkitTransformOrigin = "0% 0%";s.webkitTapHighlightColor = "rgba(0,0,0,0)";(function(){var c = b.getContext("2d");c.fillStyle = "rgba(0,0,0,0.5)";c.fillRect(0,0,W,H);var g = c.createLinearGradient(0,10,0,40);g.addColorStop(0,"#fff");g.addColorStop(1,"#bbb");c.fillStyle = g;c.strokeStyle = "rgba(0,0,0,0.3)";c.lineWidth = 1;var w = W/5;([function(x,y){c.moveTo(x+10,y+10);c.lineTo(x+20,y+20);c.moveTo(x+20,y+10);c.lineTo(x+10,y+20);c.stroke();},function(x,y){c.arc(x+13,y+13,5,0,Math.PI*2,true);c.moveTo(x+21,y+21);c.lineTo(x+17,y+17);c.stroke();},function(x,y){c.arc(x+15,y+8,1,0,Math.PI*2,true);c.moveTo(x+14,y+14);c.lineTo(x+16,y+14);c.moveTo(x+15,y+14);c.lineTo(x+15,y+22);c.moveTo(x+13,y+22);c.lineTo(x+17,y+22);c.stroke();},function(x,y){c.moveTo(x+20,y+10);c.lineTo(x+6,y+15);c.lineTo(x+20,y+20);c.fill();},function(x,y){c.moveTo(x+10,y+10);c.lineTo(x+10,y+20);c.lineTo(x+24,y+15);c.fill();}]).forEach(function(f,i){c.beginPath();c.arc(w*i+w/2,H/2,15,0,Math.PI*2,true);c.fill();c.stroke();c.save();c.fillStyle = c.strokeStyle = "rgba(0,0,0,0.5)";c.beginPath();c.lineWidth = 3;c.lineCap = "round";f(w*i+w/2-15,10);c.restore();});})();var w = window.innerWidth;var h = Math.floor(H * (w / W));var x = window.scrollX;var y = ((window.innerHeight + window.scrollY) - h);s.webkitTransform = "translate(" + x + "px, " + y + "px) scale(" + (w / W)  + ")";document.body.appendChild(b);b.addEventListener("click", function(e) {var x = e.clientX - window.scrollX;var W = window.innerWidth;var w = W/5;if (x > w*4) next();else if (x > w*3) prev();else if (x > w*2) info();else if (x > w) find();else {if (!confirm("Fechar o Finder?")) return;s.opacity = 0;init();window.removeEventListener("scroll", stalk, true);window.setTimeout(function(){b.parentNode.removeChild(b);}, 1100);}}, true);stalk = function(){var w = window.innerWidth;var h = Math.floor(H * (w / W));var x = window.scrollX;var y = ((window.innerHeight + window.scrollY) - h);s.webkitTransform = "translate(" + (x - b.offsetLeft) + "px, " + (y - b.offsetTop) + "px) scale(" + (w / b.offsetWidth)  + ")";};window.addEventListener("scroll", stalk, true);})();find();};finder();void(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement