油猴腳本API


參考

油猴文檔
本地開發調試設置
深入淺出 Greasemonkey 這個類似油猴,但是火狐上的,有pdf可下
跨頁面傳值的方式
跨頁面傳值-這個應該是操作storage

補充:設置chrome采用默認打印設置,靜默打印不彈框

Userscript Header

用戶腳本頭,用於放在腳本開頭的注釋部分,代表了腳本本身的一些信息,如在哪些頁面被調用,有哪些權限等

@name

The name of the script.
腳本名稱

Internationalization is done by adding an appendix naming the locale.
國際化是通過添加一個命名區域的附錄來完成的。(用於展示不同語言的腳本名稱,見下面)

Code:

// @name A test  
// @name:de Ein Test  

@namespace

The namespace of the script.
腳本的命名空間

@version

The script version. This is used for the update check, in case the script is not installed from userscript.org or TM has problems to retrieve the scripts meta data.
腳本版本。用於更新檢查,以防不是從userscript.org TM(即 tampermonkey 油猴本身) 安裝腳本的用戶在檢索腳本元數據時遇到問題。

@author

The scripts author.
腳本作者

@description

A short significant description.
簡短而有意義的描述。

Internationalization is done by adding an appendix naming the locale.
國際化是通過添加一個命名語言環境的附錄來完成的(如下:)

Code:

// @description This userscript does wonderful things  
// @description:de Dieses Userscript tut wundervolle Dinge  
// @description:zh 中文的描述內容

@homepage, @homepageURL, @website and @source

The authors homepage that is used at the options page to link from the scripts name to the given page. Please note that if the @namespace tag starts with 'http://' its content will be used for this too.
用於設置訪問腳本作者主頁的鏈接,位於油猴的控制面板對應腳本的主頁項。請注意,如果@namespace標記以“http://”開頭,則其內容也將用於此目的。

@icon, @iconURL and @defaulticon

The script icon in low res.
低分辨率的腳本圖標。

@icon64 and @icon64URL

This scripts icon in 64x64 pixels. If this tag, but @icon is given the @icon image will be scaled at some places at the options page.
此腳本圖標為64x64像素。如果這個標簽,但是給了 @icon@icon 圖像將在選項頁的某些地方縮放。???

@updateURL

An update URL for the userscript.
Note: a @version tag is required to make update checks work.
用戶腳本的更新URL。
注意:需要 @version 標記才能進行更新檢查。

@downloadURL

Defines the URL where the script will be downloaded from when an update was detected. If the value none is used, then no update check will be done.
定義檢測到更新時將從中下載腳本的URL。如果使用值none,則不會執行更新檢查。

@supportURL

Defines the URL where the user can report issues and get personal support.
定義用戶可以在其中報告問題和獲得個人支持的URL。

@include

The pages on that a script should run. Multiple tag instances are allowed.
Please note that @include doesn't support the URL hash parameter. You have to match the path without the hash parameter and make use of window.onurlchange

腳本應該運行的頁面。允許多個標記實例。
請注意,@include不支持URL散列參數(即URL中帶有md5之類的參數,用來檢查URL指定的文件是否匹配)。必須匹配不帶哈希參數的路徑,同時要使用 window.onurlchange(監聽url改變的權限,見@grant部分)

Code:

// @include http://www.tampermonkey.net/*  
// @include http://*  
// @include https://*  
// @include /^https:\/\/www\.tampermonkey\.net\/.*$/ // @include *  

@match

More or less equal to the @include tag. You can get more information here .
Note: the '<all_urls>' statement is not yet supported and the scheme part also accepts 'http*😕/'.

Multiple tag instances are allowed.

類似於@include標記。更多信息
注意:尚不支持“<all_url>”語句,並且方案部分也接受“http*://”。

允許多個標記實例。

@match 和 @include 是有一點區別的
match更嚴格一點,它對 * 的含義設定了更嚴格的規則,具體怎么個嚴格法?鬼知道

@exclude

Exclude URLs even it they are included by @include or @match .
Multiple tag instances are allowed.

排除URL,即使它們被@include或@match包含。
允許多個標記實例。

