AAAAA-复制标题-到memory.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // ==UserScript==
  2. // @name AAAAA-复制标题-到memory
  3. // @namespace Violentmonkey Scripts
  4. // @icon https://memory.tianyunperfect.cn/pro_icon.svg
  5. // @match *://*/*
  6. // @grant GM_registerMenuCommand
  7. // @version 1.0
  8. // @author tianyunperfect
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js
  10. // @require http://www.tianyunperfect.cn:3001/tianyunperfect/web-base/raw/master/tmp/monkey/util.js?a=1
  11. // @description 2021/1/30 下午7:09:51
  12. // ==/UserScript==
  13. (function () {
  14. 'use strict';
  15. GM_registerMenuCommand("!!!复制并加到memory", to_memory)
  16. GM_registerMenuCommand("!!!复制标题和 url", copyTitle)
  17. function to_memory() {
  18. let url = location.href;
  19. let title = document.title;
  20. if (window.self !== window.top) {
  21. return
  22. }
  23. let body = {
  24. "back": "<p></p>",
  25. "front": `<p>url: <a href="${url}">${title}</a></p>`,
  26. "period": 0,
  27. "onlyText": "",
  28. "remindTime": new Date(),
  29. "tag": "",
  30. "updateTime": "",
  31. "userId": 1
  32. };
  33. let memory_url = "https://memory.tianyunperfect.cn/api/memory-64B206F1-E915-4298-9AB7-9C561040B012/insert";
  34. axios.post(memory_url, body).then((res) => {
  35. console.log(res.data);
  36. let data = res.data;
  37. if (data.success) {
  38. } else {
  39. alert(data.message);
  40. }
  41. })
  42. myAlert(`${title}<br/>${location.host}`, 2)
  43. }
  44. function copyTitle() {
  45. myCopy(`<a href="${location.href}">${document.title}</a>`)
  46. }
  47. document.onkeydown = function (ev) {
  48. if (ev.key === 'c' && ev.shiftKey) {
  49. ev.preventDefault() // 关闭浏览器快捷键
  50. copyTitle()
  51. }
  52. }
  53. let btnStyle = `
  54. #copy-title-and-location {
  55. position: fixed; top: 300px; left: -165px; opacity: 0.3; z-index: 2147483647;
  56. background-image: none; cursor:pointer; color: #fff; background-color: #0084ff !important;
  57. margin: 5px 0px; width: auto; border-radius: 3px; border: #0084ff; outline: none; padding: 3px 6px; height: 35px;
  58. font-family: Arial, sans-serif; font-size: 22px; transition: left, 0.5s;
  59. }
  60. #copy-title-and-location:hover {left: 0px; opacity: 1;}
  61. #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;}`;
  62. let styleTag = createEle('style', btnStyle, {type: "text/css"});
  63. // 将按钮图标由原来的img改为了svg,以增强适应性,同时也将对svg的样式设置移到了上面的 btnStyle 中
  64. let iconSVG = '<?xml version="1.0" encoding="UTF-8"?><svg width="16" height="16" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><rect width="48" height="48" fill="white" fill-opacity="0.01"/><path d="M8 6C8 4.89543 8.89543 4 10 4H30L40 14V42C40 43.1046 39.1046 44 38 44H10C8.89543 44 8 43.1046 8 42V6Z" fill="none" stroke="#333" stroke-width="4" stroke-linejoin="round"/><path d="M16 20H32" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><path d="M16 28H32" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg>';
  65. let btn = createEle('button', '', {id: "copy-title-and-location"});
  66. btn.innerHTML = '插入标题和地址' + iconSVG;
  67. btn.addEventListener('click', () => {
  68. to_memory()
  69. });
  70. if (window.self === window.top) {
  71. if (document.querySelector('body')) {
  72. document.body.appendChild(btn);
  73. document.body.appendChild(styleTag);
  74. } else {
  75. document.documentElement.appendChild(btn);
  76. document.documentElement.appendChild(styleTag);
  77. }
  78. }
  79. })();