Greasy Fork

Greasy Fork is available in English.

iTuringSubtitles

Add subtitles in ituring.com.cn.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         iTuringSubtitles
// @namespace    https://github.com/arrayJY/iTuringSubtitles
// @version      0.2.1
// @description  Add subtitles in ituring.com.cn.
// @author       arrayJY
// @match        https://www.ituring.com.cn/book/tupubarticle/*
// @grant        none
// @run-at       document-end
// @require      https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js
// ==/UserScript==

(function () {
  "use strict";
  $(document).ready(() => {
    const getIndex = (title) => title.split(" ")[0];

    $("div.article-detail h2,h3").each(function () {
      $(this).attr("id", getIndex($.trim($(this).text())));
    });

    const subtitles = $("div.article-detail h2")
      .map(function () {
        const thirdSubtitles = $(this)
          .nextUntil("div.article-detail h2", "h3")
          .map(function () {
            return $.trim($(this).text());
          })
          .get();
        const subtitle = {
          secondSubtitles: $.trim($(this).text()),
          thirdSubtitles,
        };
        return subtitle;
      })
      .get();

    subtitles.shift();

    const makeList = (s, t) => {
      return $("<li></li>")
        .append(
          $("<a></a>")
            .text(s)
            .attr("href", `#${getIndex(s)}`)
            .css("font-size", "13px"),
          t ? $("<ul></ul").append(t.map((ts) => makeList(ts))).css("margin", "0px") : null
        )
        .css("padding", "2px 0px 2px 12px");
    };

    const title = $("span[style*='font-weight:bold']");
    const subtitleElements = subtitles.map((v) =>
      makeList(v.secondSubtitles, v.thirdSubtitles)
    );
    subtitleElements.forEach((v) => title.append(v));
  });
})();