-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
edit.js
38 lines (35 loc) · 1.19 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
function reFormat() {
setTimeout(function() {
document.body.textContent = document.body.textContent.trim()
func(rand, opts, "formatBody")
}, 10)
}
function next() {
reFormat()
document.body.focus()
document.body.addEventListener("cut", reFormat)
document.body.addEventListener("paste", reFormat)
editorStyle.appendChild(document.createTextNode('body>.r' + rand +':empty:after{display:"block";content:" Paste here";color:#bbb}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[rand][msg.op]) window[rand][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[rand].conv({op:info.menuItemId})
}
})
}