@require

Points to a JavaScript file that is loaded and executed before the script itself starts running.
Note: the scripts loaded via @require and their "use strict" statements might influence the userscript's strict mode!

指定在腳本本身開始運行之前就要加載並執行的JavaScript文件。
注意:通過@require加載的腳本及其“use strict”語句可能會影響用戶腳本的嚴格模式!

Code:

// @require https://code.jquery.com/jquery-2.1.4.min.js  
// @require https://code.jquery.com/jquery-2.1.3.min.js#sha256=23456...  
// @require https://code.jquery.com/jquery-2.1.2.min.js#md5=34567...,sha256=6789...  
// @require tampermonkey://vendor/jquery.js  
// @require tampermonkey://vendor/jszip/jszip.js  

Please check the sub-resource integrity section for more information how to ensure integrity. Multiple tag instances are allowed.
有關如何確保完整性的更多信息,請查看子資源完整性部分。允許多個標記實例。

@resource

Preloads resources that can by accessed via GM_getResourceURL and GM_getResourceText by the script.
預加載可以通過腳本通過GM_getResourceURL和GM_getResourceText訪問的資源。

Code:

// @resource icon1 http://www.tampermonkey.net/favicon.ico  
// @resource icon2 /images/icon.png  
// @resource html http://www.tampermonkey.net/index.html  
// @resource xml http://www.tampermonkey.net/crx/tampermonkey.xml  
// @resource SRIsecured1 http://www.tampermonkey.net/favicon.ico#md5=123434...  
// @resource SRIsecured2 http://www.tampermonkey.net/favicon.ico#md5=123434...;sha256=234234...  

Please check the sub-resource integrity section for more information how to ensure integrity. Multiple tag instances are allowed.
有關如何確保完整性的更多信息,請查看子資源完整性部分。允許多個標記實例。

@connect

This tag defines the domains (no top-level domains) including subdomains which are allowed to be retrieved by GM_xmlhttpRequest
此tag用於定義域名(不包括頂級域),包括允許GM_xmlhttpRequest檢索的子域

Code:

// @connect <value>  

<value> can have the following values:
<value>可選值如下

  • domains like tampermonkey.net (this will also allow all sub-domains)
  • sub-domains i.e. safari.tampermonkey.net
  • self to whitelist the domain the script is currently running at
  • localhost to access the localhost
  • 1.2.3.4 to connect to an IP address
  • *

If it's not possible to declare all domains a userscript might connect to then it's a good practice to do the following:
Declare all known or at least all common domains that might be connected by the script. This way the confirmation dialog can be avoided for most of the users.
如果無法聲明用戶腳本可能連接到的所有域,那么最好執行以下操作:
聲明腳本可能連接的所有已知域或至少所有公共域。這樣可以避免大多數用戶使用確認對話框。

Additionally add "@connect *" to the script. By doing so Tampermonkey will still ask the user whether the next connection to a not mentioned domain is allowed, but also offer a "Always allow all domains" button. If the user clicks at this button then all future requests will be permitted automatically.
另外在腳本中添加“@connect *”。這樣做,Tampermonkey仍然會詢問用戶是否允許下一次連接到未提及的域,但也會 提供一個“始終允許所有域”按鈕。如果用戶單擊此按鈕,則將自動允許所有未來的請求。

Users can also whitelist all requests by adding '*' to the user domain whitelist at the script settings tab.
用戶還可以通過將“*”添加到“腳本設置”選項卡上的“用戶域白名單”來將所有請求列入白名單。

Notes:

  • both, the initial and the final URL will be checked!
  • for backward compatibility to Scriptish @domain tags are interpreted as well.

注意:
初始和最終的網址都將被檢查!
為了向后兼容,@domain標記也一如既往地進行了解析。

Multiple tag instances are allowed.
允許多個標記實例。

@run-at

Defines the moment the script is injected. In opposition to other script handlers, @run-at defines the first possible moment a script wants to run. This means it may happen, that a script that uses the @require tag may be executed after the document is already loaded, cause fetching the required script took that long. Anyhow, all DOMNodeInserted and DOMContentLoaded events that happended after the given injection moment are cached and delivered to the script when it is injected.

