极客时间本地网页优化

自动展开极客时间本地网页的评论,并嵌入音频(需要开启允许访问文件网址)

// ==UserScript==
// @name         极客时间本地网页优化
// @license MIT
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  自动展开极客时间本地网页的评论,并嵌入音频(需要开启允许访问文件网址)
// @author       You
// @match        file:///*/*
// @include      file:///*/*
// @icon         https://www.google.com/s2/favicons?domain=undefined.
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
     document.querySelectorAll("ul>li>div").forEach(e=>{
         var comment = e.children[1];
         if (comment.children[0] != undefined) {
             comment.style.display = "block";
         }
     });
    document.getElementsByTagName("base")[0].remove();
    var str = location.href;
    var arr = str.split("/");
    var file_path = arr[arr.length - 1];
    var mp3 = file_path.replace(".html", ".mp3");

    // 将audio添加到首部
    var audio = document.createElement("audio");
    audio.setAttribute("controls", "");
    audio.style.position = "relative";
    audio.style.top = "80px";
    audio.style.margin = "0 auto";
    audio.style.display = "block";
    audio.setAttribute("id", "mp3-player");

    var app = document.getElementById("app");
    app.insertBefore(audio, app.firstElementChild);
    // 添加MP3
    var sourceMp3 = document.createElement("source");
    sourceMp3.setAttribute("src", mp3);
    sourceMp3.setAttribute("type", "audio/mpeg");
    sourceMp3.autoplay=false;

    audio.appendChild(sourceMp3);
    audio.autoplay=false;

    document.title=document.querySelector("h1").innerText;
    // Your code here...
})();