// use following converter: // http://chriszarate.github.io/bookmarkleter/ var d = document; var re = new RegExp(/(\+\d{1,2})?([ ()-]{0,2}\d{3,4}){2,3}\b/); var createLink = function(txt) { var a = d.createElement('a'); a.setAttribute('class', '_ph_'); a.href='#'; a.setAttribute('data-clipboard-text', txt); a.innerHTML = txt; return a; }; var embedLink = function(node) { var match = re.exec(node.data); if (!match) return; //console.log(node.data, match, match.index); node.splitText(match.index); node.nextSibling.splitText(match[0].length); node.parentNode.replaceChild(createLink(match[0]), node.nextSibling); }; var ignore = { 'a':1, 'style':1, 'script':1, 'iframe':1, 'button':1 }; var substitude = function(el) { //console.log(el, el.childNodes); [].forEach.call(el.childNodes, function(node) { if (node.nodeType == 3) { // TEXT_NODE embedLink( node ); return; } if (1 != ignore[node.nodeName.toLowerCase()]) substitude(node); }); } //console.log(rr, nn); var openGV = function(ev) { var a; setTimeout(function() { window.open('https://www.google.com/voice/b/0/#inbox'); }, 0); return false; }; var script = d.createElement('script'); script.src = 'https://cdn.jsdelivr.net/clipboard.js/1.5.10/clipboard.min.js'; script.onload = function() { clipboard = new Clipboard('._ph_'); //clipboard.on('success', function(e) { console.log('success ', e); }); //console.log(clipboard); } d.querySelector('head').appendChild(script); substitude(d.body); [].forEach.call(d.querySelectorAll('._ph_'), function(e) { e.addEventListener('click', openGV); });