定義注入腳本的時刻。與其他腳本處理程序相反,@run at 定義了腳本想要運行的第一個可能時刻。這意味着可能會發生這樣的情況:使用@require標記的腳本可能會在文檔已經加載之后執行,因為獲取所需的腳本需要很長時間。無論如何,在給定的注入時刻之后發生的所有 DOMNodeInserted 和 DOMContentLoaded 事件都會被緩存,並在注入腳本時傳遞給腳本。

Code:

// @run-at document-start  

The script will be injected as fast as possible.
腳本將盡快注入。

Code:

// @run-at document-body  

The script will be injected if the body element exists.
如果body元素存在,腳本將被注入。

Code:

// @run-at document-end  

The script will be injected when or after the DOMContentLoaded event was dispatched.
在調度DOMContentLoaded事件時或之后將注入腳本。

Code:

// @run-at document-idle  

The script will be injected after the DOMContentLoaded event was dispatched. This is the default value if no @run-at tag is given.
在調度DOMContentLoaded事件之后,將注入腳本。如果沒有給出@run at標記,這是默認值。

Code:

// @run-at context-menu  

The script will be injected if it is clicked at the browser context menu (desktop Chrome-based browsers only).
Note: all @include and @exclude statements will be ignored if this value is used, but this may change in the future.

如果在瀏覽器上下文菜單中單擊腳本(僅限於基於Chrome的桌面瀏覽器),則會注入腳本。
注意:如果使用此值,所有@include和@exclude語句都將被忽略,但這可能會在將來更改。

@grant

@grant is used to whitelist GM_* functions, the unsafeWindow object and some powerful window functions. If no @grant tag is given TM guesses the scripts needs.
@grant (授予)用於白名單 GM_* 函數、unsafeWindow 對象和一些強大的窗口函數。如果沒有給@grant標記,TM 將猜測腳本需要什么。

Code:

// @grant GM_setValue  
// @grant GM_getValue  
// @grant GM_setClipboard  
// @grant unsafeWindow  
// @grant window.close  
// @grant window.focus  
// @grant window.onurlchange  

Since closing and focusing tabs is a powerful feature this needs to be added to the @grant statements as well.
If a script runs on a single-page application, then it can use window.onurlchange to listen for URL changes:

由於關閉和聚焦選項卡(瀏覽器頁面)是一項強大的功能,因此需要將其添加到@grant語句中。
如果腳本在單頁應用程序上運行,那么它可以使用 window.onurlchange 來偵聽URL更改:

Code:

// ==UserScript==  
...  
// @grant window.onurlchange  
// ==/UserScript==  
  
if (window.onurlchange === null) {  
    // feature is supported  
    window.addEventListener('urlchange', (info) => ...);  
}  

If @grant is followed by 'none' the sandbox is disabled and the script will run directly at the page context. In this mode no GM_* function but the GM_info property will be available.
如果@grant后跟着“none”,那么沙盒將被禁用,腳本將直接在頁面上下文中運行。在這種模式下,沒有 GM_* 函數,但是GM_info屬性可用。

Code:

// @grant none

@antifeature

This tag allows script developers to disclose whether they monetize their scripts. It is for example required by GreasyFork.
這個標簽允許腳本開發人員披露他們是否將腳本貨幣化(通過腳本盈利)。例如,GreasyFork 腳本網站 需要這個標簽。

Syntax:

<type> can have the following values:

  • ads 廣告
  • tracking 跟蹤
  • miner 礦工

Code:

// @antifeature ads We show you ads  
// @antifeature:fr ads Nous vous montrons des publicités  
// @antifeature tracking We have some sort of analytics included  
// @antifeature miner We use your computer's resources to mine a crypto currency  

Internationalization is done by adding an appendix naming the locale.
國際化是通過添加一個命名語言環境的附錄來完成的(見前文說明)。

@noframes

This tag makes the script running on the main pages, but not at iframes.
此標記使腳本在主頁上運行,但不在iframe(即一個頁面內嵌套的頁面,詳見html內容)上運行。

@unwrap

