1. Intro 中文简介
Quickly implement some tiny Intellij Idea scripts by Javascript
or Lua
to process text.
Sometimes we want to inject some tiny script to process text, e.g., Base64 encode or decode, AES or RSA encrypt etc. Or auto generate some text e.g., some random characters, code template. This Idea plugin help to do this.
In Idea Plugin Marketing page, search MonkeyKing and then click install.
Download zip from Release Page, and open Idea Plugin Manager page. Click Install Plugin from Disk..., choose the download zip.
- Click add button at setting page and choose a language
- Use browser. In the browser tab and click use button
- Header was wrapped by
start
andend
-- @start
-- @version 0.1
-- @namespace com.github.mounthuaguo.mk
-- @name Script Name
-- @type action or template
-- @menu Name in right click menu
-- @require https://raw.githubusercontent.com/rxi/json.lua/master/json.lua
-- @ Some other fields what you want。
-- @end
- Header fields
-
version
required. -
namespace
required. -
name
required. -
type
required, Only supportaction
andtemplate
by now.action
will display in right click menu,template
is predefined template to quick process text. -
menu
the name in right click menu. Only enable if type is action. -
require
only supportLua
, and not supportJavascript
. -
Other fields,
homepage
,link
,description
and what every you want to add.
- Predefined variant and methods
menu
the name displayed in right click menuaction
a sample wrap of AnActionEvent
-- in lua script
local selectedText = event.selectionModel.selectedText -- the selected text
local selectionStart = event.selectionModel.selectionStart -- the selection start
local selectionEnd = event.selectionModel.selectionEnd -- the selection end
local hasSelection = event.selectionModel.hasSelection --
local text = event.document.text -- the text of the document
local textLength = event.document.textLength -- document length
local lineCount = event.document.lineCount -- document line count
event.document.replaceString(startPosition, endPosition, replace) -- replace a string
event.document.insertString(endPosition, text) -- insert a string
-- in javascript
event.selectionModel().selectedText() -- the selected text
event.selectionModel().selectionStart() -- the selection start
event.selectionModel().selectionEnd() -- the selection end
event.selectionModel().hasSelection() --
event.document().text() -- the text of the document
event.document().textLength() -- document length
event.document().lineCount() -- document line count
event.document().replaceString(startPosition, endPosition, replace) -- replace a string
event.document().insertString(endPosition, text) -- insert a string
dialog
show a dialog
local result = dialog.show({
type = 'text', -- text field
field = '用户名', -- name to display
default = '10', -- default value, string type
}, {
type = 'radio', -- radio
field = '性别', -- name to display
default = '未知', -- default value, string type
options = { '男', '女', '未知' } -- options
}, {
type = 'checkbox', -- radio
field = '技能', -- name to display
default = { 'Lua', 'Java' }, -- default value, string array type
options = { 'Lua', 'Java', 'Golang' } -- options
}, {
type = 'dropdown', -- dropdown
field = '工作年限', -- name to display
default = '0-5年', -- default value, string type
options = { '0-5年', '5-10年', '10年以上' } -- options
})
if result.success then
-- result.success is true if user click OK button
print(result.data['用户名']) -- the text field value
print(result.data['性别']) -- the radio field value
print(result.data['技能']) -- the checkbox field value
print(result.data['工作年限']) -- the dropdown field value
end
toast
a wrap of notice
toast.info('show info message')
toast.error('show error message')
toast.warn('show warning message')
log
a wrap of tool window
log.info('output info message')
log.error('output error message')
log.warn('output warning message')
require
help to handle the requirement value.
-- @start
-- ...
-- @require https://raw.githubusercontent.com/rxi/json.lua/master/json.lua
-- ...
-- @end
require.a.decode('{}')
-- or
require['a'].decode('{}')
-- a is first require,b is the second,and so on.
clipboard
copy text to system clipboard or get text from system clipboard
-- copy to clipboard
clipboard.setContents('The text!')
-- get test form clipboard
local c = clipboard.getContents()
popup
dialog (only support javascript)
popup.builder().showBalloon('Hello Popup!')
popup.builder().show('<h1>Hello Popup!</h1>') // support sample HTML tags.
popup.builder().showSearchEverywhere(
// searchKey: The user input.
// loadMore: True when user click loadMore item.
//
// return: An array contains name,desc fields.
// If is last row and has more data. need set hasMore field.
function (searchKey, loadMore) {
return [{
name: 'options1',
desc: 'description1'
},{
name: 'options2',
desc: 'description2'
}]
},
// Will call when user click a row.
// index: the select index.
function (index) {
print('You select: ' + index)
})
- In right click menu
- In search panel
We can quickly implement a simple script in internet browser by Tampermonkey plugin. The inspiration for developing this plug-in came from it, so a similar name was given. MonkeyKing is also a character in Chinese mythology.
Currently, the plug-ins only support plug-ins written by Javascript
and Lua
. As for whether other languages will be
added, it has not yet been determined. If the demand is large, you can consider adding them.
All scripts are in MonkeyKingScripts, you can fork this repository and submit PR.