// ==UserScript==
// @name AAAAA-复制标题-到memory
// @namespace Violentmonkey Scripts
// @icon https://memory.tianyunperfect.cn/pro_icon.svg
// @match *://*/*
// @exclude https://memory.tianyunperfect.cn/*
// @exclude https://tracert.alipay.com/*
// @exclude https://t.captcha.qq.com/*
// @grant GM_registerMenuCommand
// @version 1.0
// @author tianyunperfect
// @require https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js
// @require http://www.tianyunperfect.cn:3001/tianyunperfect/web-base/raw/master/tmp/monkey/util.js?a=1
// @description 2021/1/30 下午7:09:51
// ==/UserScript==
(function () {
'use strict';
GM_registerMenuCommand("!!!复制并加到memory", to_memory)
GM_registerMenuCommand("!!!复制标题和 url", copyTitle)
function to_memory() {
let url = location.href;
let title = document.title;
if (window.self !== window.top) {
return
}
let body = {
"back": "
",
"front": `url: ${title}
`,
"period": 0,
"onlyText": "",
"remindTime": new Date(),
"tag": "",
"updateTime": "",
"userId": 1
};
let memory_url = "https://memory.tianyunperfect.cn/api/memory-64B206F1-E915-4298-9AB7-9C561040B012/insert";
axios.post(memory_url, body).then((res) => {
console.log(res.data);
let data = res.data;
if (data.success) {
} else {
alert(data.message);
}
})
myAlert(`${title}
${location.host}`, 2)
}
function copyTitle() {
myCopy(`${document.title}`)
}
document.onkeydown = function (ev) {
if (ev.key === 'c' && ev.shiftKey) {
ev.preventDefault() // 关闭浏览器快捷键
copyTitle()
}
}
})();
let btnStyle = `
#copy-title-and-location {
position: fixed; top: 100px; left: -95px; opacity: 0.3; z-index: 2147483647;
background-image: none; cursor:pointer; color: #fff; background-color: #0084ff !important;
margin: 5px 0px; width: auto; border-radius: 3px; border: #0084ff; outline: none; padding: 3px 6px; height: 26px;
font-family: Arial, sans-serif; font-size: 12px; transition: left, 0.5s;
}
#copy-title-and-location:hover {left: 0px; opacity: 1;}
#copy-title-and-location svg {width: auto; vertical-align: middle; margin-left: 10px; border-style: none;text-align: center;display: inline-block !important;margin-bottom: 2px;}`;
let styleTag = createEle('style', btnStyle, { type: "text/css" });
// 将按钮图标由原来的img改为了svg,以增强适应性,同时也将对svg的样式设置移到了上面的 btnStyle 中
let iconSVG = '';
let btn = createEle('button', '', { id: "copy-title-and-location" });
btn.innerHTML = '复制标题和地址' + iconSVG;
btn.addEventListener('click', () => {
let date = new Date();
let timeStamp = '更新:' + date.toLocaleDateString().replace('\/', '年').replace('\/', '月') + '日' + date.toLocaleTimeString('chinese', { hour12: false });
let titleInfo = document.querySelector('title').innerText;
let address = '\n> 参考:[' + titleInfo + ']' + '(' + location + ')';
// 匹配微信公众号的文章地址
let regWeChat = /https:\/\/mp.weixin.qq.com\//;
if (regWeChat.test(location.toString())) {
let officialAccount = document.getElementById('js_name');
let publishDate = document.getElementById('publish_time');
publishDate.click();
address = '\n> 参考:[【微信公众号:' + officialAccount.innerText + ' ' + publishDate.innerText + '】' + titleInfo + ']' + '(' + location + ')';
}
// 【更新:2021年9月12日22:48:36】添加了一个try catch来应对当前页面不能访问 navigator.clipboard 对象的问题
try {
navigator.clipboard.writeText(timeStamp + address);
} catch (err) {
console.log('当前页面不支持访问 navigator.clipboard 对象:' + err);
// if(/www.ruanyifeng.com/.test(location.toString())) {
// location.protocol = 'https';
// }
myAlert(timeStamp, address);
}
});
// document.body.appendChild(style); // 这种写法会导致脚本在