• 油猴脚本尝试


    现在是这样的,我这边有个运维系统,里面有个日志,我们经常要复制,然后我们复制的时候需要打开内容,然后去选中复制。

    类似于这种,我觉得这个时候,去选中复制就很麻烦,右边这里不是有了吗。
    那我就想能不能点击左上角就复制内容。

    然后我现在的思路就是用油猴
    因为日志内容是我们接口查询后动态插入的,那我们就动态监听dom,如果有元素新增,就查询新出来的元素,给他加上点击事件,点击复制内容到粘贴版。

    这种日常的脚本小工具,我觉得应该还是可以用的。

    那我们现在就是要先学会使用油猴,学会监听元素新增。将内容复制进粘贴板。

    // ==UserScript==
    // @name         运维系统复制脚本
    // @namespace    http://tampermonkey.net/
    // @version      0.1
    // @description  try to take over the world!
    // @author       You
    // @match        http://192.168.88.167:8084/*
    // @icon         https://www.google.com/s2/favicons?sz=64&domain=88.167
    // @grant        GM.setClipboard
    // ==/UserScript==
    
    (function() {
        'use strict';
    
      window.onload=function(){
    
    
              var mutation= new MutationObserver(function(mutations,observer) {
        mutations.forEach(function(mutation) {
               if (mutation.type == 'childList') {
                    var datas=document.querySelectorAll(".ivu-table-cell .ivu-poptip .ivu-poptip-rel");
                       if(datas.length>0){
                            datas.forEach(function e(each) {
    
                                     each.onclick=function e(event){
                                      GM.setClipboard(event.target.innerText)
                                   }
    
                       })
    
                       }
               }
        });
    });
    var targetNode = document.getElementsByClassName("ivu-table-tip")[0];
    
    mutation.observe(targetNode, {
        childList: true,
        subtree: true
    });
          }
        // 监听页面变化
        // 监听页面变化
    
    
        // Your code here...
    })();
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47

    关键点,@match 对那个页面进行匹配执行脚本
    页面加载完成后 window.onload 等页面加载完成后监听表格元素
    如果有事件,查看下新出来的元素,有的话加上点击事件。
    然后复制内容进粘贴版本。
    其实这里有两种思路,一种是定时任务,一直查看元素有没有新增,一种就是我这种,监听父元素,有新元素就加时间,或者包装事件。

    https://www.cnblogs.com/wgb1234/p/16499981.html

    https://blog.csdn.net/qq_35385241/article/details/121989261

    https://maoshu.fun/posts/cc7c94cd.html

    https://blog.csdn.net/weixin_30536513/article/details/98380630

  • 相关阅读:
    Matlab 2016安装MinGW-w64-4.9.2
    算法设计与分析学习笔记之二分查找算法
    Polygon zkEVM Memory Align状态机
    LeetCode周赛317场 && AcWing周赛77场总结
    明明设计的是高带宽,差点加工成开路?
    【Try to Hack】vulnhub DC1
    Jenkins部署与基础配置(1)
    选择排序--java(详解)
    golang中如何配置 sql.DB 以获得更好的性能
    unity资源管理之Addressable
  • 原文地址:https://blog.csdn.net/Wzy000001/article/details/130886633