This tag is ignored because, it is not needed at Google Chrome/Chromium.
這個標簽被忽略了,因為Google Chrome/Chromium不需要它。

@nocompat

At the moment TM tries to detect whether a script was written in knowledge of Google Chrome/Chromium by looking for the @match tag, but not every script uses it. That's why TM supports this tag to disable all optimizations that might be necessary to run scripts written for Firefox/Greasemonkey. To keep this tag extensible you can to add the browser name that can be handled by the script.

目前,TM通過查找@match標記來檢測腳本是否是在Google Chrome/Chromium的規范下編寫的,但並不是每個腳本都使用它。這就是為什么TM支持用這個標簽來禁用所有的優化,因為為了能夠運行那些專為 Firefox/Greasemonkey 編寫的腳本這么做可能是必須的。如果要保持此標記的可擴展性,可以通過添加可由腳本處理的瀏覽器名稱來實現。

Code:

// @nocompat Chrome

Application Programming Interface 油猴應用程序接口(API)

unsafeWindow

The unsafeWindow object provides full access to the pages javascript functions and variables.
unsafeWindow對象提供對頁面的javascript函數和變量的完全訪問。

Subresource Integrity

子資源完整性

The hash component of the URL of @resource and @require tags can be used for this purpose.
@resource和@require標記的URL的哈希組件可用於此目的。

Code:

// @resource SRIsecured1 http://www.tampermonkey.net/favicon1.ico#md5=ad34bb...  
// @resource SRIsecured2 http://www.tampermonkey.net/favicon2.ico#md5=ac3434...,sha256=23fd34...  
// @require https://code.jquery.com/jquery-2.1.1.min.js#md5=45eef...  
// @require https://code.jquery.com/jquery-2.1.2.min.js#md5=ac56d...,sha256=6e789...  

TM supports MD5 hashes as a fallback natively, all other (SHA-1, SHA-256, SHA-384 and SHA-512) depend on window.crypto. In case multiple hashes (separated by comma or semicolon) are given the last currently supported one is used by TM. If the content of the external resource doesn't match the selected hash, then the resource is not delivered to the userscript. All hashes need to be encoded in hex or Base64 format.

TM 支持MD5哈希作為后備默認,所有其他哈希(SHA-1、SHA-256、SHA-384和SHA-512)依賴於window.crypto. 如果給出了多個散列(用逗號或分號分隔),則TM將使用當前支持的最后一個散列。如果外部資源的內容與所選哈希不匹配,則資源不會傳遞到用戶腳本。所有哈希都需要以十六進制或Base64格式編碼。

GM_addStyle(css)

Adds the given style to the document and returns the injected style element.
將給定的樣式添加到文檔並返回注入的樣式元素。

GM_addElement(tag_name, attributes), GM_addElement(parent_node, tag_name, attributes)

Creates an HTML element specified by 'tag_name' and applies all given 'attributes' and returns the injected HTML element. If a 'parent_node' is given, then it is attached to it or to document head or body otherwise.
創建一個由“tag_name”指定的HTML元素,應用所有給定的“屬性”,並返回注入的HTML元素。如果給定了“父節點”,則它將附加到該節點否則附加到文檔頭或文檔體。

For suitable 'attributes', please consult the appropriate documentation. For example:
合適的“屬性”,請參閱相應的文檔。例如:

Code:

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; };'  
});  

Note: this feature is experimental and the API may change.
注意:此功能是實驗性的,API可能會更改。

GM_deleteValue(name)

Deletes 'name' from storage.
從存儲器中刪除指定name(變量?)。

GM_listValues()

List all names of the storage.
列出存儲的所有name(變量?)。

GM_addValueChangeListener(name, function(name, old_value, new_value, remote) {})

Adds a change listener to the storage and returns the listener ID.
'name' is the name of the observed variable.
The 'remote' argument of the callback function shows whether this value was modified from the instance of another tab (true) or within this script instance (false).
Therefore this functionality can be used by scripts of different browser tabs to communicate with each other.

