zoukankan      html  css  js  c++  java
  • 扇贝背单词,增加单词快捷文本复制按钮 需要安装tampermonkey

    // ==UserScript==
    // @name         新增复制按钮
    // @namespace    http://tampermonkey.net/
    // @version      0.1
    // @description  try to take over the world!
    // @author       You
    // @match        https://web.shanbay.com/wordsweb/
    // @icon         https://www.google.com/s2/favicons?domain=shanbay.com
    // @grant        none
    // @require      https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js
    // ==/UserScript==
    
    (function() {
        'use strict';
    
    // 复制的方法
    function copyText(text, callback){ // text: 要复制的内容, callback: 回调
        var tag = document.createElement('input');
        tag.setAttribute('id', 'cp_hgz_input');
        tag.value = text;
        document.getElementsByTagName('body')[0].appendChild(tag);
        document.getElementById('cp_hgz_input').select();
        document.execCommand('copy');
        document.getElementById('cp_hgz_input').remove();
        if(callback) {callback(text)}
    }
    
        function InsertCopyBtn(){
                $(".flex-between div").each(function () {
                  if ($(this).hasClass("VocabPronounce_vcoabPronounce__2D0UH") && !$(this).hasClass("copy") ){
                    $(this).addClass("copy")
           
                    $(this).after('<div ><button type="button" class="copyBtn">Copy</button></div>')
                    $(this).after('<div style="display:none"><input id="copyInput" /></div>')
    
                    var word1="";
                     $(".VocabPronounce_word__17Tma").each(function () {
                        word1=$(this).text()
                      })
    
                    console.log("word:"+word1)
    
                    $("copyInput").attr("value",word1);
                    //增加响应时间
                    $(".copyBtn").each(function () {
                         console.log("增加响应事件");
                           $(this).click(function(){
                               //选择复制内容
                               //const input = document.querySelector('#copyInput');
                               //input.select();
                               // (document.execCommand('copy')) {
                               //    document.execCommand('copy');
                               //    console.log('复制成功');
                               //}
                               //
                               copyText(word1, function (){console.log('复制成功')})
                           });
                      })
                }
            });
        }
        function scanCopyContainer(){
                if ($(".flex-between").length>0){
               
                    InsertCopyBtn()
                }
               setTimeout(scanCopyContainer, 2000);
        }
        $(document).ready(function(){
          //隐藏文本
            setTimeout(scanCopyContainer, 300);
     
        })
        // Your code here...
    })();

  • 相关阅读:
    使用百度网盘配置私有Git服务
    Linked dylibs built for GC-only but object files built for retain/release for architecture x86_64
    我的博客搬家啦!!!
    今日头条核心业务(高级)开发工程师,直接推给部门经理,HC很多,感兴趣的可以一起聊聊。
    学习Python的三种境界
    拿到阿里,网易游戏,腾讯,smartx的offer的过程
    关于计算机网络一些问题的思考
    网易游戏面试经验(三)
    网易游戏面试经验(二)
    网易游戏面试经验(一)
  • 原文地址:https://www.cnblogs.com/jifeng/p/15118372.html
Copyright © 2011-2022 走看看