• Tampermonkey 油猴脚本例子


    // ==UserScript==
    // @name         数据召测
    // @namespace    http://tampermonkey.net/
    // @version      0.1.0303
    // @description  try to take over the world!
    // @author       You
    // @match        http://0.0.0.0/*
    // @grant        none
    // ==/UserScript==
    
    (function() {
        'use strict';
        console.info("油猴脚本启动");
        function init(){
            //console.info("init");
            let vbody = document.getElementsByTagName('body')[0]
            let vdiv = document.createElement('div')
            vdiv.setAttribute('id','cxldiv')
            vdiv.setAttribute('class','col-sm-12')
            //vbody.appendChild(vdiv)
            document.querySelector("div").appendChild(vdiv)
            vdiv.innerHTML += '  '
            //vdiv.innerHTML += '<input id="cxl_input_cons_no" type="text">'
            vdiv.innerHTML += '<button type="button" onclick="document.myscript_selected()">选记录</button>'
            vdiv.innerHTML += '<button type="button" onclick="document.myscript_changeDataItem()">选数据项</button>'
            vdiv.innerHTML += '<button type="button" onclick="document.myscript_getData()">召测</button>'
            vdiv.innerHTML += '<button id="cxlbtn_save" type="button" onclick="document.myscript_saveResult()">保存结果</button>'
            //选电表
            document.myscript_selected = function(){
                //console.info("myscript_myzc")
                //选记录
                document.getElementsByName('btSelectItem')[0].click()
                //选直抄
                document.getElementsByName('taskKind')[1].click()
                //存库
                document.getElementById('saveDb').click()
            }
            //选数据项
            document.myscript_changeDataItem = function(){
                //console.info("myscript_changeDataItem")
                //取消正有示值
                document.getElementById('30901006_anchor').click()
                //选数据项
                document.getElementById('30201001_anchor').click()
                document.getElementById('30301001_anchor').click()
                document.getElementById('30601001_anchor').click()
            }
            //召测
            document.myscript_getData = function(){
                document.getElementById('dataCall').click()
                document.querySelector("#cxlbtn_save").removeAttribute('disabled')
                if (document.myjob_save){
                    clearInterval(document.myjob_save)
                }
                document.myjob_save = setInterval("document.myscript_saveResult()",2000)
    
            }
            //保存召测结果
            document.myscript_saveResult = function(){
                console.info("myscript_saveResult")
                const result = document.getElementById('resultDetail').innerHTML.replace(/	/g,'').replace(/ss/g,'').replace(/<tr.+?>/g,'
    ').replace(/<.+?>/g,' ')
                if(result)
                {
                    console.info(result)
                    clearInterval(document.myjob_save)
    
                    const cons_no = result.match(/用户编号s+d+/)[0].replace(/用户编号/g,'cn')
                    const now = new Date().getTime()
                    document.myscript_download(result, cons_no+' '+now+'.txt')
                    document.querySelector("#cxlbtn_save").setAttribute('disabled','disabled')
                }
            }
            document.myscript_download=function(content, fileName){
                let downLink = document.createElement('a')
                downLink.download = fileName
                //字符内容转换为blod地址
                let blob = new Blob([content])
                downLink.href = URL.createObjectURL(blob)
                // 链接插入到页面
                document.body.appendChild(downLink)
                downLink.click()
                // 移除下载链接
                document.body.removeChild(downLink)
            }
        }
    
        init()
    })();
    
    
  • 相关阅读:
    Shell重新学习(忘光了)
    vim 设置默认显示行号
    maven学习资料(三)
    maven:新建的maven工程需要添加一下插件
    Spring框架:第五章:Spring EL表达式
    Spring框架:第四章:Spring管理数据库连接池
    Spring框架:第三章:对象的生命周期及单例bean生命周期的11个步骤
    Spring框架:第二章:IOC依赖注入及40个实验
    Spring框架:第一章:介绍和准备工作
    MyBatis框架:第十一章:mybatis 逆向工程
  • 原文地址:https://www.cnblogs.com/congxinglong/p/14780894.html
Copyright © 2020-2023  润新知