將一個變動監聽器添加到存儲並返回監聽器ID。
“name”是被監測變量的名稱。
回調函數的“remote”參數顯示此變量是從另一個選項卡的實例修改的(true),還是在此腳本實例中修改的(false)。
因此,瀏覽器不同選項卡的腳本可以使用此功能相互通信。

GM_removeValueChangeListener(listener_id)

Removes a change listener by its ID.
刪除指定ID的變動偵聽器。

GM_setValue(name, value)

Set the value of 'name' to the storage.
設置指定變量的值

GM_getValue(name, defaultValue)

Get the value of 'name' from storage.
獲取指定變量的值

GM_log(message)

Log a message to the console.
寫日志到控制台

GM_getResourceText(name)

Get the content of a predefined @resource tag at the script header.
獲取腳本開頭預定義的@resource標簽的內容。

GM_getResourceURL(name)

Get the base64 encoded URI of a predefined @resource tag at the script header.
獲取腳本開頭處預定義的@resource標記的base64編碼URI。

GM_registerMenuCommand(name, fn, accessKey)

Register a menu to be displayed at the Tampermonkey menu at pages where this script runs and returns a menu command ID.
注冊一個菜單顯示在運行此腳本的頁面上的Tampermonkey菜單上,並返回菜單命令ID。

GM_unregisterMenuCommand(menuCmdId)

Unregister a menu command that was previously registered by GM_registerMenuCommand with the given menu command ID.
取消注冊上面注冊的菜單命令,通過上面得到的命令ID

GM_openInTab(url, options), GM_openInTab(url, loadInBackground)

Open a new tab with this url. The options object can have the following properties:
使用此url打開新選項卡。options對象可以具有以下屬性:

  • active decides whether the new tab should be focused, 決定是否聚焦新選項卡
  • insert that inserts the new tab after the current one, 在當前選項卡之后插入新選項卡
  • setParent makes the browser re-focus the current tab on close and 使瀏覽器重新聚焦當前選項卡
  • incognito makes the tab being opened inside a incognito mode/private mode window. 使選項卡在匿名模式/專用模式窗口中打開

Otherwise the new tab is just appended. loadInBackground has the opposite meaning of active and was added to achieve Greasemonkey 3.x compatibility. If neither active nor loadInBackground is given, then the tab will not be focused. This function returns an object with the function close, the listener onclose and a flag called closed.

否則,將只是打開新選項卡。loadInBackground與active的含義相反,添加它是為了實現Greasemonkey 3.x(見前,一種專為火狐瀏覽器編寫的腳本)兼容性。如果既不提供active也不提供loadInBackground,則選項卡將不會被聚焦。此函數返回一個對象,其中包含close函數、onclose偵聽器和一個名為closed的標志。

GM_xmlhttpRequest(details)

Make an xmlHttpRequest.
進行xmlHttp請求

