-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js.html
136 lines (112 loc) · 3.32 KB
/
main.js.html
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: main.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: main.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* @author https://github.com/glegoux
* @overview Main utilities
*/
'use strict';
/**
* Utility Class managing tabs.
*
* @class
*/
class Main {
/**
* Get all tab identifiers for each window under shape
* a <tt>Map[int, array[int]]</tt> object.
*
* @memberof Main
* @public
*
* @returns {Promise.<Map>}
*
* @see https://developer.chrome.com/extensions/tabs#method-query
*/
static getTabIdsPerWindow() {
return new Promise(resolve => {
let result = new Map();
chrome.tabs.query({}, tabs => {
tabs.forEach(tab => {
let windowId = tab.windowId;
let tabId = tab.id;
if (!result.has(windowId)) {
result.set(windowId, []);
}
result.get(windowId).push(tabId);
});
resolve(result);
});
});
}
/**
* Get the current window under shape <tt>Window</tt> object.
*
* @memberof Main
* @public
*
* @returns {Promise.<Window>}
*
* @see https://developer.chrome.com/extensions/windows#method-getCurrent
* @see https://developer.chrome.com/extensions/windows#type-Window
*/
static getCurrentWindow() {
return new Promise(resolve => {
chrome.windows.getCurrent(resolve);
});
}
/**
* Merge all windows in the current window.
*
* @memberof Main
* @public
*
* @returns {Promise.<undefined>}
*
* @see Main.getTabIdsPerWindow
* @see Main.getCurrentWindow
*/
static mergeAllWindows() {
let currentWindow = Main.getCurrentWindow();
let tabIdsPerWindow = Main.getTabIdsPerWindow();
return Promise.all([currentWindow, tabIdsPerWindow])
.then(([currentWindow, tabIdsPerWindow]) => {
tabIdsPerWindow.forEach((tabIds, windowId) => {
if (windowId !== currentWindow.id) {
chrome.tabs.move(tabIds,
{windowId: currentWindow.id, index: -1});
}
});
});
}
}
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Main.html">Main</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Tue Jun 13 2017 15:29:18 GMT+0200 (CEST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>