gpt_academic
gpt_academic copied to clipboard
建议加一个copy按钮在chatbot中
附议 @binary-husky

chatbot我用起来太晕了,我还是直接拿着DOM改起来比较顺畅,我临时写了个油猴的增强插件,来通过注入JS的方法来实现这个复制的功能。
如果需要的话,刚好也有装油猴可以自行搜索 gpt_academic复制内容插件
如果有油猴懒得进行搜索安装的话,可以直接copy我的代码
// ==UserScript==
// @name gpt_academic复制内容插件
// @namespace https://github.com/binary-husky/gpt_academic
// @version 0.1
// @description gpt_academic复制插件-只在黑暗主题下使用
// @author lizheguang
// @match */?__dark-theme=true
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
// @require https://cdn.bootcdn.net/ajax/libs/clipboard.js/2.0.11/clipboard.min.js
// @grant GM_addStyle
// ==/UserScript==
GM_addStyle(`
/* CSS styles inserted using GM_addStyle */
.my-btn{
display: block;
text-align: right;
width: 100%;
}
.my-btn svg{
float: right;
}
`);
(function () {
"use strict";
console.log("COPY增强注入");
$(document).on("mouseenter mouseleave", ".markdown-body", function (event) {
var $btn;
if (event.type === "mouseenter") {
// 移入时的回调
// 在这里编写相关逻辑
var svg = $(
'<svg t="1683197822769" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2660" width="16" height="16"><path d="M857.373005 65.290005 469.604424 65.290005c-34.211173 0-62.044078 27.832905-62.044078 62.043055l0 10.340509-63.076594 0c-25.993001 0-48.228421 16.346293-57.001225 39.293935L166.626995 176.967504c-34.21015 0-62.043055 27.832905-62.043055 62.043055l0 657.655358c0 34.21015 27.832905 62.043055 62.043055 62.043055l550.115086 0c34.21015 0 62.043055-27.832905 62.043055-62.043055l0-49.634444 78.587869 0c34.21015 0 62.043055-27.832905 62.043055-62.043055L919.41606 127.33306C919.41606 93.122911 891.583155 65.290005 857.373005 65.290005zM344.483752 179.035606l194.402595 0c10.833743 0 19.646456 8.813736 19.646456 19.646456 0 10.833743-8.813736 19.646456-19.646456 19.646456L344.483752 218.328517c-10.833743 0-19.646456-8.813736-19.646456-19.646456C324.836273 187.849342 333.650009 179.035606 344.483752 179.035606zM737.423099 896.665917c0 11.402701-9.278317 20.681018-20.681018 20.681018L166.626995 917.346935c-11.403724 0-20.681018-9.278317-20.681018-20.681018L145.945977 239.010559c0-11.402701 9.277294-20.681018 20.681018-20.681018l120.111588 0c8.197706 24.02723 30.977525 41.362037 57.744145 41.362037l194.402595 0c26.767644 0 49.54644-17.334807 57.744145-41.362037l120.111588 0c11.402701 0 20.681018 9.278317 20.681018 20.681018L737.422076 896.665917zM878.054023 784.988418c0 11.402701-9.278317 20.681018-20.681018 20.681018l-78.587869 0L778.785136 239.010559c0-34.21015-27.832905-62.043055-62.043055-62.043055L595.886549 176.967504c-8.771781-22.947641-31.007201-39.293935-57.001225-39.293935l-89.963964 0L448.921359 127.33306c0-11.403724 9.278317-20.681018 20.683065-20.681018l387.768581 0c11.402701 0 20.681018 9.277294 20.681018 20.681018L878.054023 784.988418z" fill="#bfbfbf" p-id="2661"></path><path d="M620.597347 334.252737 260.748652 334.252737c-11.422144 0-20.681018 9.259898-20.681018 20.681018s9.258874 20.681018 20.681018 20.681018l359.849718 0c11.42112 0 20.681018-9.259898 20.681018-20.681018S632.018467 334.252737 620.597347 334.252737z" fill="#bfbfbf" p-id="2662"></path><path d="M620.597347 454.201619 260.748652 454.201619c-11.422144 0-20.681018 9.259898-20.681018 20.681018 0 11.42112 9.258874 20.681018 20.681018 20.681018l359.849718 0c11.42112 0 20.681018-9.259898 20.681018-20.681018C641.278365 463.46254 632.018467 454.201619 620.597347 454.201619z" fill="#bfbfbf" p-id="2663"></path><path d="M440.673511 574.151525 260.748652 574.151525c-11.422144 0-20.681018 9.259898-20.681018 20.681018 0 11.42112 9.258874 20.681018 20.681018 20.681018l179.924859 0c11.42112 0 20.681018-9.259898 20.681018-20.681018C461.35453 583.411423 452.093609 574.151525 440.673511 574.151525z" fill="#bfbfbf" p-id="2664"></path></svg>'
);
$btn = $("<button/>") // 创建一个 <button> 元素
.html(svg)
.addClass("my-btn"); // 添加一个自定义类名
// .prepend(this); // 将按钮添加到容器中
$(this).prepend($btn);
// console.log("移入");
} else {
// 移出时的回调
// 在这里编写相关逻辑
$(this).find(".my-btn").remove();
// console.log("移出");
}
});
$(document).on("click", ".my-btn", function (event) {
console.log("click-my-btn");
let that = this;
const markDownDom = $(this).parent();
// $(this).remove();
const text = markDownDom.text();
var $temp = $("<textarea>"); // 创建一个隐藏的textarea元素
$("body").append($temp); // 将textarea元素添加到DOM中
$temp.val(text).select(); // 将文案内容复制到textarea元素中,并且选中
// 有兼容问题最好是谷歌浏览器
document.execCommand("copy"); // 执行复制操作
$temp.remove(); // 移除textarea元素
});
})();