Property of details:
details屬性的詳情

  • method one of GET, HEAD, POST 請求方法類型
  • url the destination URL 目的url
  • headers ie. user-agent, referer, ... (some special headers are not supported by Safari and Android browsers)
  • 頭部:例如,用戶代理、推薦人。。。(Safari和Android瀏覽器不支持某些特殊標題)
  • data some string to send via a POST request 通過POST請求發送的字符串
  • cookie a cookie to be patched into the sent cookie set 要補充到已發送cookie集中的cookie
  • binary send the data string in binary mode 以二進制模式發送數據字符串
  • nocache don't cache the resource 不緩存資源
  • revalidate revalidate maybe cached content 重新驗證緩存的內容
  • timeout a timeout in ms 超時時間(毫秒)
  • context a property which will be added to the response object 將添加到響應對象的屬性
  • responseType one of arraybuffer, blob, json 響應類型:arraybuffer、blob、json之一
  • overrideMimeType a MIME type for the request 重寫MIME類型:一種MIME類型for請求
  • anonymous don't send cookies with the requests (please see the fetch notes) 匿名的:不要隨請求一起發送cookie(請參閱獲取說明)
  • fetch (beta) use a fetch instead of a xhr request
    (at Chrome this causes xhr.abort, details.timeout and xhr.onprogress to not work and makes xhr.onreadystatechange receive only readyState 4 events)
  • 取回、提取:(beta版)使用fetch請求而不是xhr請求
    (對於Chrome瀏覽器,以下情況將導致xhr.中止, 詳細信息:超時、xhr.onprogress 不工作,並且使得 xhr.onreadystatechange 僅接收 readyState 4 事件)
  • username a username for authentication 用於身份驗證的用戶名
  • password a password 密碼
  • onabort callback to be executed if the request was aborted 請求中止時執行的回調
  • onerror callback to be executed if the request ended up with an error 請求錯誤時執行的回調
  • onloadstart callback to be executed if the request started to load 請求開始加載時執行的回調
  • onprogress callback to be executed if the request made some progress 請求取得了一些進度時執行的回調
  • onreadystatechange callback to be executed if the request's ready state changed 請求的就緒狀態改變時執行的回調
  • ontimeout callback to be executed if the request failed due to a timeout 請求超時導致失敗時執行的回調
  • onload callback to be executed if the request was loaded. 請求加載完成時執行的回調
    It gets one argument with the following attributes:
    通過以下屬性可以獲取對應參數
    • finalUrl - the final URL after all redirects from where the data was loaded
    • 最終Url:所有重定向之后,最終加載數據時的最終Url
    • readyState - the ready state 就緒狀態
    • status - the request status 請求狀態
    • statusText - the request status text 文本形式的就緒狀態
    • responseHeaders - the request response headers 請求的響應頭
    • response - the response data as object if details.responseType was set 如果details.responseType 被設置,則響應數據為對象類型
    • responseXML - the response data as XML document 響應數據為XML文檔
    • responseText - the response data as plain string 響應數據為純字符串

Returns an object with the following property:
xmlHttp請求返回具有以下屬性的對象:

  • abort - function to be called to cancel this request 取消請求

Note: the synchronous flag at details is not supported
注意:details 不支持 同步 標志

Important: if you want to use this method then please also check the documentation about @connect.
重要提示:如果您想使用此方法,請同時查看有關@connect的文檔。

GM_download(details), GM_download(url, name)

Downloads a given URL to the local disk.
將給定的URL下載到本地磁盤。

details can have the following attributes:
details 可以具有以下屬性:

  • url - the URL from where the data should be downloaded (required) 下載數據的URL(必需)
  • name - the filename - for security reasons the file extension needs to be whitelisted at Tampermonkey's options page (required)
  • 文件名-出於安全原因,文件擴展名需要在Tampermonkey的選項頁上列出(必需)
  • headers - see GM_xmlhttpRequest for more details 有關詳細信息,請參閱GM\u xmlhttpRequest
  • saveAs - boolean value, show a saveAs dialog 布爾值,顯示另存為對話框
  • onerror callback to be executed if this download ended up with an error 下載發生錯誤時的回調
  • onload callback to be executed if this download finished 下載完成時的回調
  • onprogress callback to be executed if this download made some progress 下載取得一些進度時的回調
  • ontimeout callback to be executed if this download failed due to a timeout 下載超時失敗時的回調

The download argument of the onerror callback can have the following attributes:
下載參數onerror 回調可以有以下屬性

  • error - error reason 錯誤原因
    • not_enabled - the download feature isn't enabled by the user
    • 用戶未啟用下載功能
    • not_whitelisted - the requested file extension is not whitelisted
    • 請求的文件擴展名未列入白名單
    • not_permitted - the user enabled the download feature, but did not give the downloads permission
    • 用戶啟用了下載功能,但未授予下載權限
    • not_supported - the download feature isn't supported by the browser/version
    • 瀏覽器/版本不支持下載功能
    • not_succeeded - the download wasn't started or failed, the details attribute may provide more information
    • 下載未啟動或失敗,details 屬性可以提供更多信息
  • details - detail about that error 錯誤詳情

Returns an object with the following property:
下載請求返回具有以下屬性的對象:

  • abort - function to be called to cancel this download 取消下載

Depending on the download mode GM_info provides a property called downloadMode which is set to one of the following values: native, disabled or browser.
根據下載模式,GM_info 提供一個名為 downloadMode 的屬性,該屬性為以下值之一:nativedisabledbrowser

