zoukankan      html  css  js  c++  java
  • 用户脚本模板

    //manifest.json(chrome)

     1 {
     2    "content_scripts": [ {
     3       "exclude_globs": [  ],
     4       "include_globs": [  ],
     5       "js": [ "userscript.user.js" ],
     6       "matches": [ "http://*/*", "https://*/*" ]
     7    } ],
     8    "converted_from_user_script": true,
     9    "description": "some description",
    10    "manifest_version": 2,
    11    "name": "userscript",
    12    "permissions": [ "tabs", "notifications", "http://*/*"],
    13    "version": "1.0"
    14 }

    //manifest.xml(sogou)

     1 <?xml version="1.0" encoding="utf-8"?> 
     2  <extension> 
     3  <id>jieyuefeng.userscript.sogou</id> 
     4  <name>userscript</name> 
     5  <show_icon>false</show_icon> 
     6  <description>some description</description> 
     7  <version>2.0</version>
     8  <request_api_version>1</request_api_version>
     9  <author>jieyuefeng</author>
    10  <content_scripts> 
    11        <content_script> 
    12            <match>http://*/*</match>
    13            <match>https://*/*</match>
    14            <js>userscript.user.js</js> 
    15        </content_script>
    16  </content_scripts>
    17  </extension>

    //userscript.user.js

     1 // ==UserScript==
     2 // @name        userscript
     3 // @namespace   sunmi.sinaapp.com
     4 // @description some description
     5 // @include     http://*/*
     6 // @include     https://*/*
     7 // @version     1
     8 // ==/UserScript==
     9 
    10 function withjQuery(callback, safe){
    11     if(typeof(jQuery) == "undefined") {
    12         var script = document.createElement("script");
    13         script.type = "text/javascript";
    14         script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js";
    15         
    16         if(safe) {
    17             var cb = document.createElement("script");
    18             cb.type = "text/javascript";
    19             cb.textContent = "jQuery.noConflict();(" + callback.toString() + ")(jQuery);";
    20             script.addEventListener('load', function() {
    21                 document.head.appendChild(cb);
    22             });
    23         }
    24         else {
    25             var dollar = undefined;
    26             if(typeof($) != "undefined") dollar = $;
    27             script.addEventListener('load', function() {
    28                 jQuery.noConflict();
    29                 $ = dollar;
    30                 callback(jQuery);
    31             });
    32         }
    33         document.head.appendChild(script);
    34     } else {
    35         callback(jQuery);
    36     }
    37 }
    38 
    39 withjQuery(function($){
    40 
    41     //do something
    42         
    43 }, true);
  • 相关阅读:
    七天冲刺04
    软件工程概论项目——典型用户场景分析
    七天冲刺3
    七天冲刺2
    七天冲刺1
    第十三周总结
    软件工程概论个人作业02
    第二周学习进度
    软件工程个人作业01--四则运算
    连接数据库的javaee编译简易的WEB登陆界面
  • 原文地址:https://www.cnblogs.com/jieyuefeng/p/3006593.html
Copyright © 2011-2022 走看看