瀏覽代碼

Add anchor links

simov 8 年之前
父節點
當前提交
fb9c33f51f
共有 2 個文件被更改,包括 24 次插入5 次删除
  1. 20 5
      content/content.js
  2. 4 0
      css/content.css

+ 20 - 5
content/content.js

@@ -41,6 +41,8 @@ var oncreate = {
     }
 
     setTimeout(() => Prism.highlightAll(), 20)
+
+    anchors()
   }
 }
 
@@ -146,11 +148,17 @@ function scroll () {
   })
 }
 
-if (document.readyState === 'complete') {
-  mount()
-}
-else {
-  window.addEventListener('DOMContentLoaded', mount)
+function anchors () {
+  Array.from($('#_html').childNodes)
+  .filter((node) => /h[1-6]/i.test(node.tagName))
+  .forEach((node) => {
+    var a = document.createElement('a')
+    a.className = 'anchor'
+    a.name = node.id
+    a.href = '#' + node.id
+    a.innerHTML = '<span class="octicon octicon-link"></span>'
+    node.prepend(a)
+  })
 }
 
 var toc = (
@@ -183,3 +191,10 @@ var toc = (
     }
     return html
   }, '<div id="_toc"><div id="_ul">') + '</div></div>'
+
+if (document.readyState === 'complete') {
+  mount()
+}
+else {
+  window.addEventListener('DOMContentLoaded', mount)
+}

文件差異過大導致無法顯示
+ 4 - 0
css/content.css


部分文件因文件數量過多而無法顯示