downloadBookFromIPFS

add btn to download book from IPFS('http://library.lol/') on 3lib.net

目前為 2021-07-05 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        downloadBookFromIPFS
// @namespace    https://3lib.net/book*
// @version      1.02
// @description  add btn to download book from IPFS('http://library.lol/') on 3lib.net
// @author       xiangzi fang
// @match        https://3lib.net/book*
// @match        https://book4you.org/book*
// @match        https://hk1lib.org/book*
// @match        https://*.hk1lib.org/book*

// @grant        none
// ==/UserScript==

(function () {
  "use strict";

  function findCoverImgUrl() {
    let coverImgUrl = null;
    let coverImg = document.querySelector(".details-book-cover-content .z-book-cover.covered>img");
    console.log(coverImg);

    if (coverImg) {
      coverImgUrl = coverImg.src;
    }

    console.log("CoverImgurl", coverImgUrl);
    return coverImgUrl;
  }

  function getBookMD5(coverImgUrl) {
    let bookMD5 = null;
    if (coverImgUrl) {
      bookMD5 = coverImgUrl.split("/").pop().split(".")[0];
    }
    console.log("bookMD5", bookMD5);
    return bookMD5;
  }

  function addbtn2librarydotlol(bookMD5) {
    let bookDeailsBtns = document.querySelectorAll(".book-details-button");
    let saveLaterbtn = bookDeailsBtns[bookDeailsBtns.length - 1];

    if (bookMD5) {
      let btnHTML2add = `<div class="book-details-button">
    <a class="btn btn-success" href="http://library.lol/main/${bookMD5}" target="_blank" > Download from IPFS </a>
  </div>`;
      saveLaterbtn.insertAdjacentHTML("afterend", btnHTML2add);
    }
  }

  function mainWork() {
    let _coverImgUrl = findCoverImgUrl();
    let _bookMD5 = getBookMD5(_coverImgUrl);
    addbtn2librarydotlol(_bookMD5);
  }

  setTimeout(mainWork, 2000);
})();