GO语言圣经章节目录

GO语言圣经二级章节目录, 需要手动执行

// ==UserScript==
// @name                GO语言圣经章节目录
// @namespace           http://tampermonkey.net/
// @version             0.1
// @description         GO语言圣经二级章节目录, 需要手动执行
// @author              pogusanqian
// @match               http://books.studygolang.com/gopl-zh/*/*.html
// @icon                data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant               none
// @run-at              context-menu
// @license             MIT
// ==/UserScript==
(() => {
  // 创建二级目录节点
  const secondListWapper = document.querySelector('.book').appendChild(document.createElement('div'));
  const secondList = secondListWapper.appendChild(document.createElement('ul'));

  // 添加内容
  for (const item of document.querySelectorAll('.page-inner h3')) {
    secondList.insertAdjacentHTML('beforeend', `<li style="list-style-type: none;"><a href="#${item.id}">${item.innerHTML}</a></li>`);
  }
  // 添加样式
  secondListWapper.style.cssText = `position: absolute; top: 0; right: 0; width: 300px;`;
})();