赞
踩
// ==UserScript== // @name cds_test // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author You // @match https://bbs.tampermonkey.net.cn/thread-88-1-1.html // @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net.cn // @grant none // @require file:///Users/chendongsheng/github/force_mokey/first_test/cds.js // ==/UserScript== (function() { 'use strict'; // Your code here... alert("cds first hello world") })();
其中的注释有几个需要注意的:
name
该属性描述油猴这个插件的名字match
该属性描述在那些网址,该插件生效require
该属性描述该脚本依赖本地的文件地址,一般用于本地开发1.进入管理面板
油猴插件自身的设置里面,是有AP I文档的,但是比较奇怪,叫做支持~
API分为2个部分,第一部分是在讲头文件的配置方法,第二部分是在讲油猴自身的API。
@name 插件的名字 @version 插件的版本 @description 描述部分 @grant 类似C语言的include,python的import @author 作者 @require https://code.jquery.com/jquery-2.1.3.min.js#sha256=23456... @require 加载资源,支持md5和sha256验证 @include 加载资源 @match 在那些网址上启用该插件,支持正则匹配。 // @match *://*/* // @match https://*/* // @match http://*/foo* // @match https://*.tampermonkey.net/foo*bar @exclude 排除哪些网址
GM_addElement(tag_name, attributes), GM_addElement(parent_node, tag_name, attributes) GM_addElement('script', { textContent: 'window.foo = "bar";' }); GM_addElement('script', { src: 'https://example.com/script.js', type: 'text/javascript' }); GM_addElement(document.getElementsByTagName('div')[0], 'img', { src: 'https://example.com/image.png' }); GM_addElement(shadowDOM, 'style', { textContent: 'div { color: black; };' });
GM_addStyle(css)
GM_download(details), GM_download(url, name)
GM_getResourceText(name)
const scriptText = GM_getResourceText("myscript.js");
const script = document.createElement("script");
script.textContent = scriptText;
document.body.appendChild(script);
GM_getResourceURL(name)
const imageUrl = GM_getResourceURL("myimage.png");
const image = document.createElement("img");
image.src = imageUrl;
document.body.appendChild(image);
GM_log(message)
GM_notification(details, ondone), GM_notification(text, title, image, onclick)
GM_openInTab(url, options), GM_openInTab(url, loadInBackground)
GM_registerMenuCommand(name, callback, options_or_accessKey)
GM_unregisterMenuCommand(menuCmdId)
GM_setClipboard(data, info)
关于tab的几个函数
KV
GM_setValue(key, value)
GM_getValue(key, defaultValue)
GM_deleteValue(key)
GM_listValues()
GM_addValueChangeListener(key, (key, old_value, new_value, remote) => void)
GM_removeValueChangeListener(listenerId)
GM_xmlhttpRequest(details)
GM_webRequest(rules, listener)
cookie部分的API不常用, 暂时不记录。
window管理
window.onurlchange
window.close
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。