CNKI学术搜索注入复制DOI按钮。
当前为
// ==UserScript==
// @name CNKI学术搜索注入复制DOI按钮
// @namespace https://greasyfork.org/zh-CN/users/883114-lys-qs
// @version 0.1
// @description CNKI学术搜索注入复制DOI按钮。
// @author LYS
// @match https://scholar.cnki.net/zn/Detail/index/*
// @run-at document-end
// @icon none
// @grant none
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// 创建一个 <style> 标签
var style = document.createElement('style');
style.type = 'text/css';
// 设置 CSS 样式内容
var cssContent = '.copy-button {' +
' background-color: #fff;' +
' color: #007bff;' +
' border: 1px solid #007bff;' +
' border-radius: 5px;' +
' padding: 5px 10px;' +
' font-size: 14px;' +
' font-weight: bold;' +
' cursor: pointer;' +
'}\n' +
'.copy-button:hover {' +
' background-color: #007bff;' +
' color: #fff;' +
'}';
style.appendChild(document.createTextNode(cssContent));
// 将 <style> 标签添加到 <head> 元素中
document.head.appendChild(style);
// 获取DOI元素
var doiElem = $('.detail_doc-doi__VX6o2 a');
// 创建按钮元素
var button = $('<button/>', {
text: 'Copy DOI',
id: 'copyButton',
});
// 添加CSS类
button.addClass('copy-button');
// 将按钮元素添加到DOI元素后面
doiElem.after(button);
// 为按钮添加点击事件监听
button.on('click', function (event) {
// 获取 DOI 文本
var doiText = doiElem.text();
// 将 DOI 文本复制到剪贴板
navigator.clipboard.writeText(doiText).then(function () {
// 复制成功,给出提示
alert('DOI 已成功复制到剪贴板!');
}, function () {
// 如果复制失败,给出提示
console.error('复制失败。');
});
});
})();