forked from litejs/json-lite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedit.js
39 lines (35 loc) · 1.01 KB
/
edit.js
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
pre.focus()
pre.textContent = pre.textContent
pre.className = "R" + rand
pre.addEventListener("paste", function(ev) {
setTimeout(function() {
formatBody({})
formatEdit()
}, 10)
})
function next() {
init(window, rand, opts)
st.appendChild(document.createTextNode("body," + css))
// listen events directly as in chrome
// background can not access to "chrome-extension:" uris
chrome.runtime.onMessage.addListener(function(msg, from) {
var prom = chrome.tabs.query({active: true, currentWindow: true}, onGot)
if (prom) prom.then(onGot)
function onGot(tabs) {
var prom = chrome.tabs.getCurrent(onGot)
if (prom) prom.then(onGot)
function onGot(cur) {
if (!tabs[0] || tabs[0].index != cur.index) return
if (window[msg.op]) window[msg.op](msg)
}
}
})
chrome.contextMenus.onClicked.addListener(function(info, tab) {
var prom = chrome.tabs.getCurrent(onGot)
if (prom) prom.then(onGot)
function onGot(cur) {
if (tab.index != cur.index) return
window.conv({op:info.menuItemId})
}
})
}