Created
June 5, 2024 02:47
-
-
Save tianheg/b809aa5bf2cbd6dcc8117a92857faa14 to your computer and use it in GitHub Desktop.
Weread Copy TOC button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name 微信阅读复制目录 | |
// @description 微信阅读复制目录 | |
// @match https://weread.qq.com/web/reader/* | |
// @grant GM_setClipboard | |
// @version 1.0 | |
// @require https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js | |
// ==/UserScript== | |
/* global $ */ | |
$(window).on('load', function(){ | |
let btn = '<button class="readerControls_item mdbtn">md</button>' | |
$('.readerControls').append(btn); | |
$('.mdbtn').click(function() { | |
let md_str = ''; | |
let book_title = $('.readerCatalog_bookInfo_title_txt')[0].textContent; | |
md_str += `# ${book_title}\n`; | |
const listItems = document.querySelectorAll('.readerCatalog_list_item_title_text'); | |
listItems.forEach((item, index) => { | |
// 根据章节级别添加不同数量的#号 | |
let levelMatch = item.closest('.readerCatalog_list_item_inner').className.match(/readerCatalog_list_item_level_(\d+)/); | |
let level = 1; // 默认级别为1 | |
if (levelMatch && levelMatch[1]) { | |
level = parseInt(levelMatch[1], 10); | |
} | |
md_str += `#${'#'.repeat(level)} ${item.textContent.trim()}\n`; | |
}); | |
GM_setClipboard(md_str); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment