forked from hluk/copyq-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import-commands-after-copied.ini
60 lines (53 loc) · 1.91 KB
/
import-commands-after-copied.ini
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
[Command]
Automatic=true
Command="
copyq:
// Imports raw commands code (starting with [Command] or [Commands])
// or from a link ('https://github.com/**/copyq-commands/blob/**.ini').
var timeOutSeconds = 10
var rawDataUrlPrefix = 'https://raw.githubusercontent.com'
// Don't run this when mouse selection changes.
if ( dataFormats().indexOf(mimeClipboardMode) != -1 )
abort()
function importCommandsFromUrl(url)
{
var m = url.match(/^https?:\\/\\/github\\.com(\\/.*)\\/blob(\\/.*\\.ini)/)
if (!m)
return;
var rawDataUrl = rawDataUrlPrefix + m[1] + m[2]
var reply = networkGet(rawDataUrl)
var commandsData = str(reply.data)
if (reply.status != 200) {
throw 'Failed to fetch commands.'
+ '\\nStatus code: ' + reply.status
+ '\\nError: ' + reply.error
}
if ( !commandsData.match(/^\\[Commands?\\]/) )
return;
return importCommands(commandsData);
}
var cmds = importCommandsFromUrl(str(input())) || importCommands(input())
var list = '<ul>'
for (var i in cmds) {
var cmd = cmds[i]
var cmdType =
cmd.automatic ? 'automatic' :
cmd.inMenu ? 'menu/shortcut' :
cmd.globalShortcuts ? 'global shortcut' : '<b>???</b>';
list += '<li>' + escapeHtml(cmds[i].name) + ' (' + cmdType + ')</li>'
}
list += '</ul>'
var message = '<p><b>Import commands</b> from clipboard?</p>' + list
notification(
'.title', 'Commands Available',
'.message', message,
'.time', timeOutSeconds*1000,
'.icon', '\xf085',
'.id', 'CopyQ_commands_in_clipboard',
'.button', 'Cancel', '', '',
'.button', 'Import', 'copyq: addCommands( importCommands(input()) )', exportCommands(cmds)
)"
Icon=\xf085
Input=text/plain
Match=^\\[Commands?\\]|https?://github\\.com/.*/copyq-commands/blob/.*\\.ini
Name=Notification for Copied Commands