// ==UserScript== // @name 给起点加个复制按钮 // @namespace http://tampermonkey.net/ // @version 1.1 // @description 一键复制章节全文 // @author Win-yk // @license MIT // @match https://www.qidian.com/chapter/* // @icon https://www.google.com/s2/favicons?sz=64&domain=qidian.com // @grant GM_setClipboard // @require https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js // @downloadURL https://update.greasyfork.icu/scripts/476146/%E7%BB%99%E8%B5%B7%E7%82%B9%E5%8A%A0%E4%B8%AA%E5%A4%8D%E5%88%B6%E6%8C%89%E9%92%AE.user.js // @updateURL https://update.greasyfork.icu/scripts/476146/%E7%BB%99%E8%B5%B7%E7%82%B9%E5%8A%A0%E4%B8%AA%E5%A4%8D%E5%88%B6%E6%8C%89%E9%92%AE.meta.js // ==/UserScript== (function() { 'use strict'; function do_copy(){ var content = ''; jQuery('.content-text').each(function(){ var now_content = jQuery(this).text(); if(!jQuery(this).is('span')) { if(jQuery(this).children().length) { var dirty = jQuery(this).children().first().text(); now_content = now_content.substr(0, now_content.length - dirty.length); } now_content = '\n' + now_content + '\n'; } content += now_content + '\n'; }); GM_setClipboard(content, "text"); setTimeout(function(){ jQuery('#reader-toast-container').empty(); jQuery('#reader-toast-container').append('
复制成功
'); setTimeout(function(){ jQuery('#reader-toast-container').empty(); jQuery('#reader-toast-container').append(''); }, 600); }, 150); } function main() { var btn = '
' jQuery('#r-menu').children().first().addClass('mt-8px'); jQuery('#r-menu').prepend(btn); jQuery('#copy-button').bind('click', function(){ try { do_copy(); } catch(err) { alert('复制失败\n\n' + err.message); } }); } let observer = new MutationObserver((mutationsList, observer) => { for (let mutation of mutationsList) { if (mutation.type === 'childList') { if (!jQuery('#copy-button').length) { main(); } } } }); observer.observe(document.body, { childList: true, subtree: true }); })();