aboutsummaryrefslogtreecommitdiff
path: root/src/background/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/background/shared')
-rw-r--r--src/background/shared/bookmarks.js9
-rw-r--r--src/background/shared/completions/bookmarks.js14
-rw-r--r--src/background/shared/completions/histories.js82
-rw-r--r--src/background/shared/completions/index.js173
-rw-r--r--src/background/shared/completions/tabs.js8
-rw-r--r--src/background/shared/indicators.js13
-rw-r--r--src/background/shared/tabs.js158
-rw-r--r--src/background/shared/versions/index.js38
-rw-r--r--src/background/shared/versions/release-notes.js8
-rw-r--r--src/background/shared/versions/storage.js10
-rw-r--r--src/background/shared/zooms.js32
11 files changed, 0 insertions, 545 deletions
diff --git a/src/background/shared/bookmarks.js b/src/background/shared/bookmarks.js
deleted file mode 100644
index 5e7927b..0000000
--- a/src/background/shared/bookmarks.js
+++ /dev/null
@@ -1,9 +0,0 @@
-const create = (title, url) => {
- return browser.bookmarks.create({
- type: 'bookmark',
- title,
- url,
- });
-};
-
-export { create };
diff --git a/src/background/shared/completions/bookmarks.js b/src/background/shared/completions/bookmarks.js
deleted file mode 100644
index bd753af..0000000
--- a/src/background/shared/completions/bookmarks.js
+++ /dev/null
@@ -1,14 +0,0 @@
-const getCompletions = async(keywords) => {
- let items = await browser.bookmarks.search({ query: keywords });
- return items.filter((item) => {
- let url = undefined;
- try {
- url = new URL(item.url);
- } catch (e) {
- return false;
- }
- return item.type === 'bookmark' && url.protocol !== 'place:';
- }).slice(0, 10);
-};
-
-export { getCompletions };
diff --git a/src/background/shared/completions/histories.js b/src/background/shared/completions/histories.js
deleted file mode 100644
index 2d35401..0000000
--- a/src/background/shared/completions/histories.js
+++ /dev/null
@@ -1,82 +0,0 @@
-const filterHttp = (items) => {
- const httpsHosts = items
- .filter(item => item[1].protocol === 'https:')
- .map(item => item[1].host);
- const httpsHostSet = new Set(httpsHosts);
- return items.filter(
- item => !(item[1].protocol === 'http:' && httpsHostSet.has(item[1].host))
- );
-};
-
-const filterEmptyTitle = (items) => {
- return items.filter(item => item[0].title && item[0].title !== '');
-};
-
-const filterClosedPath = (items) => {
- const allSimplePaths = items
- .filter(item => item[1].hash === '' && item[1].search === '')
- .map(item => item[1].origin + item[1].pathname);
- const allSimplePathSet = new Set(allSimplePaths);
- return items.filter(
- item => !(item[1].hash === '' && item[1].search === '' &&
- (/\/$/).test(item[1].pathname) &&
- allSimplePathSet.has(
- (item[1].origin + item[1].pathname).replace(/\/$/, '')
- )
- )
- );
-};
-
-const reduceByPathname = (items, min) => {
- let hash = {};
- for (let item of items) {
- let pathname = item[1].origin + item[1].pathname;
- if (!hash[pathname]) {
- hash[pathname] = item;
- } else if (hash[pathname][1].href.length > item[1].href.length) {
- hash[pathname] = item;
- }
- }
- let filtered = Object.values(hash);
- if (filtered.length < min) {
- return items;
- }
- return filtered;
-};
-
-const reduceByOrigin = (items, min) => {
- let hash = {};
- for (let item of items) {
- let origin = item[1].origin;
- if (!hash[origin]) {
- hash[origin] = item;
- } else if (hash[origin][1].href.length > item[1].href.length) {
- hash[origin] = item;
- }
- }
- let filtered = Object.values(hash);
- if (filtered.length < min) {
- return items;
- }
- return filtered;
-};
-
-const getCompletions = async(keyword) => {
- let historyItems = await browser.history.search({
- text: keyword,
- startTime: 0,
- });
- return [historyItems.map(item => [item, new URL(item.url)])]
- .map(filterEmptyTitle)
- .map(filterHttp)
- .map(filterClosedPath)
- .map(items => reduceByPathname(items, 10))
- .map(items => reduceByOrigin(items, 10))
- .map(items => items
- .sort((x, y) => x[0].visitCount < y[0].visitCount)
- .slice(0, 10)
- .map(item => item[0])
- )[0];
-};
-
-export { getCompletions };
diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js
deleted file mode 100644
index 9ca13f7..0000000
--- a/src/background/shared/completions/index.js
+++ /dev/null
@@ -1,173 +0,0 @@
-import commandDocs from 'shared/commands/docs';
-import * as tabs from './tabs';
-import * as histories from './histories';
-import * as bookmarks from './bookmarks';
-import * as properties from 'shared/settings/properties';
-
-const completeCommands = (typing) => {
- let keys = Object.keys(commandDocs);
- return keys
- .filter(name => name.startsWith(typing))
- .map(name => ({
- caption: name,
- content: name,
- url: commandDocs[name],
- }));
-};
-
-const getSearchCompletions = (command, keywords, searchConfig) => {
- let engineNames = Object.keys(searchConfig.engines);
- let engineItems = engineNames.filter(name => name.startsWith(keywords))
- .map(name => ({
- caption: name,
- content: command + ' ' + name
- }));
- return Promise.resolve(engineItems);
-};
-
-const getHistoryCompletions = async(command, keywords) => {
- let items = await histories.getCompletions(keywords);
- return items.map((page) => {
- return {
- caption: page.title,
- content: command + ' ' + page.url,
- url: page.url
- };
- });
-};
-
-const getBookmarksCompletions = async(command, keywords) => {
- let items = await bookmarks.getCompletions(keywords);
- return items.map(item => ({
- caption: item.title,
- content: command + ' ' + item.url,
- url: item.url,
- }));
-};
-
-const getOpenCompletions = async(command, keywords, searchConfig) => {
- let engineItems = await getSearchCompletions(command, keywords, searchConfig);
- let historyItems = await getHistoryCompletions(command, keywords);
- let bookmarkItems = await getBookmarksCompletions(command, keywords);
- let completions = [];
- if (engineItems.length > 0) {
- completions.push({
- name: 'Search Engines',
- items: engineItems
- });
- }
- if (historyItems.length > 0) {
- completions.push({
- name: 'History',
- items: historyItems
- });
- }
- if (bookmarkItems.length > 0) {
- completions.push({
- name: 'Bookmarks',
- items: bookmarkItems
- });
- }
- return completions;
-};
-
-const getBufferCompletions = async(command, keywords, excludePinned) => {
- let items = await tabs.getCompletions(keywords, excludePinned);
- items = items.map(tab => ({
- caption: tab.title,
- content: command + ' ' + tab.title,
- url: tab.url,
- icon: tab.favIconUrl
- }));
- return [
- {
- name: 'Buffers',
- items: items
- }
- ];
-};
-
-const getSetCompletions = (command, keywords) => {
- let keys = Object.keys(properties.docs).filter(
- name => name.startsWith(keywords)
- );
- let items = keys.map((key) => {
- if (properties.types[key] === 'boolean') {
- return [
- {
- caption: key,
- content: command + ' ' + key,
- url: 'Enable ' + properties.docs[key],
- }, {
- caption: 'no' + key,
- content: command + ' no' + key,
- url: 'Disable ' + properties.docs[key],
- }
- ];
- }
- return [
- {
- caption: key,
- content: command + ' ' + key,
- url: 'Set ' + properties.docs[key],
- }
- ];
- });
- items = items.reduce((acc, val) => acc.concat(val), []);
- if (items.length === 0) {
- return Promise.resolve([]);
- }
- return Promise.resolve([
- {
- name: 'Properties',
- items,
- }
- ]);
-};
-
-const complete = (line, settings) => {
- let trimmed = line.trimStart();
- let words = trimmed.split(/ +/);
- let name = words[0];
- if (words.length === 1) {
- let items = completeCommands(name);
- if (items.length === 0) {
- return Promise.resolve([]);
- }
- return Promise.resolve([
- {
- name: 'Console Command',
- items: completeCommands(name),
- }
- ]);
- }
- let keywords = trimmed.slice(name.length).trimStart();
-
- switch (words[0]) {
- case 'o':
- case 'open':
- case 't':
- case 'tabopen':
- case 'w':
- case 'winopen':
- return getOpenCompletions(name, keywords, settings.search);
- case 'b':
- case 'buffer':
- return getBufferCompletions(name, keywords, false);
- case 'bd!':
- case 'bdel!':
- case 'bdelete!':
- case 'bdeletes!':
- return getBufferCompletions(name, keywords, false);
- case 'bd':
- case 'bdel':
- case 'bdelete':
- case 'bdeletes':
- return getBufferCompletions(name, keywords, true);
- case 'set':
- return getSetCompletions(name, keywords);
- }
- return Promise.resolve([]);
-};
-
-export { complete };
diff --git a/src/background/shared/completions/tabs.js b/src/background/shared/completions/tabs.js
deleted file mode 100644
index bdb2741..0000000
--- a/src/background/shared/completions/tabs.js
+++ /dev/null
@@ -1,8 +0,0 @@
-import * as tabs from '../tabs';
-
-const getCompletions = (keyword, excludePinned) => {
- return tabs.queryByKeyword(keyword, excludePinned);
-};
-
-
-export { getCompletions };
diff --git a/src/background/shared/indicators.js b/src/background/shared/indicators.js
deleted file mode 100644
index 74002c4..0000000
--- a/src/background/shared/indicators.js
+++ /dev/null
@@ -1,13 +0,0 @@
-const enable = () => {
- return browser.browserAction.setIcon({
- path: 'resources/enabled_32x32.png',
- });
-};
-
-const disable = () => {
- return browser.browserAction.setIcon({
- path: 'resources/disabled_32x32.png',
- });
-};
-
-export { enable, disable };
diff --git a/src/background/shared/tabs.js b/src/background/shared/tabs.js
deleted file mode 100644
index 26e2e44..0000000
--- a/src/background/shared/tabs.js
+++ /dev/null
@@ -1,158 +0,0 @@
-import * as tabCompletions from './completions/tabs';
-
-const closeTab = async(id) => {
- let tab = await browser.tabs.get(id);
- if (!tab.pinned) {
- return browser.tabs.remove(id);
- }
-};
-
-const closeTabForce = (id) => {
- return browser.tabs.remove(id);
-};
-
-const queryByKeyword = async(keyword, excludePinned = false) => {
- let tabs = await browser.tabs.query({ currentWindow: true });
- return tabs.filter((t) => {
- return t.url.toLowerCase().includes(keyword.toLowerCase()) ||
- t.title && t.title.toLowerCase().includes(keyword.toLowerCase());
- }).filter((t) => {
- return !(excludePinned && t.pinned);
- });
-};
-
-const closeTabByKeywords = async(keyword) => {
- let tabs = await queryByKeyword(keyword, true);
- if (tabs.length === 0) {
- throw new Error('No matching buffer for ' + keyword);
- } else if (tabs.length > 1) {
- throw new Error('More than one match for ' + keyword);
- }
- return browser.tabs.remove(tabs[0].id);
-};
-
-const closeTabByKeywordsForce = async(keyword) => {
- let tabs = await queryByKeyword(keyword, false);
- if (tabs.length === 0) {
- throw new Error('No matching buffer for ' + keyword);
- } else if (tabs.length > 1) {
- throw new Error('More than one match for ' + keyword);
- }
- return browser.tabs.remove(tabs[0].id);
-};
-
-const closeTabsByKeywords = async(keyword) => {
- let tabs = await tabCompletions.getCompletions(keyword);
- tabs = tabs.filter(tab => !tab.pinned);
- return browser.tabs.remove(tabs.map(tab => tab.id));
-};
-
-const closeTabsByKeywordsForce = async(keyword) => {
- let tabs = await tabCompletions.getCompletions(keyword);
- return browser.tabs.remove(tabs.map(tab => tab.id));
-};
-
-const reopenTab = async() => {
- let window = await browser.windows.getCurrent();
- let sessions = await browser.sessions.getRecentlyClosed();
- let session = sessions.find((s) => {
- return s.tab && s.tab.windowId === window.id;
- });
- if (!session) {
- return;
- }
- if (session.tab) {
- return browser.sessions.restore(session.tab.sessionId);
- }
- return browser.sessions.restore(session.window.sessionId);
-};
-
-const selectAt = async(index) => {
- let tabs = await browser.tabs.query({ currentWindow: true });
- if (tabs.length < 2) {
- return;
- }
- if (index < 0 || tabs.length <= index) {
- throw new RangeError(`tab ${index + 1} does not exist`);
- }
- let id = tabs[index].id;
- return browser.tabs.update(id, { active: true });
-};
-
-const selectByKeyword = async(current, keyword) => {
- let tabs = await queryByKeyword(keyword);
- if (tabs.length === 0) {
- throw new RangeError('No matching buffer for ' + keyword);
- }
- for (let tab of tabs) {
- if (tab.index > current.index) {
- return browser.tabs.update(tab.id, { active: true });
- }
- }
- return browser.tabs.update(tabs[0].id, { active: true });
-};
-
-const selectPrevTab = async(current, count) => {
- let tabs = await browser.tabs.query({ currentWindow: true });
- if (tabs.length < 2) {
- return;
- }
- let select = (current - count + tabs.length) % tabs.length;
- let id = tabs[select].id;
- return browser.tabs.update(id, { active: true });
-};
-
-const selectNextTab = async(current, count) => {
- let tabs = await browser.tabs.query({ currentWindow: true });
- if (tabs.length < 2) {
- return;
- }
- let select = (current + count) % tabs.length;
- let id = tabs[select].id;
- return browser.tabs.update(id, { active: true });
-};
-
-const selectFirstTab = async() => {
- let tabs = await browser.tabs.query({ currentWindow: true });
- let id = tabs[0].id;
- return browser.tabs.update(id, { active: true });
-};
-
-const selectLastTab = async() => {
- let tabs = await browser.tabs.query({ currentWindow: true });
- let id = tabs[tabs.length - 1].id;
- return browser.tabs.update(id, { active: true });
-};
-
-const selectTab = (id) => {
- return browser.tabs.update(id, { active: true });
-};
-
-const reload = (current, cache) => {
- return browser.tabs.reload(
- current.id,
- { bypassCache: cache }
- );
-};
-
-const updateTabPinned = (current, pinned) => {
- return browser.tabs.update(current.id, { pinned });
-};
-
-const toggleTabPinned = (current) => {
- return updateTabPinned(current, !current.pinned);
-};
-
-const duplicate = (id) => {
- return browser.tabs.duplicate(id);
-};
-
-export {
- closeTab, closeTabForce,
- queryByKeyword, closeTabByKeywords, closeTabByKeywordsForce,
- closeTabsByKeywords, closeTabsByKeywordsForce,
- reopenTab, selectAt, selectByKeyword,
- selectPrevTab, selectNextTab, selectFirstTab,
- selectLastTab, selectTab, reload, updateTabPinned,
- toggleTabPinned, duplicate
-};
diff --git a/src/background/shared/versions/index.js b/src/background/shared/versions/index.js
deleted file mode 100644
index aa09c92..0000000
--- a/src/background/shared/versions/index.js
+++ /dev/null
@@ -1,38 +0,0 @@
-import * as storage from './storage';
-import * as releaseNotes from './release-notes';
-import manifest from '../../../../manifest.json';
-
-const NOTIFICATION_ID = 'vimvixen-update';
-
-const notificationClickListener = (id) => {
- if (id !== NOTIFICATION_ID) {
- return;
- }
-
- browser.tabs.create({ url: releaseNotes.url(manifest.version) });
- browser.notifications.onClicked.removeListener(notificationClickListener);
-};
-
-const checkUpdated = async() => {
- let prev = await storage.load();
- if (!prev) {
- return true;
- }
- return manifest.version !== prev;
-};
-
-const notify = () => {
- browser.notifications.onClicked.addListener(notificationClickListener);
- return browser.notifications.create(NOTIFICATION_ID, {
- 'type': 'basic',
- 'iconUrl': browser.extension.getURL('resources/icon_48x48.png'),
- 'title': 'Vim Vixen ' + manifest.version + ' has been installed',
- 'message': 'Click here to see release notes',
- });
-};
-
-const commit = () => {
- storage.save(manifest.version);
-};
-
-export { checkUpdated, notify, commit };
diff --git a/src/background/shared/versions/release-notes.js b/src/background/shared/versions/release-notes.js
deleted file mode 100644
index 6ef2335..0000000
--- a/src/background/shared/versions/release-notes.js
+++ /dev/null
@@ -1,8 +0,0 @@
-const url = (version) => {
- if (version) {
- return 'https://github.com/ueokande/vim-vixen/releases/tag/' + version;
- }
- return 'https://github.com/ueokande/vim-vixen/releases/';
-};
-
-export { url };
diff --git a/src/background/shared/versions/storage.js b/src/background/shared/versions/storage.js
deleted file mode 100644
index 7883258..0000000
--- a/src/background/shared/versions/storage.js
+++ /dev/null
@@ -1,10 +0,0 @@
-const load = async() => {
- let { version } = await browser.storage.local.get('version');
- return version;
-};
-
-const save = (version) => {
- return browser.storage.local.set({ version });
-};
-
-export { load, save };
diff --git a/src/background/shared/zooms.js b/src/background/shared/zooms.js
deleted file mode 100644
index 17b28fa..0000000
--- a/src/background/shared/zooms.js
+++ /dev/null
@@ -1,32 +0,0 @@
-// For chromium
-// const ZOOM_SETTINGS = [
-// 0.25, 0.33, 0.50, 0.66, 0.75, 0.80, 0.90, 1.00,
-// 1.10, 1.25, 1.50, 1.75, 2.00, 2.50, 3.00, 4.00, 5.00
-// ];
-
-const ZOOM_SETTINGS = [
- 0.33, 0.50, 0.66, 0.75, 0.80, 0.90, 1.00,
- 1.10, 1.25, 1.50, 1.75, 2.00, 2.50, 3.00
-];
-
-const zoomIn = async(tabId = undefined) => {
- let current = await browser.tabs.getZoom(tabId);
- let factor = ZOOM_SETTINGS.find(f => f > current);
- if (factor) {
- return browser.tabs.setZoom(tabId, factor);
- }
-};
-
-const zoomOut = async(tabId = undefined) => {
- let current = await browser.tabs.getZoom(tabId);
- let factor = [].concat(ZOOM_SETTINGS).reverse().find(f => f < current);
- if (factor) {
- return browser.tabs.setZoom(tabId, factor);
- }
-};
-
-const neutral = (tabId = undefined) => {
- return browser.tabs.setZoom(tabId, 1);
-};
-
-export { zoomIn, zoomOut, neutral };