Advertisement
azcn2503

Expose Anchors Bookmarklet

May 16th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. javascript:(function() {var style = document.createElement('style');style.type = 'text/css';style.innerHTML = '.anchor_expose_hl { background-color: #ff0 !important; }';document.getElementsByTagName('head')[0].appendChild(style);var els = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'span', 'p', 'a'];var attrs = ['name', 'id'];var selector = '';for(var i in els) {for(var j in attrs) {selector += els[i] + '[' + attrs[j] + '],';}}selector = selector.replace(/,$/, '');var e = document.querySelectorAll(selector);var w = window.open('', 'anchors', 'width=400,height=400,resizeable,scrollbars');var style = document.createElement('style');style.type = 'text/css';style.innerHTML = 'li:hover { background-color: #ff0 !important; }';w.document.getElementsByTagName('head')[0].appendChild(style);var h1 = document.createElement('h1');h1.innerHTML = 'Anchors for ' + document.title;var ul = document.createElement('ul');for(var i in e) {if(e.hasOwnProperty(i) && (e[i].id || e[i].name)) {v = !e[i].id ? e[i].name : e[i].id;var att = e[i].name ? 'name' : 'id';var tn = e[i].tagName;var h = e[i].textContent || e[i].innerText || '';var li = document.createElement('li');var bindObj = {tn: tn, att: att, v: v, w: w};li.onmouseover = function() { var el = this.w.opener.document.querySelector(this.tn + '[' + this.att + '=' + this.v + ']'); el.classList.add('anchor_expose_hl'); el.scrollIntoView(); }.bind(bindObj);li.onmouseout = function() { this.w.opener.document.querySelector(this.tn + '[' + this.att + '=' + this.v + ']').classList.remove('anchor_expose_hl'); }.bind(bindObj);li.innerHTML = '<a href="' + location.href + '#' + v + '" target="_blank">' + v + '</a> - ' + (h != '' ? h : '<i>No link text</i>');ul.appendChild(li);console.log('#' + v + ' - ' + (h != '' ? h : ''));}}w.document.body.appendChild(h1);w.document.body.appendChild(ul);})();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement