• 油猴脚本


    1. 自动看视频
      视频点击后会导致重新加载页面,不适合用js做,适合用selenium
    
    // ==UserScript==
    // @name        auto learn
    // @namespace   learn
    
    // @include     http://localhost*
    
    // @require     https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js
    // @require     https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js
    // @require     https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js
    
    // ==/UserScript==
    
    (function () {
        
    // 添加jQuery
        // function jQuery(){
        //   var script = document.createElement('script');
        //   script.src = 'https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js';
        //   document.body.appendChild(script);
        // }
      
        const refreshTime = 10000;
        var  playList = $('span[class="f-ib w100 text-etc"]');
    
        setInterval(function () {
            $.each(playList,function(k,v) {
              setTimeout(function(){
              v.click();
              console.log('amize in:'+v);
              },k*20000);
            });
        }, refreshTime);
    
      
    
    
    })();
    
    
    
    1. 工作中使用
    
    // ==UserScript==
    // @name        A3 Login 
    // @namespace   A3 Test
    // @include      *admin/alt#/login
    // @include      *admin/alt#/logout
    // @require     https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js
    // @require     https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js
    // @require     https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js
    
    // ==/UserScript==
    
    
    (function () {
        
    // 添加jQuery
        // function jQuery(){
        //   var script = document.createElement('script');
        //   script.src = 'https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js';
        //   document.body.appendChild(script);
        // }
        
    // 添加Bootstrap js
        // function addBootstrapJS(){
        //   let bootstrapJSLink = '
        //     <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) -->
        //     <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
        //     <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
        //     <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
        //     ';
        //   $(bootstrapJSLink).appendTo($('body'));
        // }
        // addBootstrapJS()
      
    // 添加Bootstrap css
        function addBootstrap(){
          let bootstrapLink = '<link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">';
          $(bootstrapLink).appendTo($('head'));
        }
        addBootstrap()
     
    
    // uve框架模拟用户输入
      // const event = document.createEvent('HTMLEvents');
      // event.initEvent('input', false, true);
      // document.querySelector("#username").value="user";
      // document.querySelector("#username").dispatchEvent(event);
      // document.querySelector("#password").value="password";
      // document.querySelector("#password").dispatchEvent(event);
      // document.querySelector('button[type=submit]').click();
      
      
      
    // 添加二/三层菜单  
    //     var list=[
    //         {name:"第1章",value:["第一课","第二课","第三课","第四课"]},
    //         {name:"第2章",value:["第一课","第二课","第三课","第四课"]},
    //         {name:"第3章",value:["第一课","第二课","第三课","第四课"]}
    //     ];
        
    //     function initList() {
    //         createUl(list,document.getElementById("div11"));
    //         var lis=document.querySelectorAll("li");
    //         for (var i=0;i<lis.length;i++){
    //             lis[i].addEventListener("click",clickHandler);
    //         }
    //     }
    //     function createUl(_list,parent) {
    //         var ul=document.createElement("ul");
    //         ul.setAttribute("style","display:inline-block");
    //         // ul.setAttribute("style","list-style-type:none");
    //         // ul.setAttribute("style","list-style:none");
    //         // ul.setAttribute("style"," margin-left:100");
       
    //         if (Array.isArray(_list)) {
    //             for (var i = 0; i < _list.length; i++) {
    //                 var li = document.createElement("li");
    //                 if (_list[i].name) {
    //                     li.innerHTML = _list[i].name;
    //                     // li.display="none";
    //                     // li.setAttribute("style","float:left");
    //                 } else {
    //                     li.innerHTML = _list[i];
    //                     // li.display="none";
    //                     // li.setAttribute("style","float:left");
    //                 }
    //                 if (Array.isArray(_list[i].value)) {
    //                     createUl(_list[i].value, li);
    //                 }
    //                 ul.appendChild(li);
    //             }
    //         }
    //         parent.appendChild(ul);
    //     }
    //     function clickHandler(e) {
    //         e.stopPropagation();//阻止冒泡
    //         if (!this.firstElementChild) return;
    //         this.bool=!this.bool;
    //         if (this.bool) this.firstElementChild.style.display="none";
    //         if (!this.bool) this.firstElementChild.style.display="block";
    //     }  
        
          // initList();
    
    
      
        //定义insterAfter
        function insterAfter(newElement,targetElement){
        var parent = targetElement.parentNode;
        if(parent.lastChild == targetElement){
               parent.appendChild(newElement);
          }
        else{
               parent.insertBefore(newElement,targetElement.nextSibling);
         }              
        }
        
        //加主要div
        var div1 = document.createElement("div");
        div1.setAttribute("id", "div1");
        div1.setAttribute("class", "div1");
        div1.setAttribute("style","z-index:999");	
        div1.innerHTML = "<div id='div11' style='float: left'> </div>"
        document.body.appendChild(div1);
    
    
        //加个搜索按钮
        var bt1 = document.createElement("button");
        bt1.setAttribute("name", "bt1");
        bt1.setAttribute("class", "baidu");
        bt1.setAttribute("id", "bt1");
        bt1.innerHTML = "百度一下";
        bt1.setAttribute("style","float:left");	
        bt1.setAttribute("style"," 100px;height: 36px;margin: 1px;color: #fff;font-size: 15px;letter-spacing: 1px;background: #3385ff;border-bottom: 1px solid #2d78f4;text-align: center;cursor:pointer;border:0;");
        document.getElementById("div11").appendChild(bt1);
    
      
        //加个bootstrap 类型元素
    //       let modalHtml = `
    //         <div class="btn-group" role="group" aria-label="...">
    //             <div class="btn-group" role="group">
    //                 <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
    //                         aria-expanded="false">
    //                     Dropdown
    //                     <span class="caret"></span>
    //                 </button>
    //                 <ul class="dropdown-menu">
    //                     <li><a href="#">Dropdown link</a></li>
    //                     <li><a href="#">Dropdown link</a></li>
    //                 </ul>
    //             </div>
    //             <div class="btn-group" role="group">
    //                 <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true"
    //                         aria-expanded="false">
    //                     Dropdown
    //                     <span class="caret"></span>
    //                 </button>
    //                 <ul class="dropdown-menu">
    //                     <li><a href="#">Dropdown link</a></li>
    //                     <li><a href="#">Dropdown link</a></li>
    //                 </ul>
    //             </div>
    //         </div>
    // <ul class="nav nav-tabs">
    //   <li role="presentation" class="active"><a href="#">Home</a></li>
    //   <li role="presentation"><a href="#">Profile</a></li>
    //   <li role="presentation"><a href="#">Messages</a></li>
    // </ul>
    
    //     `;
      
    //     // $(modalHtml).appendTo($('body'));
    //     /* 设定css */
    //     // $('#modal .btn').css({
    //     //   'width':'150px',
    //     //   'text-align':'center',
    //     //   'margin':'5px',
    //     //   'float':'right'
    //     // });
    //     $(modalHtml).appendTo($('#div1'));
      
      
      
    // <li  class="nav-item b-nav-dropdown dropdown pf-label" id="a3test_li"><a aria-haspopup="true"
    //                                                                                             aria-expanded="false"
    //                                                                                             target="_self" href="#"
    //                                                                                             class="nav-link dropdown-toggle dropdown-toggle-no-caret"
    //                                                                                             id="a3test_a"> a3test</a>
    //     <ul tabindex="-1" class="dropdown-menu dropdown-menu-right" aria-labelledby="__BVID__41__BV_button_">
    //         <li data-v-b7159e12="" role="presentation">
    //             <button role="menuitem" type="button" class="dropdown-item">Français</button>
    //         </li>
    //         <li data-v-b7159e12="" role="presentation">
    //             <hr data-v-b7159e12="" role="separator" aria-orientation="horizontal" class="dropdown-divider">
    //         </li>
    //         <li data-v-b7159e12="" role="presentation"><a href="#/licenses" class="dropdown-item" role="menuitem"
    //                                                       target="_self">Manage Licenses</a></li>
    //         <li data-v-b7159e12="" role="presentation">
    //             <hr data-v-b7159e12="" role="separator" aria-orientation="horizontal" class="dropdown-divider">
    //         </li>
    //         <li data-v-b7159e12="" role="presentation"><a href="#/logout" class="dropdown-item" role="menuitem"
    //                                                       target="_self">Log out</a></li>
    //     </ul>
    // </li>
      
      
        let a3test_li = `
          <li  class="nav-item b-nav-dropdown dropdown show" id="a3test_li">
              <a aria-haspopup="true" aria-expanded="false" target="_self" href="#"
                class="nav-link dropdown-toggle dropdown-toggle-no-caret" id="a3test_a">a3test</a>
    
              <ul tabindex="-1" class="dropdown-menu dropdown-menu-right show" aria-labelledby="__BVID__41__BV_button_">
                  <li data-v-b7159e12="" role="presentation">
                      <button role="menuitem" type="button" class="dropdown-item">Français</button>
                  </li>
                  <li data-v-b7159e12="" role="presentation">
                      <hr data-v-b7159e12="" role="separator" aria-orientation="horizontal" class="dropdown-divider">
                  </li>
                  <li data-v-b7159e12="" role="presentation"><a href="#/licenses" class="dropdown-item" role="menuitem"
                                                                target="_self">Manage Licenses</a></li>
                  <li data-v-b7159e12="" role="presentation">
                      <hr data-v-b7159e12="" role="separator" aria-orientation="horizontal" class="dropdown-divider">
                  </li>
                  <li data-v-b7159e12="" role="presentation"><a href="#/logout" class="dropdown-item" role="menuitem"
                                                                target="_self">Log out</a></li>
              </ul>
          </li>
        `;
      
        $(a3test_li).appendTo($(".navbar-nav:not(.notifications)").eq(1));
      
      
    
      
      
      
        //加ul div 111111
        // var div12 = document.createElement("div");
        // div12.setAttribute("id", "div12");
        // div12.setAttribute("style","float:left");	
        // div12.setAttribute("class","divhide");	
        // div12.innerHTML = "<ul type='none' >" 
        //   +"<li>111 <a href='#/configuration/roles'>test111</a> </li>"
        //   +"<li>222</li>"
        //   +"</ul>";
      
        // insterAfter(div12,document.getElementById("div11"));
      
        //加ul div 222222
        let div12 = `
          <div class="btn-group" role="group" aria-label="...">
            <a href='#/configuration/roles'>test111</a>
          </div>
        `;
        
        $(div12).appendTo($('#div1'));
        
      
      
        $("body").on("click","div .baidu",function () {
          console.log(this);
          var bt = document.createElement("button");
          // bt.setAttribute("name", "bt1");
          bt.innerHTML = "百度一下";
          bt.setAttribute("class", "baidu");
          bt.setAttribute("style"," 100px;height: 36px;margin: 1px;color: #fff;font-size: 15px;letter-spacing: 1px;background: #3385ff;border-bottom: 1px solid #2d78f4;text-align: center;cursor:pointer;border:0;");
          // bt.setAttribute("style","z-index:999");	
          // bt.setAttribute("style"," 100px;height: 300px;margin: 1px;");
           
          // var first=document.body.firstChild;
          // var first= document.getElementsByTagName("nav");
          // document.body.insertBefore(bt,first);
          // $(".divhide").slideUp(1000);
          $(".divhide").slideToggle(1000);
          div1.appendChild(bt);
        });
        
    
         
      
    })();
    
    
    
    
    
    
    
  • 相关阅读:
    Redis
    Maven总结
    spring知识点总结
    网上好文搜集整理
    python 代码删除空目录
    plantUML使用指南
    python的基础操作
    八卦基础编程学习
    python历年入坑记录大全
    python实现的百度云自动下载
  • 原文地址:https://www.cnblogs.com/amize/p/14424110.html
Copyright © 2020-2023  润新知