tianyunperfect 3 лет назад
Родитель
Сommit
6cd4b03f18
3 измененных файлов с 91 добавлено и 1 удалено
  1. 56 0
      tmp/monkey/AAAAA-复制标题-到memory.js
  2. 0 0
      tmp/monkey/tmp.js
  3. 35 1
      tmp/monkey/util.js

+ 56 - 0
tmp/monkey/AAAAA-复制标题-到memory.js

@@ -0,0 +1,56 @@
+// ==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/369c684a3d4f12d24ef0e6edacde733e3a6e2d00/tmp/monkey/util.js
+// @description 2021/1/30 下午7:09:51
+// ==/UserScript==
+
+(function () {
+    'use strict';
+    GM_registerMenuCommand("!!!复制并加到memory", to_memory)
+    GM_registerMenuCommand("!!!复制标题和 url", myCopy(`${pre_str}<a href="${location.href}">${document.title}</a>`))
+
+    function to_memory() {
+        let url = location.href;
+        let title = document.title;
+        let body = {
+            "back": "<p></p>",
+            "front": `<p>url: <a href="${url}">${title}</a></p>`,
+            "period": 0,
+            "onlyText": "",
+            "remindTime": new Date(),
+            "tag": "",
+            "updateTime": "",
+            "userId": 1
+        }
+        if (window.confirm(`${title}\n${location.host}\n`)) {
+            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);
+                }
+            })
+        }
+    }
+
+    document.onkeydown = function (ev) {
+        if (ev.key === 'c' && ev.shiftKey) {
+            ev.preventDefault() // 关闭浏览器快捷键
+            myCopy(`${pre_str}<a href="${location.href}">${document.title}</a>`)
+        }
+
+    }
+})();

+ 0 - 0
tmp/monkey/tmp.js


+ 35 - 1
tmp/monkey/util.js

@@ -23,4 +23,38 @@ function addNewStyle(newStyle) {
         document.getElementsByTagName('head')[0].appendChild(styleElement);
     }
     styleElement.appendChild(document.createTextNode(newStyle));
-}
+}
+
+//直接读取浏览器url
+function GetQueryString(name) {
+    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
+    var r = location.href.substring(location.href.indexOf('?') + 1).match(reg); //获取url中"?"符后的字符串并正则匹配
+    var context = "";
+    if (r != null)
+        context = r[2];
+    reg = null;
+    r = null;
+    return context == null || context === "" || context === "undefined" ? "" : decodeURI(context);
+}
+function getRandomInt(min, max) {
+    min = Math.ceil(min);
+    max = Math.floor(max);
+    return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive
+}
+function myCopy(inner_html) {
+    let tmpId = "tmpId123123" + getRandomInt(1, 10000);
+    let a = document.createElement('div');
+    a.id = tmpId;
+    a.innerHTML = inner_html
+    document.querySelector('body').appendChild(a)
+    let range = document.createRange();
+    range.selectNode(document.querySelector("#" + tmpId));
+    // 清除选择
+    window.getSelection().removeAllRanges();
+    window.getSelection().addRange(range);
+    console.log('复制成功');
+    document.execCommand('copy');
+    // 清除选择
+    window.getSelection().removeAllRanges();
+    document.querySelector("#" + tmpId).remove();
+}