GM_getTab(callback)

Get a object that is persistent as long as this tab is open.
獲取一個在選項卡打開期間能一直存在的(選項卡?)對象。

GM_saveTab(tab)

Save the tab object to reopen it after a page unload.
保存選項卡對象以在頁面卸載后重新打開它

GM_getTabs(callback)

Get all tab objects as a hash to communicate with other script instances.
將所有選項卡對象作為散列獲取,以便與其他腳本實例通信。

GM_notification(details, ondone), GM_notification(text, title, image, onclick)

Shows a HTML5 Desktop notification and/or highlight the current tab.
顯示HTML5桌面通知和/或突出顯示當前選項卡。

details can have the following attributes:
details 可以具有以下屬性:

  • text - the text of the notification (required unless highlight is set) 通知的文本(除非設置了highlight值,否則必須輸入)
  • title - the notificaton title 通知的標題
  • image - the image 圖片
  • highlight - a boolean flag whether to highlight the tab that sends the notfication (required unless text is set)
  • 一個布爾標志,是否突出顯示發送通知的選項卡(除非設置了text值,否則為必需)
  • silent - a boolean flag whether to not play a sound 是否播放聲音
  • timeout - the time after that the notification will be hidden (0 = disabled)
  • 多長時間后通知隱藏(0表示不隱藏)
  • ondone - called when the notification is closed (no matter if this was triggered by a timeout or a click) or the tab was highlighted
  • 當通知關閉(無論這是由超時或單擊觸發)或選項卡高亮顯示之后的調用
  • onclick - called in case the user clicks the notification 用戶點擊通知時的回調

All parameters do exactly the same like their corresponding details property pendant.
所有參數的作用與其對應的details屬性完全相同。

GM_setClipboard(data, info)

Copies data into the clipboard. The parameter info can be an object like "{ type: 'text', mimetype: 'text/plain'}" or just a string expressing the type ("text" or "html").
將數據復制到剪貼板。參數 info 可以是一個類似於“{type:'text',mimetype:'text/plain'}”的對象,也可以只是一個表示(一種)類型的字符串("text""html")。

GM_info

Get some info about the script and TM. The object might look like this:
獲取一些關於腳本和TM的信息。對象可能如下所示:

Code:

Object+  
---> script: Object+  
------> author: ""  
------>copyright: "2012+, You"  
------>description: "enter something useful"  
------>excludes: Array[0]  
------>homepage: null  
------>icon: null  
------>icon64: null  
------>includes: Array[2]  
------>lastUpdated: 1338465932430  
------>matches: Array[2]  
------>downloadMode: 'browser'  
------>name: "Local File Test"  
------>namespace: "http://your.homepage/"  
------>options: Object+  
--------->awareOfChrome: true  
--------->compat_arrayleft: false  
--------->compat_foreach: false  
--------->compat_forvarin: false  
--------->compat_metadata: false  
--------->compat_prototypes: false  
--------->compat_uW_gmonkey: false  
--------->noframes: false  
--------->override: Object+  
------------>excludes: false  
------------>includes: false  
------------>orig_excludes: Array[0]  
------------>orig_includes: Array[2]  
------------>use_excludes: Array[0]  
------------>use_includes: Array[0]  
--------->run_at: "document-end"  
------>position: 1  
------>resources: Array[0]  
------>run-at: "document-end"  
------>system: false  
------>unwrap: false  
------>version: "0.1"  
---> scriptMetaStr: undefined  
---> scriptSource: "// ==UserScript==\n// @name       Local File Test\n ...."  
---> scriptUpdateURL: undefined  
---> scriptWillUpdate: false  
---> scriptHandler: "Tampermonkey"  
---> isIncognito: false  
---> isFirstPartyIsolation: false  
---> version: "4.0.25"

<><![CDATA[your_text_here]]></>

Tampermonkey supports this way of storing meta data. TM tries to automatically detect whether a script needs this compatibility option to be enabled.
Tampermonkey支持這種存儲元數據的方式。TM嘗試自動檢測腳本是否需要啟用此兼容性選項。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM