From 467fce2d37cfa30d82220993908d1305ccae6dd0 Mon Sep 17 00:00:00 2001 From: Ryan Wu Date: Sun, 29 Mar 2015 10:54:32 +0800 Subject: [PATCH] add toc --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ toc.js | 19 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 toc.js diff --git a/README.md b/README.md index e44e9cf..ff38d97 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,46 @@ Copyleft 2001 by D.H.Grand(nOBODY/Ginux), 2010 by Gasolin, 2015 by Ryan Wu 本文另有简体中文版: [http://www.beiww.com/doc/oss/smart-questions.html](http://www.beiww.com/doc/oss/smart-questions.html) ##目錄 + * [聲明](https://github.com/ryanhanwu/smartquestions#聲明) + * [簡介](https://github.com/ryanhanwu/smartquestions#簡介) + * [在提問之前](https://github.com/ryanhanwu/smartquestions#在提問之前) + * [如何提問](https://github.com/ryanhanwu/smartquestions#如何提問) + * [慎選提問的論壇](https://github.com/ryanhanwu/smartquestions#慎選提問的論壇) + * [新手網站或IRC回應最快](https://github.com/ryanhanwu/smartquestions#新手網站或IRC回應最快) + * [第二步,使用專案郵件列表](https://github.com/ryanhanwu/smartquestions#第二步,使用專案郵件列表) + * [使用有意義且描述明確的標題](https://github.com/ryanhanwu/smartquestions#使用有意義且描述明確的標題) + * [使問題容易回覆](https://github.com/ryanhanwu/smartquestions#使問題容易回覆) + * [用辭貼切,語法正確,拼寫無誤](https://github.com/ryanhanwu/smartquestions#用辭貼切,語法正確,拼寫無誤) + * [使用易於讀取且標準的文件格式發送問題](https://github.com/ryanhanwu/smartquestions#使用易於讀取且標準的文件格式發送問題) + * [準確描述問題並言之有物](https://github.com/ryanhanwu/smartquestions#準確描述問題並言之有物) + * [話不在多而在精](https://github.com/ryanhanwu/smartquestions#話不在多而在精) + * [別動輒聲稱找到Bug](https://github.com/ryanhanwu/smartquestions#別動輒聲稱找到Bug) + * [低聲下氣前還是要先做功課](https://github.com/ryanhanwu/smartquestions#低聲下氣前還是要先做功課) + * [描述問題症狀而非猜測](https://github.com/ryanhanwu/smartquestions#描述問題症狀而非猜測) + * [按發生時間先後列出問題症狀](https://github.com/ryanhanwu/smartquestions#按發生時間先後列出問題症狀) + * [描述目標而不是過程](https://github.com/ryanhanwu/smartquestions#描述目標而不是過程) + * [別要求使用私人電郵回覆](https://github.com/ryanhanwu/smartquestions#別要求使用私人電郵回覆) + * [提問應清楚明確](https://github.com/ryanhanwu/smartquestions#提問應清楚明確) + * [當詢問有關程式碼的問題時](https://github.com/ryanhanwu/smartquestions#當詢問有關程式碼的問題時) + * [別把自己家庭作業的問題貼上來](https://github.com/ryanhanwu/smartquestions#別把自己家庭作業的問題貼上來) + * [去除無意義的疑問](https://github.com/ryanhanwu/smartquestions#去除無意義的疑問) + * [不要把問題標記為"急",即使對你而言確實如此](https://github.com/ryanhanwu/smartquestions#不要把問題標記為"急",即使對你而言確實如此) + * [有禮貌絕沒有害處,而且有時是有益的](https://github.com/ryanhanwu/smartquestions#有禮貌絕沒有害處,而且有時是有益的) + * [問題解決後,加個簡短說明](https://github.com/ryanhanwu/smartquestions#問題解決後,加個簡短說明) + * [如何解讀答案](https://github.com/ryanhanwu/smartquestions#如何解讀答案) + * [RTFM和STFW:如何知道你已完全搞砸](https://github.com/ryanhanwu/smartquestions#RTFM和STFW:如何知道你已完全搞砸) + * [如果還是搞不懂](https://github.com/ryanhanwu/smartquestions#如果還是搞不懂) + * [應對粗魯的回應](https://github.com/ryanhanwu/smartquestions#應對粗魯的回應) + * [如何避免扮演失敗者](https://github.com/ryanhanwu/smartquestions#如何避免扮演失敗者) + * [提問的禁忌](https://github.com/ryanhanwu/smartquestions#提問的禁忌) + * [問題清單](https://github.com/ryanhanwu/smartquestions#問題清單) + * [蠢問題範例](https://github.com/ryanhanwu/smartquestions#蠢問題範例) + * [好問題,壞問題](https://github.com/ryanhanwu/smartquestions#好問題,壞問題) + * [如果得不到回答](https://github.com/ryanhanwu/smartquestions#如果得不到回答) + * [如何更好地回答問題](https://github.com/ryanhanwu/smartquestions#如何更好地回答問題) + * [相關資源](https://github.com/ryanhanwu/smartquestions#相關資源) + * [鳴謝](https://github.com/ryanhanwu/smartquestions#鳴謝) + ##聲明 許多專案在他們的使用協助/說明網頁中連結了本指南,這麼做很好,我們也鼓勵大家都這麼做。但如果你是負責管理這個專案網頁的人,請在超連結附近的顯著位置上註明: diff --git a/toc.js b/toc.js new file mode 100644 index 0000000..5ba1fad --- /dev/null +++ b/toc.js @@ -0,0 +1,19 @@ +(function(window) { + String.prototype.repeat = function(num) { + return new Array(num + 1).join(this); + }; + var url = document.URL, + headers = jQuery("article :header"), + result; + for (var i = 2; i < headers.length; i++) { + var header = headers[i], + headerText = header.textContent.trim(), + hIndex = parseInt(header.nodeName.substring(1)) - 1, + indent = " ".repeat(hIndex), + link = ['
', indent, '* [', headerText, '](', url, '#', headerText, ')', '\n', '
']; + result += link.join(''); + } + var win = window.open("", "win"); + win.document.body.innerHTML = result; + +})(window);