commit
938fe9f752
10 changed files with 788 additions and 32 deletions
@ -0,0 +1,123 @@ |
||||
const express = require('express'); |
||||
const lanthan = require('lanthan'); |
||||
const path = require('path'); |
||||
const assert = require('assert'); |
||||
const eventually = require('./eventually'); |
||||
const clipboard = require('./lib/clipboard'); |
||||
const settings = require('./settings'); |
||||
|
||||
const Key = lanthan.Key; |
||||
|
||||
const newApp = () => { |
||||
let app = express(); |
||||
app.get('/', (req, res) => { |
||||
res.status(200).send(`<html lang="en"></html">`); |
||||
}); |
||||
return app; |
||||
}; |
||||
|
||||
describe("navigate test", () => { |
||||
|
||||
const port = 12321; |
||||
let http; |
||||
let firefox; |
||||
let session; |
||||
let browser; |
||||
|
||||
before(async() => { |
||||
http = newApp().listen(port); |
||||
|
||||
firefox = await lanthan.firefox({ |
||||
spy: path.join(__dirname, '..'), |
||||
}); |
||||
session = firefox.session; |
||||
browser = firefox.browser; |
||||
|
||||
await browser.storage.local.set({ |
||||
settings, |
||||
}); |
||||
}); |
||||
|
||||
after(async() => { |
||||
if (firefox) { |
||||
await firefox.close(); |
||||
} |
||||
http.close(); |
||||
}); |
||||
|
||||
beforeEach(async() => { |
||||
let tabs = await browser.tabs.query({}); |
||||
for (let tab of tabs.slice(1)) { |
||||
await browser.tabs.remove(tab.id); |
||||
} |
||||
}) |
||||
|
||||
it('should copy current URL by y', async () => { |
||||
await session.navigateTo(`http://127.0.0.1:${port}/#should_copy_url`); |
||||
let body = await session.findElementByCSS('body'); |
||||
|
||||
await body.sendKeys('y'); |
||||
await eventually(async() => { |
||||
let data = await clipboard.read(); |
||||
assert.equal(data, `http://127.0.0.1:${port}/#should_copy_url`); |
||||
}); |
||||
}); |
||||
|
||||
it('should open an URL from clipboard by p', async () => { |
||||
await session.navigateTo(`http://127.0.0.1:${port}/`); |
||||
let body = await session.findElementByCSS('body'); |
||||
|
||||
await clipboard.write(`http://127.0.0.1:${port}/#open_from_clipboard`); |
||||
await body.sendKeys('p'); |
||||
|
||||
await eventually(async() => { |
||||
let tabs = await browser.tabs.query({ active: true }); |
||||
assert.equal(tabs[0].url, `http://127.0.0.1:${port}/#open_from_clipboard`); |
||||
}); |
||||
}); |
||||
|
||||
it('should open an URL from clipboard to new tab by P', async () => { |
||||
await session.navigateTo(`http://127.0.0.1:${port}/`); |
||||
let body = await session.findElementByCSS('body'); |
||||
|
||||
await clipboard.write(`http://127.0.0.1:${port}/#open_to_new_tab`); |
||||
await body.sendKeys(Key.Shift, 'p'); |
||||
|
||||
await eventually(async() => { |
||||
let tabs = await browser.tabs.query({}); |
||||
assert.deepEqual(tabs.map(t => t.url), [ |
||||
`http://127.0.0.1:${port}/`, |
||||
`http://127.0.0.1:${port}/#open_to_new_tab`, |
||||
]); |
||||
}); |
||||
}); |
||||
|
||||
it('should open search result with keywords in clipboard by p', async () => { |
||||
await session.navigateTo(`http://127.0.0.1:${port}/`); |
||||
let body = await session.findElementByCSS('body'); |
||||
|
||||
await clipboard.write(`an apple`); |
||||
await body.sendKeys('p'); |
||||
|
||||
await eventually(async() => { |
||||
let tabs = await browser.tabs.query({}); |
||||
assert.equal(tabs[0].url, `http://127.0.0.1:${port}/google?q=an%20apple`); |
||||
}); |
||||
}); |
||||
|
||||
it('should open search result with keywords in clipboard to new tabby P', async () => { |
||||
await session.navigateTo(`http://127.0.0.1:${port}/`); |
||||
let body = await session.findElementByCSS('body'); |
||||
|
||||
await clipboard.write(`an apple`); |
||||
await body.sendKeys(Key.Shift, 'p'); |
||||
|
||||
await eventually(async() => { |
||||
let tabs = await browser.tabs.query({}); |
||||
assert.deepEqual(tabs.map(t => t.url), [ |
||||
`http://127.0.0.1:${port}/`, |
||||
`http://127.0.0.1:${port}/google?q=an%20apple`, |
||||
]); |
||||
}); |
||||
}); |
||||
}); |
@ -0,0 +1,136 @@ |
||||
const express = require('express'); |
||||
const lanthan = require('lanthan'); |
||||
const path = require('path'); |
||||
const assert = require('assert'); |
||||
const eventually = require('./eventually'); |
||||
const settings = require('./settings'); |
||||
const Console = require('./lib/Console'); |
||||
|
||||
const Key = lanthan.Key; |
||||
|
||||
const newApp = () => { |
||||
let app = express(); |
||||
app.get('/', (req, res) => { |
||||
res.send(`<!DOCTYPEhtml>
|
||||
<html lang="en"> |
||||
<body>ok</body> |
||||
</html">`); |
||||
}); |
||||
return app; |
||||
}; |
||||
|
||||
describe("general completion test", () => { |
||||
const port = 12321; |
||||
let http; |
||||
let firefox; |
||||
let session; |
||||
let browser; |
||||
let body; |
||||
|
||||
before(async() => { |
||||
firefox = await lanthan.firefox({ |
||||
spy: path.join(__dirname, '..'), |
||||
builderf: (builder) => { |
||||
builder.addFile('build/settings.js'); |
||||
}, |
||||
}); |
||||
session = firefox.session; |
||||
browser = firefox.browser; |
||||
http = newApp().listen(port); |
||||
|
||||
await browser.storage.local.set({ |
||||
settings, |
||||
}); |
||||
}); |
||||
|
||||
after(async() => { |
||||
http.close(); |
||||
if (firefox) { |
||||
await firefox.close(); |
||||
} |
||||
}); |
||||
|
||||
beforeEach(async() => { |
||||
await session.navigateTo(`http://127.0.0.1:${port}`); |
||||
body = await session.findElementByCSS('body'); |
||||
}); |
||||
|
||||
it('should all commands on empty line', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
|
||||
await eventually(async() => { |
||||
let items = await c.getCompletions(); |
||||
assert.equal(items.length, 10); |
||||
assert.deepEqual(items[0], { type: 'title', text: 'Console Command' }); |
||||
assert(items[1].text.startsWith('set')) |
||||
assert(items[2].text.startsWith('open')) |
||||
assert(items[3].text.startsWith('tabopen')) |
||||
}); |
||||
}); |
||||
|
||||
it('should only commands filtered by prefix', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
await c.sendKeys('b'); |
||||
|
||||
await eventually(async() => { |
||||
let items = await c.getCompletions(); |
||||
assert.equal(items.length, 4); |
||||
assert.deepEqual(items[0], { type: 'title', text: 'Console Command' }); |
||||
assert(items[1].text.startsWith('buffer')) |
||||
assert(items[2].text.startsWith('bdelete')) |
||||
assert(items[3].text.startsWith('bdeletes')) |
||||
}); |
||||
}); |
||||
|
||||
it('selects completion items by <Tab>/<S-Tab> keys', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
await c.sendKeys('b'); |
||||
|
||||
await eventually(async() => { |
||||
let items = await c.getCompletions(); |
||||
assert.equal(items.length, 4); |
||||
}); |
||||
|
||||
await c.sendKeys(Key.Tab); |
||||
await eventually(async() => { |
||||
let items = await c.getCompletions(); |
||||
assert(items[1].highlight) |
||||
|
||||
let v = await c.currentValue(); |
||||
assert.equal(v, 'buffer'); |
||||
}); |
||||
|
||||
await c.sendKeys(Key.Tab, Key.Tab); |
||||
await eventually(async() => { |
||||
let items = await c.getCompletions(); |
||||
assert(items[3].highlight) |
||||
|
||||
let v = await c.currentValue(); |
||||
assert.equal(v, 'bdeletes'); |
||||
}); |
||||
|
||||
await c.sendKeys(Key.Tab); |
||||
await eventually(async() => { |
||||
let v = await c.currentValue(); |
||||
assert.equal(v, 'b'); |
||||
}); |
||||
|
||||
await c.sendKeys(Key.Shift, Key.Tab); |
||||
await eventually(async() => { |
||||
let items = await c.getCompletions(); |
||||
assert(items[3].highlight) |
||||
|
||||
let v = await c.currentValue(); |
||||
assert.equal(v, 'bdeletes'); |
||||
}); |
||||
}); |
||||
}); |
@ -0,0 +1,214 @@ |
||||
const express = require('express'); |
||||
const lanthan = require('lanthan'); |
||||
const path = require('path'); |
||||
const assert = require('assert'); |
||||
const eventually = require('./eventually'); |
||||
const settings = require('./settings'); |
||||
const Console = require('./lib/Console'); |
||||
|
||||
const Key = lanthan.Key; |
||||
|
||||
const newApp = () => { |
||||
|
||||
let app = express(); |
||||
app.get('/*', (req, res) => { |
||||
res.send(`<!DOCTYPEhtml>
|
||||
<html lang="en"> |
||||
<head> |
||||
<title>title_${req.path.slice(1)}</title> |
||||
</head> |
||||
<body><h1>home</h1></body> |
||||
</html">`); |
||||
}); |
||||
return app; |
||||
}; |
||||
|
||||
describe("completion on buffer/bdelete/bdeletes", () => { |
||||
const port = 12321; |
||||
let http; |
||||
let firefox; |
||||
let session; |
||||
let browser; |
||||
let body; |
||||
|
||||
before(async() => { |
||||
firefox = await lanthan.firefox({ |
||||
spy: path.join(__dirname, '..'), |
||||
builderf: (builder) => { |
||||
builder.addFile('build/settings.js'); |
||||
}, |
||||
}); |
||||
session = firefox.session; |
||||
browser = firefox.browser; |
||||
http = newApp().listen(port); |
||||
|
||||
await browser.storage.local.set({ |
||||
settings, |
||||
}); |
||||
}); |
||||
|
||||
after(async() => { |
||||
http.close(); |
||||
if (firefox) { |
||||
await firefox.close(); |
||||
} |
||||
}); |
||||
|
||||
beforeEach(async() => { |
||||
let tabs = await browser.tabs.query({}); |
||||
for (let tab of tabs.slice(1)) { |
||||
await browser.tabs.remove(tab.id); |
||||
} |
||||
|
||||
await browser.tabs.update(tabs[0].id, { url: `http://127.0.0.1:${port}/site1`, pinned: true }); |
||||
await browser.tabs.create({ url: `http://127.0.0.1:${port}/site2`, pinned: true }) |
||||
for (let i = 3; i <= 5; ++i) { |
||||
await browser.tabs.create({ url: `http://127.0.0.1:${port}/site${i}` }) |
||||
} |
||||
|
||||
await eventually(async() => { |
||||
let handles = await session.getWindowHandles(); |
||||
assert.equal(handles.length, 5); |
||||
await session.switchToWindow(handles[2]); |
||||
await session.findElementByCSS('iframe'); |
||||
}); |
||||
body = await session.findElementByCSS('body'); |
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100)); |
||||
}); |
||||
|
||||
it('should all tabs by "buffer" command with empty params', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
await c.sendKeys('buffer '); |
||||
|
||||
await eventually(async() => { |
||||
let items = await c.getCompletions(); |
||||
assert.equal(items.length, 6); |
||||
assert.deepEqual(items[0], { type: 'title', text: 'Buffers' }); |
||||
assert(items[1].text.startsWith('1:')); |
||||
assert(items[2].text.startsWith('2:')); |
||||
assert(items[3].text.startsWith('3:')); |
||||
assert(items[4].text.startsWith('4:')); |
||||
assert(items[5].text.startsWith('5:')); |
||||
|
||||
assert(items[3].text.includes('%')); |
||||
assert(items[5].text.includes('#')); |
||||
}); |
||||
}) |
||||
|
||||
it('should filter items with URLs by keywords on "buffer" command', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
await c.sendKeys('buffer title_site2'); |
||||
|
||||
await eventually(async() => { |
||||
let items = await c.getCompletions(); |
||||
assert.deepEqual(items[0], { type: 'title', text: 'Buffers' }); |
||||
assert(items[1].text.startsWith('2:')); |
||||
assert(items[1].text.includes('title_site2')); |
||||
assert(items[1].text.includes(`http://127.0.0.1:${port}/site2`)); |
||||
}); |
||||
}) |
||||
|
||||
it('should filter items with titles by keywords on "buffer" command', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
await c.sendKeys('buffer /site2'); |
||||
|
||||
await eventually(async() => { |
||||
let items = await c.getCompletions(); |
||||
assert.deepEqual(items[0], { type: 'title', text: 'Buffers' }); |
||||
assert(items[1].text.startsWith('2:')); |
||||
}); |
||||
}) |
||||
|
||||
it('should show one item by number on "buffer" command', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
await c.sendKeys('buffer 2'); |
||||
|
||||
await eventually(async() => { |
||||
let items = await c.getCompletions(); |
||||
assert.equal(items.length, 2); |
||||
assert.deepEqual(items[0], { type: 'title', text: 'Buffers' }); |
||||
assert(items[1].text.startsWith('2:')); |
||||
}); |
||||
}) |
||||
|
||||
it('should show unpinned tabs "bdelete" command', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
await c.sendKeys('bdelete site'); |
||||
|
||||
await eventually(async() => { |
||||
let items = await c.getCompletions(); |
||||
assert.equal(items.length, 4); |
||||
assert(items[1].text.includes('site3')); |
||||
assert(items[2].text.includes('site4')); |
||||
assert(items[3].text.includes('site5')); |
||||
}); |
||||
}) |
||||
|
||||
it('should show unpinned tabs "bdeletes" command', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
await c.sendKeys('bdelete site'); |
||||
|
||||
await eventually(async() => { |
||||
let items = await c.getCompletions(); |
||||
assert.equal(items.length, 4); |
||||
assert(items[1].text.includes('site3')); |
||||
assert(items[2].text.includes('site4')); |
||||
assert(items[3].text.includes('site5')); |
||||
}); |
||||
}) |
||||
|
||||
it('should show both pinned and unpinned tabs "bdelete!" command', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
await c.sendKeys('bdelete! site'); |
||||
|
||||
await eventually(async() => { |
||||
let items = await c.getCompletions(); |
||||
assert.equal(items.length, 6); |
||||
assert(items[1].text.includes('site1')); |
||||
assert(items[2].text.includes('site2')); |
||||
assert(items[3].text.includes('site3')); |
||||
assert(items[4].text.includes('site4')); |
||||
assert(items[5].text.includes('site5')); |
||||
}); |
||||
}) |
||||
|
||||
it('should show both pinned and unpinned tabs "bdeletes!" command', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
await c.sendKeys('bdeletes! site'); |
||||
|
||||
await eventually(async() => { |
||||
let items = await c.getCompletions(); |
||||
assert.equal(items.length, 6); |
||||
assert(items[1].text.includes('site1')); |
||||
assert(items[2].text.includes('site2')); |
||||
assert(items[3].text.includes('site3')); |
||||
assert(items[4].text.includes('site4')); |
||||
assert(items[5].text.includes('site5')); |
||||
}); |
||||
}) |
||||
}); |
@ -0,0 +1,132 @@ |
||||
const express = require('express'); |
||||
const lanthan = require('lanthan'); |
||||
const path = require('path'); |
||||
const assert = require('assert'); |
||||
const eventually = require('./eventually'); |
||||
const settings = require('./settings'); |
||||
const Console = require('./lib/Console'); |
||||
|
||||
const Key = lanthan.Key; |
||||
|
||||
const newApp = () => { |
||||
|
||||
let app = express(); |
||||
app.get('/', (req, res) => { |
||||
res.send(`<!DOCTYPEhtml>
|
||||
<html lang="en"> |
||||
<body>ok</body> |
||||
</html">`); |
||||
}); |
||||
return app; |
||||
}; |
||||
|
||||
describe("completion on open/tabopen/winopen commands", () => { |
||||
const port = 12321; |
||||
let http; |
||||
let firefox; |
||||
let session; |
||||
let browser; |
||||
let body; |
||||
|
||||
before(async() => { |
||||
firefox = await lanthan.firefox({ |
||||
spy: path.join(__dirname, '..'), |
||||
builderf: (builder) => { |
||||
builder.addFile('build/settings.js'); |
||||
}, |
||||
}); |
||||
session = firefox.session; |
||||
browser = firefox.browser; |
||||
http = newApp().listen(port); |
||||
|
||||
await browser.storage.local.set({ |
||||
settings, |
||||
}); |
||||
|
||||
// Add item into hitories
|
||||
await session.navigateTo(`https://i-beam.org`); |
||||
}); |
||||
|
||||
after(async() => { |
||||
http.close(); |
||||
if (firefox) { |
||||
await firefox.close(); |
||||
} |
||||
}); |
||||
|
||||
beforeEach(async() => { |
||||
await session.navigateTo(`http://127.0.0.1:${port}`); |
||||
body = await session.findElementByCSS('body'); |
||||
}); |
||||
|
||||
it('should show completions from search engines, bookmarks, and histories by "open" command', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
await c.sendKeys('open '); |
||||
|
||||
await eventually(async() => { |
||||
let completions = await c.getCompletions(); |
||||
assert(completions.find(x => x.type === 'title' && x.text === 'Search Engines')); |
||||
assert(completions.find(x => x.type === 'title' && x.text === 'Bookmarks')); |
||||
assert(completions.find(x => x.type === 'title' && x.text === 'History')); |
||||
}); |
||||
}); |
||||
|
||||
it('should filter items with URLs by keywords on "open" command', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
await c.sendKeys('open https://'); |
||||
|
||||
await eventually(async() => { |
||||
let completions = await c.getCompletions(); |
||||
let items = completions.filter(x => x.type === 'item').map(x => x.text); |
||||
assert(items.every(x => x.includes('https://'))); |
||||
}); |
||||
}) |
||||
|
||||
it('should filter items with titles by keywords on "open" command', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
await c.sendKeys('open getting'); |
||||
|
||||
await eventually(async() => { |
||||
let completions = await c.getCompletions(); |
||||
let items = completions.filter(x => x.type === 'item').map(x => x.text); |
||||
assert(items.every(x => x.toLowerCase().includes('getting'))); |
||||
}); |
||||
}) |
||||
|
||||
it('should filter items with titles by keywords on "tabopen" command', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
await c.sendKeys('tabopen https://'); |
||||
|
||||
await eventually(async() => { |
||||
let completions = await c.getCompletions(); |
||||
let items = completions.filter(x => x.type === 'item').map(x => x.text); |
||||
assert(items.every(x => x.includes('https://'))); |
||||
}); |
||||
}) |
||||
|
||||
it('should filter items with titles by keywords on "winopen" command', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
await c.sendKeys('winopen https://'); |
||||
|
||||
await eventually(async() => { |
||||
let completions = await c.getCompletions(); |
||||
let items = completions.filter(x => x.type === 'item').map(x => x.text); |
||||
assert(items.every(x => x.includes('https://'))); |
||||
}); |
||||
}) |
||||
}); |
@ -0,0 +1,75 @@ |
||||
const express = require('express'); |
||||
const lanthan = require('lanthan'); |
||||
const path = require('path'); |
||||
const assert = require('assert'); |
||||
const eventually = require('./eventually'); |
||||
const settings = require('./settings'); |
||||
const Console = require('./lib/Console'); |
||||
|
||||
const Key = lanthan.Key; |
||||
|
||||
describe("completion on set commands", () => { |
||||
const port = 12321; |
||||
let firefox; |
||||
let session; |
||||
let browser; |
||||
let body; |
||||
|
||||
before(async() => { |
||||
firefox = await lanthan.firefox({ |
||||
spy: path.join(__dirname, '..'), |
||||
builderf: (builder) => { |
||||
builder.addFile('build/settings.js'); |
||||
}, |
||||
}); |
||||
session = firefox.session; |
||||
browser = firefox.browser; |
||||
|
||||
await browser.storage.local.set({ |
||||
settings, |
||||
}); |
||||
}); |
||||
|
||||
after(async() => { |
||||
if (firefox) { |
||||
await firefox.close(); |
||||
} |
||||
}); |
||||
|
||||
beforeEach(async() => { |
||||
await session.navigateTo(`about:blank`); |
||||
body = await session.findElementByCSS('body'); |
||||
}); |
||||
|
||||
it('should show all property names by "set" command with empty params', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
await c.sendKeys('set '); |
||||
|
||||
await eventually(async() => { |
||||
let items = await c.getCompletions(); |
||||
assert.equal(items.length, 5); |
||||
assert.deepEqual(items[0], { type: 'title', text: 'Properties' }); |
||||
assert(items[1].text.startsWith('hintchars')) |
||||
assert(items[2].text.startsWith('smoothscroll')) |
||||
assert(items[3].text.startsWith('nosmoothscroll')) |
||||
assert(items[4].text.startsWith('complete')) |
||||
}); |
||||
}); |
||||
|
||||
it('should show filtered property names by "set" command', async() => { |
||||
await body.sendKeys(':'); |
||||
|
||||
await session.switchToFrame(0); |
||||
let c = new Console(session); |
||||
await c.sendKeys('set no'); |
||||
|
||||
await eventually(async() => { |
||||
let items = await c.getCompletions(); |
||||
assert.equal(items.length, 2); |
||||
assert(items[1].text.includes('nosmoothscroll')) |
||||
}); |
||||
}); |
||||
}); |
@ -0,0 +1,41 @@ |
||||
class Console { |
||||
constructor(session) { |
||||
this.session = session; |
||||
} |
||||
|
||||
async sendKeys(...keys) { |
||||
let input = await this.session.findElementByCSS('input'); |
||||
input.sendKeys(...keys); |
||||
} |
||||
|
||||
async currentValue() { |
||||
return await this.session.executeScript(() => { |
||||
let input = document.querySelector('input'); |
||||
return input.value; |
||||
}); |
||||
} |
||||
|
||||
async getCompletions() { |
||||
return await this.session.executeScript(() => { |
||||
let items = document.querySelectorAll('.vimvixen-console-completion > li'); |
||||
if (items.length === 0) { |
||||
throw new Error('completion items not found'); |
||||
} |
||||
|
||||
let objs = []; |
||||
for (let li of items) { |
||||
if (li.classList.contains('vimvixen-console-completion-title')) { |
||||
objs.push({ type: 'title', text: li.textContent.trim() }); |
||||
} else if ('vimvixen-console-completion-item') { |
||||
let highlight = li.classList.contains('vimvixen-completion-selected'); |
||||
objs.push({ type: 'item', text: li.textContent.trim(), highlight }); |
||||
} else { |
||||
throw new Error(`unexpected class: ${li.className}`); |
||||
} |
||||
} |
||||
return objs; |
||||
}); |
||||
} |
||||
} |
||||
|
||||
module.exports = Console; |
@ -0,0 +1,63 @@ |
||||
'use strict'; |
||||
|
||||
const { spawn } = require('child_process'); |
||||
|
||||
const readLinux = () => { |
||||
let stdout = '', stderr = ''; |
||||
return new Promise((resolve, reject) => { |
||||
let xsel = spawn('xsel', ['--clipboard', '--output']); |
||||
xsel.stdout.on('data', (data) => { |
||||
stdout += data; |
||||
}); |
||||
xsel.stderr.on('data', (data) => { |
||||
stderr += data; |
||||
}); |
||||
xsel.on('close', (code) => { |
||||
if (code !== 0) { |
||||
throw new Error(`xsel returns ${code}: ${stderr}`) |
||||
} |
||||
resolve(stdout); |
||||
}); |
||||
}); |
||||
}; |
||||
|
||||
const writeLinux = (data) => { |
||||
let stdout = '', stderr = ''; |
||||
return new Promise((resolve, reject) => { |
||||
let xsel = spawn('xsel', ['--clipboard', '--input']); |
||||
xsel.stderr.on('data', (data) => { |
||||
stderr += data; |
||||
}); |
||||
xsel.on('close', (code) => { |
||||
if (code !== 0) { |
||||
throw new Error(`xsel returns ${code}: ${stderr}`) |
||||
} |
||||
resolve(); |
||||
}); |
||||
xsel.stdin.write(data); |
||||
xsel.stdin.end(); |
||||
}); |
||||
}; |
||||
|
||||
const unsupported = (os) => { |
||||
return () => { |
||||
throw new Error(`Unsupported os: ${os}`); |
||||
}; |
||||
}; |
||||
|
||||
const detect = () => { |
||||
switch (process.platform) { |
||||
case 'linux': |
||||
return { |
||||
read: readLinux, |
||||
write: writeLinux, |
||||
}; |
||||
default: |
||||
return { |
||||
read: unsupported(process.platform), |
||||
write: unsupported(process.platform), |
||||
}; |
||||
} |
||||
} |
||||
|
||||
module.exports = detect(); |
Reference in new issue