Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chrome-tool

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chrome-tool - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

browser-action.js

91

dechromeify.js

@@ -1,5 +0,5 @@

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
Object.defineProperty(exports, '__esModule', {
value: true
});

@@ -9,32 +9,67 @@ /**

*/
exports["default"] = dechromeify;
exports['default'] = dechromeify;
function dechromeify(myThis, fn) {
var opts = arguments[2] === undefined ? {} : arguments[2];
/**
* Dechromeify whole objects
*/
exports.dechromeifyAll = dechromeifyAll;
return function () {
for (var _len = arguments.length, myArgs = Array(_len), _key = 0; _key < _len; _key++) {
myArgs[_key] = arguments[_key];
}
function dechromeify(obj, key) {
return function dechromeified() {
var deferred = Promise.defer();
return new Promise(function (resolve, reject) {
// Callback for Chrome
myArgs.push(function (one) {
if (chrome.runtime.lastError) {
// Chrome API error
reject.call(this, chrome.runtime.lastError);
} else if (opts.responseErrors && one !== undefined && one.error !== undefined) {
// Call value error
reject.call(this, one.error);
} else {
resolve.apply(this, arguments);
}
});
// Add callback as last argument
Array.prototype.push.call(arguments, function callback() {
if (chrome.runtime.lastError) {
deferred.reject(chrome.runtime.lastError);
} else {
deferred.resolve(arguments[0]);
}
});
// Execute Chrome function
fn.apply(myThis, myArgs);
});
};
// Execute function
obj[key].apply(obj, arguments);
return deferred.promise;
};
}
module.exports = exports["default"];
function dechromeifyAll(obj, sync) {
var target = {};
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = Object.keys(obj)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var key = _step.value;
var prop = obj[key];
if (typeof prop === 'function') {
if (sync && sync.indexOf(key) !== -1) {
target[key] = prop.bind(obj);
} else {
target[key] = dechromeify(obj, key);
}
} else if (prop instanceof chrome.Event) {
target[key] = prop.addListener.bind(prop);
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator['return']) {
_iterator['return']();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return target;
}
{
"name": "chrome-tool",
"version": "1.0.1",
"version": "2.0.0",
"description": "Useful functions for creating Chrome apps and extensions",
"keywords": [ "chrome" ],
"keywords": [
"chrome"
],
"author": "Jannes Meyer <jannes.meyer@gmail.com>",

@@ -13,3 +15,6 @@ "license": "GPLv3",

},
"main": "chrome.js",
"main": "index.js",
"dependencies": {
"object.assign": "^1.1.1"
},
"devDependencies": {

@@ -16,0 +21,0 @@ "babel": "x",

'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
value: true
});
var _interopRequireDefault = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; };
var _interopRequireWildcard = function (obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } };

@@ -25,3 +25,3 @@ /**

*/
exports.show = show;
exports.open = open;

