From 631e566e2d433fb8f2a97c83a8e6ac4299765e43 Mon Sep 17 00:00:00 2001 From: Robert Foy Date: Wed, 29 Nov 2017 04:43:03 +1100 Subject: [PATCH 1/2] Rendering delay to work around Chromium Issue --- src/popup.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/popup.js b/src/popup.js index e23ee84..6bc53ba 100644 --- a/src/popup.js +++ b/src/popup.js @@ -2,19 +2,22 @@ chrome.tabs.getSelected(null, function(tab) { chrome.tabs.sendRequest(tab.id, {msg: "getOutline"}, function(outline) { - var elOutline = document.getElementById('outline'); - elOutline.innerHTML = outline; - - var links = elOutline.getElementsByTagName('a'); - for (var i=0; i < links.length; i++) { - links[i].onclick=function(e) { - var lnk = e.target; - while (lnk.nodeName!='A' && lnk) lnk = lnk.parentNode; - - e.preventDefault(); - var id = lnk.href.substring(lnk.href.indexOf('#')+1); - chrome.tabs.sendRequest(tab.id, {msg: "jumpTo", id: id}); + var oldOutline = document.getElementById('outline'); + var newOutline = oldOutline.cloneNode(false); + oldOutline.parentNode.replaceChild(newOutline, oldOutline); + setTimeout(function () { + newOutline.appendChild(document.createRange().createContextualFragment(outline)); + var links = elOutline.getElementsByTagName('a'); + for (var i=0; i < links.length; i++) { + links[i].onclick=function(e) { + var lnk = e.target; + while (lnk.nodeName!='A' && lnk) lnk = lnk.parentNode; + + e.preventDefault(); + var id = lnk.href.substring(lnk.href.indexOf('#')+1); + chrome.tabs.sendRequest(tab.id, { msg: "jumpTo", id: id }); + } } - } + }, 200); }); }); From 06c034cd0426d27b65940973a52707a971cef001 Mon Sep 17 00:00:00 2001 From: Robert Foy Date: Wed, 29 Nov 2017 05:01:17 +1100 Subject: [PATCH 2/2] Fix incorrect var --- src/popup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/popup.js b/src/popup.js index 6bc53ba..9d8bcb9 100644 --- a/src/popup.js +++ b/src/popup.js @@ -7,7 +7,7 @@ chrome.tabs.getSelected(null, function(tab) oldOutline.parentNode.replaceChild(newOutline, oldOutline); setTimeout(function () { newOutline.appendChild(document.createRange().createContextualFragment(outline)); - var links = elOutline.getElementsByTagName('a'); + var links = newOutline.getElementsByTagName('a'); for (var i=0; i < links.length; i++) { links[i].onclick=function(e) { var lnk = e.target;