@@ -39,161 +39,243 @@ /**

/**
* Move tabs from a source to a target window.
* If targetWindowId is undefined, create new window.
* Create new window
*/
exports.moveToNewWindow = moveToNewWindow;
/**
* Move tabs to a target window
*/
exports.moveToWindow = moveToWindow;
var marked0$0 = [backwards].map(regeneratorRuntime.mark);
var _dechromeify = require('./dechromeify');
/**
* Close all tabs except the current tab
*/
exports.closeOthers = closeOthers;
var _dechromeify2 = _interopRequireDefault(_dechromeify);
var _dechromeifyAll2 = require('./dechromeify');
// TODO: automatically do the whole chrome.tabs
var create = _dechromeify2['default'](chrome.tabs, chrome.tabs.create);
var get = _dechromeify2['default'](chrome.tabs, chrome.tabs.get);
var getCurrent = _dechromeify2['default'](chrome.tabs, chrome.tabs.getCurrent);
var move = _dechromeify2['default'](chrome.tabs, chrome.tabs.move);
var query = _dechromeify2['default'](chrome.tabs, chrome.tabs.query);
var remove = _dechromeify2['default'](chrome.tabs, chrome.tabs.remove);
var update = _dechromeify2['default'](chrome.tabs, chrome.tabs.update);
var duplicate = _dechromeify2['default'](chrome.tabs, chrome.tabs.duplicate);
exports.create = create;
var _import = require('./windows');
var Windows = _interopRequireWildcard(_import);
var _dechromeifyAll = _dechromeifyAll2.dechromeifyAll(chrome.tabs, ['connect']);
var get = _dechromeifyAll.get;
var getCurrent = _dechromeifyAll.getCurrent;
var sendRequest = _dechromeifyAll.sendRequest;
var sendMessage = _dechromeifyAll.sendMessage;
var getSelected = _dechromeifyAll.getSelected;
var getAllInWindow = _dechromeifyAll.getAllInWindow;
var create = _dechromeifyAll.create;
var duplicate = _dechromeifyAll.duplicate;
var query = _dechromeifyAll.query;
var highlight = _dechromeifyAll.highlight;
var update = _dechromeifyAll.update;
var move = _dechromeifyAll.move;
var reload = _dechromeifyAll.reload;
var remove = _dechromeifyAll.remove;
var detectLanguage = _dechromeifyAll.detectLanguage;
var captureVisibleTab = _dechromeifyAll.captureVisibleTab;
var executeScript = _dechromeifyAll.executeScript;
var insertCSS = _dechromeifyAll.insertCSS;
var setZoom = _dechromeifyAll.setZoom;
var getZoom = _dechromeifyAll.getZoom;
var setZoomSettings = _dechromeifyAll.setZoomSettings;
var getZoomSettings = _dechromeifyAll.getZoomSettings;
var connect = _dechromeifyAll.connect;
exports.get = get;
exports.getCurrent = getCurrent;
exports.sendRequest = sendRequest;
exports.sendMessage = sendMessage;
exports.getSelected = getSelected;
exports.getAllInWindow = getAllInWindow;
exports.create = create;
exports.duplicate = duplicate;
exports.query = query;
exports.highlight = highlight;
exports.update = update;
exports.move = move;
exports.query = query;
exports.reload = reload;
exports.remove = remove;
exports.update = update;
exports.duplicate = duplicate;
exports.detectLanguage = detectLanguage;
exports.captureVisibleTab = captureVisibleTab;
exports.executeScript = executeScript;
exports.insertCSS = insertCSS;
exports.setZoom = setZoom;
exports.getZoom = getZoom;
exports.setZoomSettings = setZoomSettings;
exports.getZoomSettings = getZoomSettings;
exports.connect = connect;
/**
* Generator: Iterate backwards over an array
*/
function backwards(arr) {
var i;
return regeneratorRuntime.wrap(function backwards$(context$1$0) {
while (1) switch (context$1$0.prev = context$1$0.next) {
case 0:
i = arr.length - 1;
case 1:
if (!(i >= 0)) {
context$1$0.next = 7;
break;
}
context$1$0.next = 4;
return arr[i];
case 4:
--i;
context$1$0.next = 1;
break;
case 7:
case 'end':
return context$1$0.stop();
}
}, marked0$0[0], this);
}
var isOpera = navigator.vendor.indexOf('Opera') !== -1;
function getHighlighted() {
// TODO: file a bug report about this
// Opera doesn't have highlighted tabs, so we have to customize the query
if (isOpera) {
return query({ lastFocusedWindow: true, active: true });
} else {
return query({ lastFocusedWindow: true, highlighted: true });
}
// Opera doesn't have highlighted tabs, so we have to customize the query
if (isOpera) {
return query({ lastFocusedWindow: true, active: true });
} else {
return query({ lastFocusedWindow: true, highlighted: true });
}
}
function getActive() {
return query({ lastFocusedWindow: true, active: true }).then(function (results) {
return results[0];
});
return query({ lastFocusedWindow: true, active: true }).then(function (results) {
return results[0];
});
}
function show(openerTab, url) {
// if (openerTab.url === 'chrome://newtab/' && !openerTab.incognito) {
// return Promise.all([ Chrome.createTab({ url }), Chrome.removeTabs(openerTab.id) ]);
// }
return Chrome.createTab({ url: url, openerTabId: openerTab.id });
function open(openerTab, url) {
// if (openerTab.url === 'chrome://newtab/' && !openerTab.incognito) {
// return Promise.all([ create({ url }), remove(openerTab.id) ]);
// }
return create({ url: url, openerTabId: openerTab.id });
}
function count() {
return Chrome.queryTabs({ windowType: 'normal' }).then(function (tabs) {
return tabs.length;
});
return query({ windowType: 'normal' }).then(function (tabs) {
return tabs.length;
});
}
function moveHighlighted(direction) {
Chrome.getLastFocusedWindow({ populate: true }).then(function (wnd) {
var numTabs = wnd.tabs.length;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
if (direction === 0) {
throw new TypeError('The direction parameter can\'t be zero');
}
Windows.getLastFocused({ populate: true }).then(function (wnd) {
// Opera reports all tabs as not highlighted, even the active one
var highlighted = wnd.tabs.filter(function (t) {
return t.highlighted || t.active;
});
var tabs = wnd.tabs;
try {
for (var _iterator = (direction > 0 ? backwards(wnd.tabs) : wnd.tabs)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var tab = _step.value;
// Change the iteration behaviour to backwards
if (direction > 0) {
highlighted[Symbol.iterator] = backwardsIterator;
}
// Opera doesn't have highlighted tabs, so we also check for .active
if (!tab.highlighted && !tab.active) {
continue;
}
// Iterate through all highlighted tabs
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
// TODO: make this more efficient with many tabs
var newIndex = tab.index;
do {
// Moving pinned tabs into non-pinned tabs (and vice-versa) is impossible,
// so we have to skip those indexes
newIndex = (newIndex + direction + numTabs) % numTabs;
} while (tab.pinned !== wnd.tabs[newIndex].pinned);
try {
for (var _iterator = highlighted[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var tab = _step.value;
Chrome.moveTabs(tab.id, { index: newIndex });
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator['return']) {
_iterator['return']();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
});
var index = tab.index;
do {
index = (tabs.length + index + direction) % tabs.length;
} while (tab.pinned !== tabs[index].pinned);
move(tab.id, { index: index });
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator['return']) {
_iterator['return']();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
});
}
function moveToWindow(tabs, targetWindowId, incognito) {
var tabIds = tabs.map(function (tab) {
return tab.id;
});
var activeTab = tabs.find(function (tab) {
return tab.active;
});
/**
* Iterates backwards over an array.
* Does not handle sparse arrays in a special way, just like
* the original iterator.
*/
function backwardsIterator() {
var array = this;
var i = array.length;
return {
next: function next() {
var value = array[--i];
return i < 0 ? { done: true } : { value: value };
}
};
}
function moveToNewWindow(tabs, incognito) {
var tabIds = tabs.map(function (tab) {
return tab.id;
});
var activeTab = tabs.find(function (tab) {
return tab.active;
});
if (targetWindowId === undefined) {
// Create a new window
setTimeout(function () {
// Use the first tab, so that we don't get a NTP
Chrome.createWindow({ tabId: tabIds.shift(), focused: true, incognito: incognito }).then(function (wnd) {
if (tabIds.length > 0) {
Chrome.moveTabs(tabIds, { windowId: wnd.id, index: -1 }).then(function () {
Chrome.updateTab(activeTab.id, { active: true });
});
}
});
}, 0);
} else {
// Use existing window
Chrome.updateWindow(targetWindowId, { focused: true });
Chrome.moveTabs(tabIds, { windowId: targetWindowId, index: -1 }).then(function () {
Chrome.updateTab(activeTab.id, { active: true });
});
}
setTimeout(function () {
// Use the first tab, so that we don't get a NTP
Windows.create({ tabId: tabIds.shift(), focused: true, incognito: incognito }).then(function (wnd) {
if (tabIds.length > 0) {
move(tabIds, { windowId: wnd.id, index: -1 }).then(function () {
update(activeTab.id, { active: true });
});
}
});
}, 0);
}
function moveToWindow(tabs, targetWindowId) {
var tabIds = tabs.map(function (tab) {
return tab.id;
});
var activeTab = tabs.find(function (tab) {
return tab.active;
});
Windows.update(targetWindowId, { focused: true });
move(tabIds, { windowId: targetWindowId, index: -1 }).then(function () {
update(activeTab.id, { active: true });
});
}
function closeOthers() {
Promise.all([getCurrent(), Windows.getAll({ populate: true })]).then(function (sourceTab, windows) {
// Identify the window that hosts the sourceTab
var sourceWindow;
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = windows[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var wnd = _step2.value;
if (wnd.id === sourceTab.windowId) {
sourceWindow = wnd;
} else {
// Close other windows
Windows.remove(wnd.id);
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2['return']) {
_iterator2['return']();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
// Close other tabs
var tabIds = sourceWindow.tabs.map(function (t) {
return t.id;
}).filter(function (id) {
return id !== sourceTab.id;
});
remove(tabIds);
});
}
// async
// sync

@@ -7,21 +7,62 @@ 'use strict';

var _interopRequireDefault = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; };
var _interopRequireWildcard = function (obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } };
var _dechromeify = require('./dechromeify');
/**
* Opens all windows/tabs that are passed into this function.
* Re-uses the current window for the first window and just opens
* new tabs in it if it only has one tab.
*
* @param windows: 2-dimensional array of windows and URLs
*/
exports.open = open;
/*
* Documentation:
* https://developer.chrome.com/extensions/windows#toc
*/
var _dechromeify2 = _interopRequireDefault(_dechromeify);
var _dechromeifyAll2 = require('./dechromeify');
// TODO: automatically convert the module
var create = _dechromeify2['default'](chrome.windows, chrome.windows.create);
var get = _dechromeify2['default'](chrome.windows, chrome.windows.get);
var getAll = _dechromeify2['default'](chrome.windows, chrome.windows.getAll);
var getLastFocused = _dechromeify2['default'](chrome.windows, chrome.windows.getLastFocused);
var update = _dechromeify2['default'](chrome.windows, chrome.windows.update);
var remove = _dechromeify2['default'](chrome.windows, chrome.windows.remove);
var _import = require('./tabs');
exports.create = create;
var Tabs = _interopRequireWildcard(_import);
var _dechromeifyAll = _dechromeifyAll2.dechromeifyAll(chrome.windows);
var get = _dechromeifyAll.get;
var getCurrent = _dechromeifyAll.getCurrent;
var getLastFocused = _dechromeifyAll.getLastFocused;
var getAll = _dechromeifyAll.getAll;
var create = _dechromeifyAll.create;
var update = _dechromeifyAll.update;
var remove = _dechromeifyAll.remove;
exports.get = get;
exports.getCurrent = getCurrent;
exports.getLastFocused = getLastFocused;
exports.getAll = getAll;
exports.getLastFocused = getLastFocused;
exports.create = create;
exports.update = update;
exports.remove = remove;
function open(windows) {
var reuseThreshold = arguments[1] === undefined ? 1 : arguments[1];
getLastFocused({ populate: true }).then(function (wnd) {
// New tabs to create in the CURRENT window
var newTabs = wnd.tabs.length <= reuseThreshold ? windows.shift() : [];
// Open new windows
windows.forEach(function (urls) {
create({ url: urls, focused: false });
});
// Restore focus and open new tabs
if (newTabs.length > 0) {
update(wnd.id, { focused: true });
}
newTabs.forEach(function (url) {
Tabs.create({ windowId: wnd.id, url: url, active: false });
});
});
}
// async

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc