├── CHANGELOG.md
├── ISSUE_TEMPLATE.md
├── LICENSE
├── README.md
├── images
├── arrange.svg
├── icons
│ ├── icon.svg
│ ├── icon128.png
│ ├── icon16.png
│ └── icon48.png
├── search.svg
├── settings.svg
└── tabs.svg
├── manifest.json
├── scripts
├── lib
│ ├── jquery
│ │ ├── jquery-3.3.1.min.js
│ │ └── jquery-ui.js
│ ├── platform.js
│ └── underscore.js
├── src
│ ├── bg.js
│ ├── listeners.js
│ ├── main.js
│ ├── renderHTML.js
│ ├── tabGroup.js
│ └── tabManager.js
└── utils
│ └── utils.js
├── store_content
├── large_tile_icon.png
├── large_tile_icon.svg
├── marquee_tile_icon.png
├── marquee_tile_icon.svg
├── screenshots
│ ├── Screen_Shot_4_Col.png
│ ├── Screen_Shot_6_Col.png
│ ├── Screen_Shot_Settings_4_Col.png
│ ├── Screen_Shot_Settings_All_2_Col.png
│ └── Screen_Shot_Settings_All_4_Col.png
├── small_tile_icon.png
├── small_tile_icon.svg
└── tile_icon.png
├── styles
├── lib
│ ├── bootstrap.min.css
│ └── fontawesome
│ │ ├── css
│ │ └── fontawesome-all.min.css
│ │ └── webfonts
│ │ ├── fa-brands-400.eot
│ │ ├── fa-brands-400.svg
│ │ ├── fa-brands-400.ttf
│ │ ├── fa-brands-400.woff
│ │ ├── fa-brands-400.woff2
│ │ ├── fa-regular-400.eot
│ │ ├── fa-regular-400.svg
│ │ ├── fa-regular-400.ttf
│ │ ├── fa-regular-400.woff
│ │ ├── fa-regular-400.woff2
│ │ ├── fa-solid-900.eot
│ │ ├── fa-solid-900.svg
│ │ ├── fa-solid-900.ttf
│ │ ├── fa-solid-900.woff
│ │ └── fa-solid-900.woff2
└── src
│ ├── arrangementOptions.css
│ ├── main.css
│ ├── modals.css
│ ├── settings.css
│ ├── tabGroups.css
│ └── windows.css
└── tabPage.html
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 | All changes between releases of this project will be documented here.
3 |
4 | ## [0.4.0](https://github.com/adamjamesadair/manage-my-tabs/releases/tag/v0.4.0) - 2019-03-05
5 | ### Added
6 | - An option to view and restore tabs closed during the current session.
7 |
8 | ### Modified
9 | - Focus is set to the search bar when opening Manage My Tabs.
10 | - The shortcut to open MMT has been changed from Ctrl + space to Alt + M to avoid conflicts
11 | - Change in the default settings:
12 | - Include manager tab default set to true
13 | - Close manager on click default set to false
14 |
15 |
16 |
17 | ## [0.3.1](https://github.com/adamjamesadair/manage-my-tabs/releases/tag/v0.3.1) - 2018-06-13
18 | ### Fixed
19 | - Page reloading too often causing slow load times and closing of tab groups.
20 | - Typing in the search bar triggering shortcuts.
21 | - Visibility of 'No search results' text.
22 |
23 | ## [0.3.0](https://github.com/adamjamesadair/manage-my-tabs/releases/tag/v0.3.0) - 2018-06-13
24 | ### Added
25 | - Option to copy the URL of a tab. Found in the tab options dropdown.
26 | - Option to Merge tab, tab group or window with another window or send to a new window. Found in the options dropdown.
27 | - Reload option for tabs, tab groups and windows. Found in the options dropdown.
28 | - A button in the 'All' section to close all windows. Confirmation is required to prevent accidents.
29 | - Shortcuts for navigation and major functions. A list of available shortcuts can be seen in settings -> View Shortcuts.
30 |
31 | ### Fixed
32 | - Page reloading when a tab title is changed. Only the HTML element is updated now.
33 |
34 | ## [0.2.1](https://github.com/adamjamesadair/manage-my-tabs/releases/tag/v0.2.1) - 2018-06-08
35 | ### Fixed
36 | - Search results not updating when deleting part of the search query.
37 | - Multiple instances of Manage My Tabs opening in Firefox.
38 | - Undo for closed windows not working in Firefox.
39 |
40 |
41 | ## [0.2.0](https://github.com/adamjamesadair/manage-my-tabs/releases/tag/v0.2.0) - 2018-06-08
42 | ### Added
43 | - Firefox support.
44 | - Shortcuts for navigating windows and opening settings.
45 | - New default view where tabs are all displayed on one screen and grouped by window.
46 | - Classic mode which functions as v0.1.0.
47 | - New styles for settings and navigating tabs, tab groups and windows.
48 | - Settings:
49 | - Max tabs per tab group toggle and slider.
50 | - Close extension after navigating to a tab.
51 | - Allow scrolling beyond the end of the last window.
52 | - Toggle Classic mode.
53 |
54 | ### Changed
55 | - Window select buttons scroll to selected window instead of changing pages.
56 | - Moved search options closer to the search bar.
57 | - Arrange tabs button now arranges the tabs in all windows.
58 |
59 | ### Fixed
60 | - Tabs being placed in wrong tab groups.
61 | - Undo button causing dulicate tabs to be opened.
62 | - Changing the search settings not refreshing the results.
63 | - Errors when using undo with tab groups
64 |
65 | ## [0.1.0](https://github.com/adamjamesadair/manage-my-tabs/releases/tag/v0.1.0) - 2018-05-17
66 | ### Added
67 | - Button to reorder tabs in current window.
68 | - Tooltip to settings icon.
69 | - Selected window is now highlighted in the 'select window' section.
70 |
71 | ### Changed
72 | - Restyled the links to tabs.
73 | - Restyled column setting buttons.
74 | - Restyled undo and select window buttons.
75 | - Moved setting for displaying tabs from all tabs to 'All' button in 'select window' section.
76 | - Manage My Tabs remains open when opening a new tab or changing tab focus.
77 |
78 | ### Fixed
79 | - Issue with extension tabs showing their id as the title.
80 |
--------------------------------------------------------------------------------
/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
2 | ## Description of the problem
3 |
4 |
5 | ## Browser
6 |
7 |
8 | ## Expected behaviour
9 |
10 |
11 | ## Steps to reproduce the problem
12 |
13 | -
14 | -
15 | -
16 |
17 | ## Possible cause and/or solution (Optional)
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 adamjamesadair
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | Manage My Tabs - Window and Tab Manager
4 |
5 |
6 |
7 | ## Description
8 |
9 | Manage My Tabs is an extension that gives the user a quick and simple way to manage their tabs. Tabs are grouped by website name and are shown in one convinient tab that the user may search and customize. From the manager tab, the user can navigate to any tab, close tabs individually or by groups and view tabs from other windows.
10 |
11 | ## Website
12 | https://adamjamesadair.github.io/manage-my-tabs
13 |
14 | ## Installation
15 | ### Chrome
16 | Install the latest release through the chrome web store: \
17 | https://chrome.google.com/webstore/detail/manage-my-tabs-tab-manage/jbhejjmjopbmikcoffcckcnbaiohgbge
18 |
19 | #### Unpacked Extension (Development release)
20 | - If you downloaded the code, unzip the file.
21 | - Open the extension manager by navigating to [chrome://extensions/](chrome://extensions/) or by clicking `Window -> Extensions`.
22 | - Enable developer mode with the toggle in the top right corner.
23 | - Click `LOAD UNPACKED` and select the source code folder or drag the folder into the window.
24 |
25 | ### Firefox
26 | Install the latest release through the firefox add-on gallery: \
27 | https://addons.mozilla.org/en-US/firefox/addon/manage-my-tabs/
28 | #### Unpacked Extension (Development release)
29 | - If you downloaded the code, unzip the file.
30 | - Open the extension manager by navigating to [about:debugging](about:debugging).
31 | - Click `Load Temporary Add-on` and select the manifest.json file.
32 |
33 | For development releases, download the [source code](https://github.com/adamjamesadair/manage-my-tabs) or clone this repository.
34 |
35 | ## Contributing
36 |
37 | Thank you for your interest in the development of Manage My Tabs!
38 |
39 | Please look at the [project boards](https://github.com/adamjamesadair/manage-my-tabs/projects) and specifically the [Main Development](https://github.com/adamjamesadair/manage-my-tabs/projects/4) project to see our plans for future releases.
40 |
41 | Please work from and submit all pull requests to the `develop` branch. The `master` branch is reserved for public releases and will often be several commits behind the `develop` branch.
42 |
43 | ### Pull Requests
44 | Please submit an issue describing the nature your changes before submitting a pull request. This helps us keep track of the development process.
45 |
46 | ## Change Log
47 | See the change log [here](https://github.com/adamjamesadair/manage-my-tabs/blob/master/CHANGELOG.md).
48 |
49 | ## License
50 | [MIT](http://opensource.org/licenses/MIT)
51 |
--------------------------------------------------------------------------------
/images/arrange.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
141 |
--------------------------------------------------------------------------------
/images/icons/icon.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
118 |
--------------------------------------------------------------------------------
/images/icons/icon128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adamjamesadair/manage-my-tabs/053973bef3c0144ccb348dc16671aec93b1472cf/images/icons/icon128.png
--------------------------------------------------------------------------------
/images/icons/icon16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adamjamesadair/manage-my-tabs/053973bef3c0144ccb348dc16671aec93b1472cf/images/icons/icon16.png
--------------------------------------------------------------------------------
/images/icons/icon48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adamjamesadair/manage-my-tabs/053973bef3c0144ccb348dc16671aec93b1472cf/images/icons/icon48.png
--------------------------------------------------------------------------------
/images/search.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
84 |
--------------------------------------------------------------------------------
/images/settings.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
73 |
--------------------------------------------------------------------------------
/images/tabs.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
188 |
--------------------------------------------------------------------------------
/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "manifest_version": 2,
3 |
4 | "name": "Manage My Tabs - Tab Manager",
5 | "description": "Manage My Tabs is an extension that gives the user a quick and simple way to manage their tabs.",
6 | "version": "0.4.0",
7 |
8 | "browser_action": {
9 | "default_icon": "images/icons/icon128.png"
10 | },
11 | "icons": { "16": "images/icons/icon16.png",
12 | "48": "images/icons/icon48.png",
13 | "128": "images/icons/icon128.png"
14 | },
15 | "permissions": [
16 | "tabs",
17 | "activeTab",
18 | "storage",
19 | "clipboardWrite"
20 | ],
21 | "background":{
22 | "scripts": ["scripts/src/bg.js"]
23 | },
24 | "commands": {
25 | "_execute_browser_action": {
26 | "suggested_key": {
27 | "default": "Alt+M",
28 | "mac": "Alt+M"
29 | }
30 | }
31 | },
32 | "content_scripts": [
33 | {
34 | "matches": ["https://*/*"],
35 | "js": ["scripts/lib/jquery/jquery-3.3.1.min.js", "scripts/lib/jquery/jquery-ui.js"]
36 | }
37 | ]
38 | }
39 |
--------------------------------------------------------------------------------
/scripts/lib/platform.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * Platform.js
3 | * Copyright 2014-2018 Benjamin Tan
4 | * Copyright 2011-2013 John-David Dalton
5 | * Available under MIT license
6 | */
7 | ;(function() {
8 | 'use strict';
9 |
10 | /** Used to determine if values are of the language type `Object`. */
11 | var objectTypes = {
12 | 'function': true,
13 | 'object': true
14 | };
15 |
16 | /** Used as a reference to the global object. */
17 | var root = (objectTypes[typeof window] && window) || this;
18 |
19 | /** Backup possible global object. */
20 | var oldRoot = root;
21 |
22 | /** Detect free variable `exports`. */
23 | var freeExports = objectTypes[typeof exports] && exports;
24 |
25 | /** Detect free variable `module`. */
26 | var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
27 |
28 | /** Detect free variable `global` from Node.js or Browserified code and use it as `root`. */
29 | var freeGlobal = freeExports && freeModule && typeof global == 'object' && global;
30 | if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
31 | root = freeGlobal;
32 | }
33 |
34 | /**
35 | * Used as the maximum length of an array-like object.
36 | * See the [ES6 spec](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength)
37 | * for more details.
38 | */
39 | var maxSafeInteger = Math.pow(2, 53) - 1;
40 |
41 | /** Regular expression to detect Opera. */
42 | var reOpera = /\bOpera/;
43 |
44 | /** Possible global object. */
45 | var thisBinding = this;
46 |
47 | /** Used for native method references. */
48 | var objectProto = Object.prototype;
49 |
50 | /** Used to check for own properties of an object. */
51 | var hasOwnProperty = objectProto.hasOwnProperty;
52 |
53 | /** Used to resolve the internal `[[Class]]` of values. */
54 | var toString = objectProto.toString;
55 |
56 | /*--------------------------------------------------------------------------*/
57 |
58 | /**
59 | * Capitalizes a string value.
60 | *
61 | * @private
62 | * @param {string} string The string to capitalize.
63 | * @returns {string} The capitalized string.
64 | */
65 | function capitalize(string) {
66 | string = String(string);
67 | return string.charAt(0).toUpperCase() + string.slice(1);
68 | }
69 |
70 | /**
71 | * A utility function to clean up the OS name.
72 | *
73 | * @private
74 | * @param {string} os The OS name to clean up.
75 | * @param {string} [pattern] A `RegExp` pattern matching the OS name.
76 | * @param {string} [label] A label for the OS.
77 | */
78 | function cleanupOS(os, pattern, label) {
79 | // Platform tokens are defined at:
80 | // http://msdn.microsoft.com/en-us/library/ms537503(VS.85).aspx
81 | // http://web.archive.org/web/20081122053950/http://msdn.microsoft.com/en-us/library/ms537503(VS.85).aspx
82 | var data = {
83 | '10.0': '10',
84 | '6.4': '10 Technical Preview',
85 | '6.3': '8.1',
86 | '6.2': '8',
87 | '6.1': 'Server 2008 R2 / 7',
88 | '6.0': 'Server 2008 / Vista',
89 | '5.2': 'Server 2003 / XP 64-bit',
90 | '5.1': 'XP',
91 | '5.01': '2000 SP1',
92 | '5.0': '2000',
93 | '4.0': 'NT',
94 | '4.90': 'ME'
95 | };
96 | // Detect Windows version from platform tokens.
97 | if (pattern && label && /^Win/i.test(os) && !/^Windows Phone /i.test(os) &&
98 | (data = data[/[\d.]+$/.exec(os)])) {
99 | os = 'Windows ' + data;
100 | }
101 | // Correct character case and cleanup string.
102 | os = String(os);
103 |
104 | if (pattern && label) {
105 | os = os.replace(RegExp(pattern, 'i'), label);
106 | }
107 |
108 | os = format(
109 | os.replace(/ ce$/i, ' CE')
110 | .replace(/\bhpw/i, 'web')
111 | .replace(/\bMacintosh\b/, 'Mac OS')
112 | .replace(/_PowerPC\b/i, ' OS')
113 | .replace(/\b(OS X) [^ \d]+/i, '$1')
114 | .replace(/\bMac (OS X)\b/, '$1')
115 | .replace(/\/(\d)/, ' $1')
116 | .replace(/_/g, '.')
117 | .replace(/(?: BePC|[ .]*fc[ \d.]+)$/i, '')
118 | .replace(/\bx86\.64\b/gi, 'x86_64')
119 | .replace(/\b(Windows Phone) OS\b/, '$1')
120 | .replace(/\b(Chrome OS \w+) [\d.]+\b/, '$1')
121 | .split(' on ')[0]
122 | );
123 |
124 | return os;
125 | }
126 |
127 | /**
128 | * An iteration utility for arrays and objects.
129 | *
130 | * @private
131 | * @param {Array|Object} object The object to iterate over.
132 | * @param {Function} callback The function called per iteration.
133 | */
134 | function each(object, callback) {
135 | var index = -1,
136 | length = object ? object.length : 0;
137 |
138 | if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) {
139 | while (++index < length) {
140 | callback(object[index], index, object);
141 | }
142 | } else {
143 | forOwn(object, callback);
144 | }
145 | }
146 |
147 | /**
148 | * Trim and conditionally capitalize string values.
149 | *
150 | * @private
151 | * @param {string} string The string to format.
152 | * @returns {string} The formatted string.
153 | */
154 | function format(string) {
155 | string = trim(string);
156 | return /^(?:webOS|i(?:OS|P))/.test(string)
157 | ? string
158 | : capitalize(string);
159 | }
160 |
161 | /**
162 | * Iterates over an object's own properties, executing the `callback` for each.
163 | *
164 | * @private
165 | * @param {Object} object The object to iterate over.
166 | * @param {Function} callback The function executed per own property.
167 | */
168 | function forOwn(object, callback) {
169 | for (var key in object) {
170 | if (hasOwnProperty.call(object, key)) {
171 | callback(object[key], key, object);
172 | }
173 | }
174 | }
175 |
176 | /**
177 | * Gets the internal `[[Class]]` of a value.
178 | *
179 | * @private
180 | * @param {*} value The value.
181 | * @returns {string} The `[[Class]]`.
182 | */
183 | function getClassOf(value) {
184 | return value == null
185 | ? capitalize(value)
186 | : toString.call(value).slice(8, -1);
187 | }
188 |
189 | /**
190 | * Host objects can return type values that are different from their actual
191 | * data type. The objects we are concerned with usually return non-primitive
192 | * types of "object", "function", or "unknown".
193 | *
194 | * @private
195 | * @param {*} object The owner of the property.
196 | * @param {string} property The property to check.
197 | * @returns {boolean} Returns `true` if the property value is a non-primitive, else `false`.
198 | */
199 | function isHostType(object, property) {
200 | var type = object != null ? typeof object[property] : 'number';
201 | return !/^(?:boolean|number|string|undefined)$/.test(type) &&
202 | (type == 'object' ? !!object[property] : true);
203 | }
204 |
205 | /**
206 | * Prepares a string for use in a `RegExp` by making hyphens and spaces optional.
207 | *
208 | * @private
209 | * @param {string} string The string to qualify.
210 | * @returns {string} The qualified string.
211 | */
212 | function qualify(string) {
213 | return String(string).replace(/([ -])(?!$)/g, '$1?');
214 | }
215 |
216 | /**
217 | * A bare-bones `Array#reduce` like utility function.
218 | *
219 | * @private
220 | * @param {Array} array The array to iterate over.
221 | * @param {Function} callback The function called per iteration.
222 | * @returns {*} The accumulated result.
223 | */
224 | function reduce(array, callback) {
225 | var accumulator = null;
226 | each(array, function(value, index) {
227 | accumulator = callback(accumulator, value, index, array);
228 | });
229 | return accumulator;
230 | }
231 |
232 | /**
233 | * Removes leading and trailing whitespace from a string.
234 | *
235 | * @private
236 | * @param {string} string The string to trim.
237 | * @returns {string} The trimmed string.
238 | */
239 | function trim(string) {
240 | return String(string).replace(/^ +| +$/g, '');
241 | }
242 |
243 | /*--------------------------------------------------------------------------*/
244 |
245 | /**
246 | * Creates a new platform object.
247 | *
248 | * @memberOf platform
249 | * @param {Object|string} [ua=navigator.userAgent] The user agent string or
250 | * context object.
251 | * @returns {Object} A platform object.
252 | */
253 | function parse(ua) {
254 |
255 | /** The environment context object. */
256 | var context = root;
257 |
258 | /** Used to flag when a custom context is provided. */
259 | var isCustomContext = ua && typeof ua == 'object' && getClassOf(ua) != 'String';
260 |
261 | // Juggle arguments.
262 | if (isCustomContext) {
263 | context = ua;
264 | ua = null;
265 | }
266 |
267 | /** Browser navigator object. */
268 | var nav = context.navigator || {};
269 |
270 | /** Browser user agent string. */
271 | var userAgent = nav.userAgent || '';
272 |
273 | ua || (ua = userAgent);
274 |
275 | /** Used to flag when `thisBinding` is the [ModuleScope]. */
276 | var isModuleScope = isCustomContext || thisBinding == oldRoot;
277 |
278 | /** Used to detect if browser is like Chrome. */
279 | var likeChrome = isCustomContext
280 | ? !!nav.likeChrome
281 | : /\bChrome\b/.test(ua) && !/internal|\n/i.test(toString.toString());
282 |
283 | /** Internal `[[Class]]` value shortcuts. */
284 | var objectClass = 'Object',
285 | airRuntimeClass = isCustomContext ? objectClass : 'ScriptBridgingProxyObject',
286 | enviroClass = isCustomContext ? objectClass : 'Environment',
287 | javaClass = (isCustomContext && context.java) ? 'JavaPackage' : getClassOf(context.java),
288 | phantomClass = isCustomContext ? objectClass : 'RuntimeObject';
289 |
290 | /** Detect Java environments. */
291 | var java = /\bJava/.test(javaClass) && context.java;
292 |
293 | /** Detect Rhino. */
294 | var rhino = java && getClassOf(context.environment) == enviroClass;
295 |
296 | /** A character to represent alpha. */
297 | var alpha = java ? 'a' : '\u03b1';
298 |
299 | /** A character to represent beta. */
300 | var beta = java ? 'b' : '\u03b2';
301 |
302 | /** Browser document object. */
303 | var doc = context.document || {};
304 |
305 | /**
306 | * Detect Opera browser (Presto-based).
307 | * http://www.howtocreate.co.uk/operaStuff/operaObject.html
308 | * http://dev.opera.com/articles/view/opera-mini-web-content-authoring-guidelines/#operamini
309 | */
310 | var opera = context.operamini || context.opera;
311 |
312 | /** Opera `[[Class]]`. */
313 | var operaClass = reOpera.test(operaClass = (isCustomContext && opera) ? opera['[[Class]]'] : getClassOf(opera))
314 | ? operaClass
315 | : (opera = null);
316 |
317 | /*------------------------------------------------------------------------*/
318 |
319 | /** Temporary variable used over the script's lifetime. */
320 | var data;
321 |
322 | /** The CPU architecture. */
323 | var arch = ua;
324 |
325 | /** Platform description array. */
326 | var description = [];
327 |
328 | /** Platform alpha/beta indicator. */
329 | var prerelease = null;
330 |
331 | /** A flag to indicate that environment features should be used to resolve the platform. */
332 | var useFeatures = ua == userAgent;
333 |
334 | /** The browser/environment version. */
335 | var version = useFeatures && opera && typeof opera.version == 'function' && opera.version();
336 |
337 | /** A flag to indicate if the OS ends with "/ Version" */
338 | var isSpecialCasedOS;
339 |
340 | /* Detectable layout engines (order is important). */
341 | var layout = getLayout([
342 | { 'label': 'EdgeHTML', 'pattern': 'Edge' },
343 | 'Trident',
344 | { 'label': 'WebKit', 'pattern': 'AppleWebKit' },
345 | 'iCab',
346 | 'Presto',
347 | 'NetFront',
348 | 'Tasman',
349 | 'KHTML',
350 | 'Gecko'
351 | ]);
352 |
353 | /* Detectable browser names (order is important). */
354 | var name = getName([
355 | 'Adobe AIR',
356 | 'Arora',
357 | 'Avant Browser',
358 | 'Breach',
359 | 'Camino',
360 | 'Electron',
361 | 'Epiphany',
362 | 'Fennec',
363 | 'Flock',
364 | 'Galeon',
365 | 'GreenBrowser',
366 | 'iCab',
367 | 'Iceweasel',
368 | 'K-Meleon',
369 | 'Konqueror',
370 | 'Lunascape',
371 | 'Maxthon',
372 | { 'label': 'Microsoft Edge', 'pattern': 'Edge' },
373 | 'Midori',
374 | 'Nook Browser',
375 | 'PaleMoon',
376 | 'PhantomJS',
377 | 'Raven',
378 | 'Rekonq',
379 | 'RockMelt',
380 | { 'label': 'Samsung Internet', 'pattern': 'SamsungBrowser' },
381 | 'SeaMonkey',
382 | { 'label': 'Silk', 'pattern': '(?:Cloud9|Silk-Accelerated)' },
383 | 'Sleipnir',
384 | 'SlimBrowser',
385 | { 'label': 'SRWare Iron', 'pattern': 'Iron' },
386 | 'Sunrise',
387 | 'Swiftfox',
388 | 'Waterfox',
389 | 'WebPositive',
390 | 'Opera Mini',
391 | { 'label': 'Opera Mini', 'pattern': 'OPiOS' },
392 | 'Opera',
393 | { 'label': 'Opera', 'pattern': 'OPR' },
394 | 'Chrome',
395 | { 'label': 'Chrome Mobile', 'pattern': '(?:CriOS|CrMo)' },
396 | { 'label': 'Firefox', 'pattern': '(?:Firefox|Minefield)' },
397 | { 'label': 'Firefox for iOS', 'pattern': 'FxiOS' },
398 | { 'label': 'IE', 'pattern': 'IEMobile' },
399 | { 'label': 'IE', 'pattern': 'MSIE' },
400 | 'Safari'
401 | ]);
402 |
403 | /* Detectable products (order is important). */
404 | var product = getProduct([
405 | { 'label': 'BlackBerry', 'pattern': 'BB10' },
406 | 'BlackBerry',
407 | { 'label': 'Galaxy S', 'pattern': 'GT-I9000' },
408 | { 'label': 'Galaxy S2', 'pattern': 'GT-I9100' },
409 | { 'label': 'Galaxy S3', 'pattern': 'GT-I9300' },
410 | { 'label': 'Galaxy S4', 'pattern': 'GT-I9500' },
411 | { 'label': 'Galaxy S5', 'pattern': 'SM-G900' },
412 | { 'label': 'Galaxy S6', 'pattern': 'SM-G920' },
413 | { 'label': 'Galaxy S6 Edge', 'pattern': 'SM-G925' },
414 | { 'label': 'Galaxy S7', 'pattern': 'SM-G930' },
415 | { 'label': 'Galaxy S7 Edge', 'pattern': 'SM-G935' },
416 | 'Google TV',
417 | 'Lumia',
418 | 'iPad',
419 | 'iPod',
420 | 'iPhone',
421 | 'Kindle',
422 | { 'label': 'Kindle Fire', 'pattern': '(?:Cloud9|Silk-Accelerated)' },
423 | 'Nexus',
424 | 'Nook',
425 | 'PlayBook',
426 | 'PlayStation Vita',
427 | 'PlayStation',
428 | 'TouchPad',
429 | 'Transformer',
430 | { 'label': 'Wii U', 'pattern': 'WiiU' },
431 | 'Wii',
432 | 'Xbox One',
433 | { 'label': 'Xbox 360', 'pattern': 'Xbox' },
434 | 'Xoom'
435 | ]);
436 |
437 | /* Detectable manufacturers. */
438 | var manufacturer = getManufacturer({
439 | 'Apple': { 'iPad': 1, 'iPhone': 1, 'iPod': 1 },
440 | 'Archos': {},
441 | 'Amazon': { 'Kindle': 1, 'Kindle Fire': 1 },
442 | 'Asus': { 'Transformer': 1 },
443 | 'Barnes & Noble': { 'Nook': 1 },
444 | 'BlackBerry': { 'PlayBook': 1 },
445 | 'Google': { 'Google TV': 1, 'Nexus': 1 },
446 | 'HP': { 'TouchPad': 1 },
447 | 'HTC': {},
448 | 'LG': {},
449 | 'Microsoft': { 'Xbox': 1, 'Xbox One': 1 },
450 | 'Motorola': { 'Xoom': 1 },
451 | 'Nintendo': { 'Wii U': 1, 'Wii': 1 },
452 | 'Nokia': { 'Lumia': 1 },
453 | 'Samsung': { 'Galaxy S': 1, 'Galaxy S2': 1, 'Galaxy S3': 1, 'Galaxy S4': 1 },
454 | 'Sony': { 'PlayStation': 1, 'PlayStation Vita': 1 }
455 | });
456 |
457 | /* Detectable operating systems (order is important). */
458 | var os = getOS([
459 | 'Windows Phone',
460 | 'Android',
461 | 'CentOS',
462 | { 'label': 'Chrome OS', 'pattern': 'CrOS' },
463 | 'Debian',
464 | 'Fedora',
465 | 'FreeBSD',
466 | 'Gentoo',
467 | 'Haiku',
468 | 'Kubuntu',
469 | 'Linux Mint',
470 | 'OpenBSD',
471 | 'Red Hat',
472 | 'SuSE',
473 | 'Ubuntu',
474 | 'Xubuntu',
475 | 'Cygwin',
476 | 'Symbian OS',
477 | 'hpwOS',
478 | 'webOS ',
479 | 'webOS',
480 | 'Tablet OS',
481 | 'Tizen',
482 | 'Linux',
483 | 'Mac OS X',
484 | 'Macintosh',
485 | 'Mac',
486 | 'Windows 98;',
487 | 'Windows '
488 | ]);
489 |
490 | /*------------------------------------------------------------------------*/
491 |
492 | /**
493 | * Picks the layout engine from an array of guesses.
494 | *
495 | * @private
496 | * @param {Array} guesses An array of guesses.
497 | * @returns {null|string} The detected layout engine.
498 | */
499 | function getLayout(guesses) {
500 | return reduce(guesses, function(result, guess) {
501 | return result || RegExp('\\b' + (
502 | guess.pattern || qualify(guess)
503 | ) + '\\b', 'i').exec(ua) && (guess.label || guess);
504 | });
505 | }
506 |
507 | /**
508 | * Picks the manufacturer from an array of guesses.
509 | *
510 | * @private
511 | * @param {Array} guesses An object of guesses.
512 | * @returns {null|string} The detected manufacturer.
513 | */
514 | function getManufacturer(guesses) {
515 | return reduce(guesses, function(result, value, key) {
516 | // Lookup the manufacturer by product or scan the UA for the manufacturer.
517 | return result || (
518 | value[product] ||
519 | value[/^[a-z]+(?: +[a-z]+\b)*/i.exec(product)] ||
520 | RegExp('\\b' + qualify(key) + '(?:\\b|\\w*\\d)', 'i').exec(ua)
521 | ) && key;
522 | });
523 | }
524 |
525 | /**
526 | * Picks the browser name from an array of guesses.
527 | *
528 | * @private
529 | * @param {Array} guesses An array of guesses.
530 | * @returns {null|string} The detected browser name.
531 | */
532 | function getName(guesses) {
533 | return reduce(guesses, function(result, guess) {
534 | return result || RegExp('\\b' + (
535 | guess.pattern || qualify(guess)
536 | ) + '\\b', 'i').exec(ua) && (guess.label || guess);
537 | });
538 | }
539 |
540 | /**
541 | * Picks the OS name from an array of guesses.
542 | *
543 | * @private
544 | * @param {Array} guesses An array of guesses.
545 | * @returns {null|string} The detected OS name.
546 | */
547 | function getOS(guesses) {
548 | return reduce(guesses, function(result, guess) {
549 | var pattern = guess.pattern || qualify(guess);
550 | if (!result && (result =
551 | RegExp('\\b' + pattern + '(?:/[\\d.]+|[ \\w.]*)', 'i').exec(ua)
552 | )) {
553 | result = cleanupOS(result, pattern, guess.label || guess);
554 | }
555 | return result;
556 | });
557 | }
558 |
559 | /**
560 | * Picks the product name from an array of guesses.
561 | *
562 | * @private
563 | * @param {Array} guesses An array of guesses.
564 | * @returns {null|string} The detected product name.
565 | */
566 | function getProduct(guesses) {
567 | return reduce(guesses, function(result, guess) {
568 | var pattern = guess.pattern || qualify(guess);
569 | if (!result && (result =
570 | RegExp('\\b' + pattern + ' *\\d+[.\\w_]*', 'i').exec(ua) ||
571 | RegExp('\\b' + pattern + ' *\\w+-[\\w]*', 'i').exec(ua) ||
572 | RegExp('\\b' + pattern + '(?:; *(?:[a-z]+[_-])?[a-z]+\\d+|[^ ();-]*)', 'i').exec(ua)
573 | )) {
574 | // Split by forward slash and append product version if needed.
575 | if ((result = String((guess.label && !RegExp(pattern, 'i').test(guess.label)) ? guess.label : result).split('/'))[1] && !/[\d.]+/.test(result[0])) {
576 | result[0] += ' ' + result[1];
577 | }
578 | // Correct character case and cleanup string.
579 | guess = guess.label || guess;
580 | result = format(result[0]
581 | .replace(RegExp(pattern, 'i'), guess)
582 | .replace(RegExp('; *(?:' + guess + '[_-])?', 'i'), ' ')
583 | .replace(RegExp('(' + guess + ')[-_.]?(\\w)', 'i'), '$1 $2'));
584 | }
585 | return result;
586 | });
587 | }
588 |
589 | /**
590 | * Resolves the version using an array of UA patterns.
591 | *
592 | * @private
593 | * @param {Array} patterns An array of UA patterns.
594 | * @returns {null|string} The detected version.
595 | */
596 | function getVersion(patterns) {
597 | return reduce(patterns, function(result, pattern) {
598 | return result || (RegExp(pattern +
599 | '(?:-[\\d.]+/|(?: for [\\w-]+)?[ /-])([\\d.]+[^ ();/_-]*)', 'i').exec(ua) || 0)[1] || null;
600 | });
601 | }
602 |
603 | /**
604 | * Returns `platform.description` when the platform object is coerced to a string.
605 | *
606 | * @name toString
607 | * @memberOf platform
608 | * @returns {string} Returns `platform.description` if available, else an empty string.
609 | */
610 | function toStringPlatform() {
611 | return this.description || '';
612 | }
613 |
614 | /*------------------------------------------------------------------------*/
615 |
616 | // Convert layout to an array so we can add extra details.
617 | layout && (layout = [layout]);
618 |
619 | // Detect product names that contain their manufacturer's name.
620 | if (manufacturer && !product) {
621 | product = getProduct([manufacturer]);
622 | }
623 | // Clean up Google TV.
624 | if ((data = /\bGoogle TV\b/.exec(product))) {
625 | product = data[0];
626 | }
627 | // Detect simulators.
628 | if (/\bSimulator\b/i.test(ua)) {
629 | product = (product ? product + ' ' : '') + 'Simulator';
630 | }
631 | // Detect Opera Mini 8+ running in Turbo/Uncompressed mode on iOS.
632 | if (name == 'Opera Mini' && /\bOPiOS\b/.test(ua)) {
633 | description.push('running in Turbo/Uncompressed mode');
634 | }
635 | // Detect IE Mobile 11.
636 | if (name == 'IE' && /\blike iPhone OS\b/.test(ua)) {
637 | data = parse(ua.replace(/like iPhone OS/, ''));
638 | manufacturer = data.manufacturer;
639 | product = data.product;
640 | }
641 | // Detect iOS.
642 | else if (/^iP/.test(product)) {
643 | name || (name = 'Safari');
644 | os = 'iOS' + ((data = / OS ([\d_]+)/i.exec(ua))
645 | ? ' ' + data[1].replace(/_/g, '.')
646 | : '');
647 | }
648 | // Detect Kubuntu.
649 | else if (name == 'Konqueror' && !/buntu/i.test(os)) {
650 | os = 'Kubuntu';
651 | }
652 | // Detect Android browsers.
653 | else if ((manufacturer && manufacturer != 'Google' &&
654 | ((/Chrome/.test(name) && !/\bMobile Safari\b/i.test(ua)) || /\bVita\b/.test(product))) ||
655 | (/\bAndroid\b/.test(os) && /^Chrome/.test(name) && /\bVersion\//i.test(ua))) {
656 | name = 'Android Browser';
657 | os = /\bAndroid\b/.test(os) ? os : 'Android';
658 | }
659 | // Detect Silk desktop/accelerated modes.
660 | else if (name == 'Silk') {
661 | if (!/\bMobi/i.test(ua)) {
662 | os = 'Android';
663 | description.unshift('desktop mode');
664 | }
665 | if (/Accelerated *= *true/i.test(ua)) {
666 | description.unshift('accelerated');
667 | }
668 | }
669 | // Detect PaleMoon identifying as Firefox.
670 | else if (name == 'PaleMoon' && (data = /\bFirefox\/([\d.]+)\b/.exec(ua))) {
671 | description.push('identifying as Firefox ' + data[1]);
672 | }
673 | // Detect Firefox OS and products running Firefox.
674 | else if (name == 'Firefox' && (data = /\b(Mobile|Tablet|TV)\b/i.exec(ua))) {
675 | os || (os = 'Firefox OS');
676 | product || (product = data[1]);
677 | }
678 | // Detect false positives for Firefox/Safari.
679 | else if (!name || (data = !/\bMinefield\b/i.test(ua) && /\b(?:Firefox|Safari)\b/.exec(name))) {
680 | // Escape the `/` for Firefox 1.
681 | if (name && !product && /[\/,]|^[^(]+?\)/.test(ua.slice(ua.indexOf(data + '/') + 8))) {
682 | // Clear name of false positives.
683 | name = null;
684 | }
685 | // Reassign a generic name.
686 | if ((data = product || manufacturer || os) &&
687 | (product || manufacturer || /\b(?:Android|Symbian OS|Tablet OS|webOS)\b/.test(os))) {
688 | name = /[a-z]+(?: Hat)?/i.exec(/\bAndroid\b/.test(os) ? os : data) + ' Browser';
689 | }
690 | }
691 | // Add Chrome version to description for Electron.
692 | else if (name == 'Electron' && (data = (/\bChrome\/([\d.]+)\b/.exec(ua) || 0)[1])) {
693 | description.push('Chromium ' + data);
694 | }
695 | // Detect non-Opera (Presto-based) versions (order is important).
696 | if (!version) {
697 | version = getVersion([
698 | '(?:Cloud9|CriOS|CrMo|Edge|FxiOS|IEMobile|Iron|Opera ?Mini|OPiOS|OPR|Raven|SamsungBrowser|Silk(?!/[\\d.]+$))',
699 | 'Version',
700 | qualify(name),
701 | '(?:Firefox|Minefield|NetFront)'
702 | ]);
703 | }
704 | // Detect stubborn layout engines.
705 | if ((data =
706 | layout == 'iCab' && parseFloat(version) > 3 && 'WebKit' ||
707 | /\bOpera\b/.test(name) && (/\bOPR\b/.test(ua) ? 'Blink' : 'Presto') ||
708 | /\b(?:Midori|Nook|Safari)\b/i.test(ua) && !/^(?:Trident|EdgeHTML)$/.test(layout) && 'WebKit' ||
709 | !layout && /\bMSIE\b/i.test(ua) && (os == 'Mac OS' ? 'Tasman' : 'Trident') ||
710 | layout == 'WebKit' && /\bPlayStation\b(?! Vita\b)/i.test(name) && 'NetFront'
711 | )) {
712 | layout = [data];
713 | }
714 | // Detect Windows Phone 7 desktop mode.
715 | if (name == 'IE' && (data = (/; *(?:XBLWP|ZuneWP)(\d+)/i.exec(ua) || 0)[1])) {
716 | name += ' Mobile';
717 | os = 'Windows Phone ' + (/\+$/.test(data) ? data : data + '.x');
718 | description.unshift('desktop mode');
719 | }
720 | // Detect Windows Phone 8.x desktop mode.
721 | else if (/\bWPDesktop\b/i.test(ua)) {
722 | name = 'IE Mobile';
723 | os = 'Windows Phone 8.x';
724 | description.unshift('desktop mode');
725 | version || (version = (/\brv:([\d.]+)/.exec(ua) || 0)[1]);
726 | }
727 | // Detect IE 11 identifying as other browsers.
728 | else if (name != 'IE' && layout == 'Trident' && (data = /\brv:([\d.]+)/.exec(ua))) {
729 | if (name) {
730 | description.push('identifying as ' + name + (version ? ' ' + version : ''));
731 | }
732 | name = 'IE';
733 | version = data[1];
734 | }
735 | // Leverage environment features.
736 | if (useFeatures) {
737 | // Detect server-side environments.
738 | // Rhino has a global function while others have a global object.
739 | if (isHostType(context, 'global')) {
740 | if (java) {
741 | data = java.lang.System;
742 | arch = data.getProperty('os.arch');
743 | os = os || data.getProperty('os.name') + ' ' + data.getProperty('os.version');
744 | }
745 | if (rhino) {
746 | try {
747 | version = context.require('ringo/engine').version.join('.');
748 | name = 'RingoJS';
749 | } catch(e) {
750 | if ((data = context.system) && data.global.system == context.system) {
751 | name = 'Narwhal';
752 | os || (os = data[0].os || null);
753 | }
754 | }
755 | if (!name) {
756 | name = 'Rhino';
757 | }
758 | }
759 | else if (
760 | typeof context.process == 'object' && !context.process.browser &&
761 | (data = context.process)
762 | ) {
763 | if (typeof data.versions == 'object') {
764 | if (typeof data.versions.electron == 'string') {
765 | description.push('Node ' + data.versions.node);
766 | name = 'Electron';
767 | version = data.versions.electron;
768 | } else if (typeof data.versions.nw == 'string') {
769 | description.push('Chromium ' + version, 'Node ' + data.versions.node);
770 | name = 'NW.js';
771 | version = data.versions.nw;
772 | }
773 | }
774 | if (!name) {
775 | name = 'Node.js';
776 | arch = data.arch;
777 | os = data.platform;
778 | version = /[\d.]+/.exec(data.version);
779 | version = version ? version[0] : null;
780 | }
781 | }
782 | }
783 | // Detect Adobe AIR.
784 | else if (getClassOf((data = context.runtime)) == airRuntimeClass) {
785 | name = 'Adobe AIR';
786 | os = data.flash.system.Capabilities.os;
787 | }
788 | // Detect PhantomJS.
789 | else if (getClassOf((data = context.phantom)) == phantomClass) {
790 | name = 'PhantomJS';
791 | version = (data = data.version || null) && (data.major + '.' + data.minor + '.' + data.patch);
792 | }
793 | // Detect IE compatibility modes.
794 | else if (typeof doc.documentMode == 'number' && (data = /\bTrident\/(\d+)/i.exec(ua))) {
795 | // We're in compatibility mode when the Trident version + 4 doesn't
796 | // equal the document mode.
797 | version = [version, doc.documentMode];
798 | if ((data = +data[1] + 4) != version[1]) {
799 | description.push('IE ' + version[1] + ' mode');
800 | layout && (layout[1] = '');
801 | version[1] = data;
802 | }
803 | version = name == 'IE' ? String(version[1].toFixed(1)) : version[0];
804 | }
805 | // Detect IE 11 masking as other browsers.
806 | else if (typeof doc.documentMode == 'number' && /^(?:Chrome|Firefox)\b/.test(name)) {
807 | description.push('masking as ' + name + ' ' + version);
808 | name = 'IE';
809 | version = '11.0';
810 | layout = ['Trident'];
811 | os = 'Windows';
812 | }
813 | os = os && format(os);
814 | }
815 | // Detect prerelease phases.
816 | if (version && (data =
817 | /(?:[ab]|dp|pre|[ab]\d+pre)(?:\d+\+?)?$/i.exec(version) ||
818 | /(?:alpha|beta)(?: ?\d)?/i.exec(ua + ';' + (useFeatures && nav.appMinorVersion)) ||
819 | /\bMinefield\b/i.test(ua) && 'a'
820 | )) {
821 | prerelease = /b/i.test(data) ? 'beta' : 'alpha';
822 | version = version.replace(RegExp(data + '\\+?$'), '') +
823 | (prerelease == 'beta' ? beta : alpha) + (/\d+\+?/.exec(data) || '');
824 | }
825 | // Detect Firefox Mobile.
826 | if (name == 'Fennec' || name == 'Firefox' && /\b(?:Android|Firefox OS)\b/.test(os)) {
827 | name = 'Firefox Mobile';
828 | }
829 | // Obscure Maxthon's unreliable version.
830 | else if (name == 'Maxthon' && version) {
831 | version = version.replace(/\.[\d.]+/, '.x');
832 | }
833 | // Detect Xbox 360 and Xbox One.
834 | else if (/\bXbox\b/i.test(product)) {
835 | if (product == 'Xbox 360') {
836 | os = null;
837 | }
838 | if (product == 'Xbox 360' && /\bIEMobile\b/.test(ua)) {
839 | description.unshift('mobile mode');
840 | }
841 | }
842 | // Add mobile postfix.
843 | else if ((/^(?:Chrome|IE|Opera)$/.test(name) || name && !product && !/Browser|Mobi/.test(name)) &&
844 | (os == 'Windows CE' || /Mobi/i.test(ua))) {
845 | name += ' Mobile';
846 | }
847 | // Detect IE platform preview.
848 | else if (name == 'IE' && useFeatures) {
849 | try {
850 | if (context.external === null) {
851 | description.unshift('platform preview');
852 | }
853 | } catch(e) {
854 | description.unshift('embedded');
855 | }
856 | }
857 | // Detect BlackBerry OS version.
858 | // http://docs.blackberry.com/en/developers/deliverables/18169/HTTP_headers_sent_by_BB_Browser_1234911_11.jsp
859 | else if ((/\bBlackBerry\b/.test(product) || /\bBB10\b/.test(ua)) && (data =
860 | (RegExp(product.replace(/ +/g, ' *') + '/([.\\d]+)', 'i').exec(ua) || 0)[1] ||
861 | version
862 | )) {
863 | data = [data, /BB10/.test(ua)];
864 | os = (data[1] ? (product = null, manufacturer = 'BlackBerry') : 'Device Software') + ' ' + data[0];
865 | version = null;
866 | }
867 | // Detect Opera identifying/masking itself as another browser.
868 | // http://www.opera.com/support/kb/view/843/
869 | else if (this != forOwn && product != 'Wii' && (
870 | (useFeatures && opera) ||
871 | (/Opera/.test(name) && /\b(?:MSIE|Firefox)\b/i.test(ua)) ||
872 | (name == 'Firefox' && /\bOS X (?:\d+\.){2,}/.test(os)) ||
873 | (name == 'IE' && (
874 | (os && !/^Win/.test(os) && version > 5.5) ||
875 | /\bWindows XP\b/.test(os) && version > 8 ||
876 | version == 8 && !/\bTrident\b/.test(ua)
877 | ))
878 | ) && !reOpera.test((data = parse.call(forOwn, ua.replace(reOpera, '') + ';'))) && data.name) {
879 | // When "identifying", the UA contains both Opera and the other browser's name.
880 | data = 'ing as ' + data.name + ((data = data.version) ? ' ' + data : '');
881 | if (reOpera.test(name)) {
882 | if (/\bIE\b/.test(data) && os == 'Mac OS') {
883 | os = null;
884 | }
885 | data = 'identify' + data;
886 | }
887 | // When "masking", the UA contains only the other browser's name.
888 | else {
889 | data = 'mask' + data;
890 | if (operaClass) {
891 | name = format(operaClass.replace(/([a-z])([A-Z])/g, '$1 $2'));
892 | } else {
893 | name = 'Opera';
894 | }
895 | if (/\bIE\b/.test(data)) {
896 | os = null;
897 | }
898 | if (!useFeatures) {
899 | version = null;
900 | }
901 | }
902 | layout = ['Presto'];
903 | description.push(data);
904 | }
905 | // Detect WebKit Nightly and approximate Chrome/Safari versions.
906 | if ((data = (/\bAppleWebKit\/([\d.]+\+?)/i.exec(ua) || 0)[1])) {
907 | // Correct build number for numeric comparison.
908 | // (e.g. "532.5" becomes "532.05")
909 | data = [parseFloat(data.replace(/\.(\d)$/, '.0$1')), data];
910 | // Nightly builds are postfixed with a "+".
911 | if (name == 'Safari' && data[1].slice(-1) == '+') {
912 | name = 'WebKit Nightly';
913 | prerelease = 'alpha';
914 | version = data[1].slice(0, -1);
915 | }
916 | // Clear incorrect browser versions.
917 | else if (version == data[1] ||
918 | version == (data[2] = (/\bSafari\/([\d.]+\+?)/i.exec(ua) || 0)[1])) {
919 | version = null;
920 | }
921 | // Use the full Chrome version when available.
922 | data[1] = (/\bChrome\/([\d.]+)/i.exec(ua) || 0)[1];
923 | // Detect Blink layout engine.
924 | if (data[0] == 537.36 && data[2] == 537.36 && parseFloat(data[1]) >= 28 && layout == 'WebKit') {
925 | layout = ['Blink'];
926 | }
927 | // Detect JavaScriptCore.
928 | // http://stackoverflow.com/questions/6768474/how-can-i-detect-which-javascript-engine-v8-or-jsc-is-used-at-runtime-in-androi
929 | if (!useFeatures || (!likeChrome && !data[1])) {
930 | layout && (layout[1] = 'like Safari');
931 | data = (data = data[0], data < 400 ? 1 : data < 500 ? 2 : data < 526 ? 3 : data < 533 ? 4 : data < 534 ? '4+' : data < 535 ? 5 : data < 537 ? 6 : data < 538 ? 7 : data < 601 ? 8 : '8');
932 | } else {
933 | layout && (layout[1] = 'like Chrome');
934 | data = data[1] || (data = data[0], data < 530 ? 1 : data < 532 ? 2 : data < 532.05 ? 3 : data < 533 ? 4 : data < 534.03 ? 5 : data < 534.07 ? 6 : data < 534.10 ? 7 : data < 534.13 ? 8 : data < 534.16 ? 9 : data < 534.24 ? 10 : data < 534.30 ? 11 : data < 535.01 ? 12 : data < 535.02 ? '13+' : data < 535.07 ? 15 : data < 535.11 ? 16 : data < 535.19 ? 17 : data < 536.05 ? 18 : data < 536.10 ? 19 : data < 537.01 ? 20 : data < 537.11 ? '21+' : data < 537.13 ? 23 : data < 537.18 ? 24 : data < 537.24 ? 25 : data < 537.36 ? 26 : layout != 'Blink' ? '27' : '28');
935 | }
936 | // Add the postfix of ".x" or "+" for approximate versions.
937 | layout && (layout[1] += ' ' + (data += typeof data == 'number' ? '.x' : /[.+]/.test(data) ? '' : '+'));
938 | // Obscure version for some Safari 1-2 releases.
939 | if (name == 'Safari' && (!version || parseInt(version) > 45)) {
940 | version = data;
941 | }
942 | }
943 | // Detect Opera desktop modes.
944 | if (name == 'Opera' && (data = /\bzbov|zvav$/.exec(os))) {
945 | name += ' ';
946 | description.unshift('desktop mode');
947 | if (data == 'zvav') {
948 | name += 'Mini';
949 | version = null;
950 | } else {
951 | name += 'Mobile';
952 | }
953 | os = os.replace(RegExp(' *' + data + '$'), '');
954 | }
955 | // Detect Chrome desktop mode.
956 | else if (name == 'Safari' && /\bChrome\b/.exec(layout && layout[1])) {
957 | description.unshift('desktop mode');
958 | name = 'Chrome Mobile';
959 | version = null;
960 |
961 | if (/\bOS X\b/.test(os)) {
962 | manufacturer = 'Apple';
963 | os = 'iOS 4.3+';
964 | } else {
965 | os = null;
966 | }
967 | }
968 | // Strip incorrect OS versions.
969 | if (version && version.indexOf((data = /[\d.]+$/.exec(os))) == 0 &&
970 | ua.indexOf('/' + data + '-') > -1) {
971 | os = trim(os.replace(data, ''));
972 | }
973 | // Add layout engine.
974 | if (layout && !/\b(?:Avant|Nook)\b/.test(name) && (
975 | /Browser|Lunascape|Maxthon/.test(name) ||
976 | name != 'Safari' && /^iOS/.test(os) && /\bSafari\b/.test(layout[1]) ||
977 | /^(?:Adobe|Arora|Breach|Midori|Opera|Phantom|Rekonq|Rock|Samsung Internet|Sleipnir|Web)/.test(name) && layout[1])) {
978 | // Don't add layout details to description if they are falsey.
979 | (data = layout[layout.length - 1]) && description.push(data);
980 | }
981 | // Combine contextual information.
982 | if (description.length) {
983 | description = ['(' + description.join('; ') + ')'];
984 | }
985 | // Append manufacturer to description.
986 | if (manufacturer && product && product.indexOf(manufacturer) < 0) {
987 | description.push('on ' + manufacturer);
988 | }
989 | // Append product to description.
990 | if (product) {
991 | description.push((/^on /.test(description[description.length - 1]) ? '' : 'on ') + product);
992 | }
993 | // Parse the OS into an object.
994 | if (os) {
995 | data = / ([\d.+]+)$/.exec(os);
996 | isSpecialCasedOS = data && os.charAt(os.length - data[0].length - 1) == '/';
997 | os = {
998 | 'architecture': 32,
999 | 'family': (data && !isSpecialCasedOS) ? os.replace(data[0], '') : os,
1000 | 'version': data ? data[1] : null,
1001 | 'toString': function() {
1002 | var version = this.version;
1003 | return this.family + ((version && !isSpecialCasedOS) ? ' ' + version : '') + (this.architecture == 64 ? ' 64-bit' : '');
1004 | }
1005 | };
1006 | }
1007 | // Add browser/OS architecture.
1008 | if ((data = /\b(?:AMD|IA|Win|WOW|x86_|x)64\b/i.exec(arch)) && !/\bi686\b/i.test(arch)) {
1009 | if (os) {
1010 | os.architecture = 64;
1011 | os.family = os.family.replace(RegExp(' *' + data), '');
1012 | }
1013 | if (
1014 | name && (/\bWOW64\b/i.test(ua) ||
1015 | (useFeatures && /\w(?:86|32)$/.test(nav.cpuClass || nav.platform) && !/\bWin64; x64\b/i.test(ua)))
1016 | ) {
1017 | description.unshift('32-bit');
1018 | }
1019 | }
1020 | // Chrome 39 and above on OS X is always 64-bit.
1021 | else if (
1022 | os && /^OS X/.test(os.family) &&
1023 | name == 'Chrome' && parseFloat(version) >= 39
1024 | ) {
1025 | os.architecture = 64;
1026 | }
1027 |
1028 | ua || (ua = null);
1029 |
1030 | /*------------------------------------------------------------------------*/
1031 |
1032 | /**
1033 | * The platform object.
1034 | *
1035 | * @name platform
1036 | * @type Object
1037 | */
1038 | var platform = {};
1039 |
1040 | /**
1041 | * The platform description.
1042 | *
1043 | * @memberOf platform
1044 | * @type string|null
1045 | */
1046 | platform.description = ua;
1047 |
1048 | /**
1049 | * The name of the browser's layout engine.
1050 | *
1051 | * The list of common layout engines include:
1052 | * "Blink", "EdgeHTML", "Gecko", "Trident" and "WebKit"
1053 | *
1054 | * @memberOf platform
1055 | * @type string|null
1056 | */
1057 | platform.layout = layout && layout[0];
1058 |
1059 | /**
1060 | * The name of the product's manufacturer.
1061 | *
1062 | * The list of manufacturers include:
1063 | * "Apple", "Archos", "Amazon", "Asus", "Barnes & Noble", "BlackBerry",
1064 | * "Google", "HP", "HTC", "LG", "Microsoft", "Motorola", "Nintendo",
1065 | * "Nokia", "Samsung" and "Sony"
1066 | *
1067 | * @memberOf platform
1068 | * @type string|null
1069 | */
1070 | platform.manufacturer = manufacturer;
1071 |
1072 | /**
1073 | * The name of the browser/environment.
1074 | *
1075 | * The list of common browser names include:
1076 | * "Chrome", "Electron", "Firefox", "Firefox for iOS", "IE",
1077 | * "Microsoft Edge", "PhantomJS", "Safari", "SeaMonkey", "Silk",
1078 | * "Opera Mini" and "Opera"
1079 | *
1080 | * Mobile versions of some browsers have "Mobile" appended to their name:
1081 | * eg. "Chrome Mobile", "Firefox Mobile", "IE Mobile" and "Opera Mobile"
1082 | *
1083 | * @memberOf platform
1084 | * @type string|null
1085 | */
1086 | platform.name = name;
1087 |
1088 | /**
1089 | * The alpha/beta release indicator.
1090 | *
1091 | * @memberOf platform
1092 | * @type string|null
1093 | */
1094 | platform.prerelease = prerelease;
1095 |
1096 | /**
1097 | * The name of the product hosting the browser.
1098 | *
1099 | * The list of common products include:
1100 | *
1101 | * "BlackBerry", "Galaxy S4", "Lumia", "iPad", "iPod", "iPhone", "Kindle",
1102 | * "Kindle Fire", "Nexus", "Nook", "PlayBook", "TouchPad" and "Transformer"
1103 | *
1104 | * @memberOf platform
1105 | * @type string|null
1106 | */
1107 | platform.product = product;
1108 |
1109 | /**
1110 | * The browser's user agent string.
1111 | *
1112 | * @memberOf platform
1113 | * @type string|null
1114 | */
1115 | platform.ua = ua;
1116 |
1117 | /**
1118 | * The browser/environment version.
1119 | *
1120 | * @memberOf platform
1121 | * @type string|null
1122 | */
1123 | platform.version = name && version;
1124 |
1125 | /**
1126 | * The name of the operating system.
1127 | *
1128 | * @memberOf platform
1129 | * @type Object
1130 | */
1131 | platform.os = os || {
1132 |
1133 | /**
1134 | * The CPU architecture the OS is built for.
1135 | *
1136 | * @memberOf platform.os
1137 | * @type number|null
1138 | */
1139 | 'architecture': null,
1140 |
1141 | /**
1142 | * The family of the OS.
1143 | *
1144 | * Common values include:
1145 | * "Windows", "Windows Server 2008 R2 / 7", "Windows Server 2008 / Vista",
1146 | * "Windows XP", "OS X", "Ubuntu", "Debian", "Fedora", "Red Hat", "SuSE",
1147 | * "Android", "iOS" and "Windows Phone"
1148 | *
1149 | * @memberOf platform.os
1150 | * @type string|null
1151 | */
1152 | 'family': null,
1153 |
1154 | /**
1155 | * The version of the OS.
1156 | *
1157 | * @memberOf platform.os
1158 | * @type string|null
1159 | */
1160 | 'version': null,
1161 |
1162 | /**
1163 | * Returns the OS string.
1164 | *
1165 | * @memberOf platform.os
1166 | * @returns {string} The OS string.
1167 | */
1168 | 'toString': function() { return 'null'; }
1169 | };
1170 |
1171 | platform.parse = parse;
1172 | platform.toString = toStringPlatform;
1173 |
1174 | if (platform.version) {
1175 | description.unshift(version);
1176 | }
1177 | if (platform.name) {
1178 | description.unshift(name);
1179 | }
1180 | if (os && name && !(os == String(os).split(' ')[0] && (os == name.split(' ')[0] || product))) {
1181 | description.push(product ? '(' + os + ')' : 'on ' + os);
1182 | }
1183 | if (description.length) {
1184 | platform.description = description.join(' ');
1185 | }
1186 | return platform;
1187 | }
1188 |
1189 | /*--------------------------------------------------------------------------*/
1190 |
1191 | // Export platform.
1192 | var platform = parse();
1193 |
1194 | // Some AMD build optimizers, like r.js, check for condition patterns like the following:
1195 | if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
1196 | // Expose platform on the global object to prevent errors when platform is
1197 | // loaded by a script tag in the presence of an AMD loader.
1198 | // See http://requirejs.org/docs/errors.html#mismatch for more details.
1199 | root.platform = platform;
1200 |
1201 | // Define as an anonymous module so platform can be aliased through path mapping.
1202 | define(function() {
1203 | return platform;
1204 | });
1205 | }
1206 | // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
1207 | else if (freeExports && freeModule) {
1208 | // Export for CommonJS support.
1209 | forOwn(platform, function(value, key) {
1210 | freeExports[key] = value;
1211 | });
1212 | }
1213 | else {
1214 | // Export to the global object.
1215 | root.platform = platform;
1216 | }
1217 | }.call(this));
1218 |
--------------------------------------------------------------------------------
/scripts/src/bg.js:
--------------------------------------------------------------------------------
1 | chrome.browserAction.onClicked.addListener(() => {
2 | chrome.windows.getLastFocused({populate: true}, window => {
3 | chrome.tabs.create({url: 'tabPage.html', windowId: window.id});
4 | });
5 | });
6 |
--------------------------------------------------------------------------------
/scripts/src/listeners.js:
--------------------------------------------------------------------------------
1 | function addListeners(tabManager) {
2 | // shortcuts
3 | $(document).bind('keyup', function(e) {
4 | if (e.target.id != 'search-input') {
5 | var key = e.which || e.keyCode;
6 | key = String.fromCharCode(key);
7 | let shortcuts = {
8 | 'U': 'undo',
9 | 'S': 'toggleSettings',
10 | 'A': 'arrangeTabs',
11 | '&': 'selectWindowPrev',
12 | '(': 'selectWindowNext',
13 | '0': 'selectWindowAll'
14 | };
15 |
16 | let next = 1;
17 | let command = parseInt(key) || shortcuts[key];
18 | if (typeof command == 'number') {
19 | $('#win-btn-' + command).click();
20 | } else {
21 | switch (command) {
22 | case 'undo':
23 | tabManager.reopenLastClosed();
24 | break;
25 | case 'toggleSettings':
26 | toggleSettings();
27 | break;
28 | case 'arrangeTabs':
29 | arrangeTabs();
30 | break;
31 | case 'selectWindowPrev':
32 | next -= 2; // Wow, very hack
33 | case 'selectWindowNext':
34 | let currentWindowNumber = $('.window-select-active')[0].id.replace('win-btn-', '');
35 | currentWindowNumber = parseInt(currentWindowNumber);
36 | let targetWindow = currentWindowNumber + next;
37 | $('#win-btn-' + targetWindow).click();
38 | break;
39 | case 'selectWindowAll':
40 | $('#win-btn-all').click();
41 | break;
42 | }
43 | }
44 | }
45 | });
46 |
47 | // Add listener for updating tabs
48 | chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
49 | if (tabManager.managerTab) {
50 | if (tabManager.managerTab.url == tab.url && Object.keys(changeInfo).length > 1 && changeInfo['status'] == 'loading') {
51 | chrome.tabs.remove(tabManager.managerTab.id);
52 | }
53 | }
54 |
55 | if (changeInfo['url']) {
56 | tabManager.reloadPage();
57 | } else if (changeInfo['title']) {
58 | $('#t-' + tab.id).empty();
59 | $('#t-' + tab.id).append(renderTabContent(tab));
60 | }
61 | });
62 |
63 | // Add listner for tabs being removed
64 | chrome.tabs.onRemoved.addListener((tabID, removedInfo) => {
65 | let tab;
66 | // If the manager tab is the last tab in all windows, close
67 | if (tabManager.windows.length == 1 && tabManager.windows[0].tabs.length <= 2 && tabManager.windows[0].tabs[0].id === tabManager.managerTab.id) {
68 | tabManager.close();
69 | }
70 | // Add the closed tab to closed tab list
71 | for (openTab of tabManager.openTabs) {
72 | if (openTab.id == tabID) {
73 | tab = openTab;
74 | tabManager.tryAddToClosedElements(openTab);
75 | }
76 | }
77 | if (!tab.isGroup)
78 | tabManager.reloadPage();
79 | });
80 |
81 | // Add listner for creating tabs
82 | chrome.tabs.onCreated.addListener((tab) => {
83 | tabManager.reloadPage();
84 | });
85 |
86 | // Add listener for window closing
87 | chrome.windows.onRemoved.addListener(() => {
88 | tabManager.reloadPage();
89 | });
90 |
91 | // Add listener for undo button
92 | $("#undo-btn").on('click', () => {
93 | tabManager.reopenLastClosed();
94 | });
95 |
96 | // Add listener for settings button
97 | $('#settings-icon').on('click', () => {
98 | toggleSettings();
99 | });
100 |
101 | // Add listener for tab count settings
102 |
103 | tabManager.addGenericSettingsCallbacks();
104 |
105 | // Add listener for layout options
106 | $(".layout-option").each(function() {
107 | $(this).on('click', function(e) {
108 | // Remove active class from all buttons
109 | $(".layout-option-active").each(function() {
110 | $(this).toggleClass('layout-option-active layout-option');
111 | });
112 | // Add active class to the button that was pressed
113 | $(this).toggleClass('layout-option-active layout-option');
114 | chrome.storage.local.set({
115 | 'col': 12 / e.target.id
116 | });
117 | tabManager.reloadPage();
118 | });
119 | });
120 |
121 | // Add listener for sort options
122 | $(".sort-option").each(function() {
123 | $(this).on('click', () => {
124 | chrome.storage.local.set({
125 | 'sortMethod': $(this).attr('id')
126 | });
127 | tabManager.reloadPage();
128 | });
129 | });
130 |
131 | // Add listener for search options
132 | $(".search-option").each(function() {
133 | $(this).on('click', () => {
134 | chrome.storage.local.set({
135 | 'searchScope': $(this).attr('id')
136 | });
137 | tabManager.reloadPage();
138 | });
139 | });
140 |
141 | $('#shortcut-btn').on('click', () => {
142 | $('.modal-bg').empty();
143 | $('.modal-bg').append(``);
144 | $('.shortcut-settings-modal').append(renderShortcutModal());
145 | $('.modal-bg').show();
146 | });
147 |
148 | // Add listener for arrange tabs button
149 | $("#arrange-tabs-btn").on('click', () => {
150 | arrangeTabs();
151 | });
152 |
153 | // Add listener for restore tabs button
154 | $("#restore-tabs-btn").on('click', () => {
155 | $('.modal-bg').empty();
156 | $('.modal-bg').append(``);
157 | $('.view-closed-tabs').append(renderRestoreTabModal(tabManager.closedElements));
158 | addRestoreTabModalListeners(tabManager);
159 | $('.modal-bg').show();
160 | });
161 |
162 | // Add listener for restore defaults button
163 | $("#restore-Btn").on('click', () => {
164 | chrome.storage.local.set(defaultSettings);
165 | tabManager.reloadPage();
166 | });
167 | }
168 |
169 | function addTabListeners(tab, tabManager) {
170 | // Add event listener to tab
171 | $('#t-' + tab.id + ' .tab').on('click', () => {
172 | chrome.windows.update(tab.windowId, {
173 | focused: true
174 | });
175 |
176 | let updateProperties;
177 | if (platform.name == "Firefox") {
178 | updateProperties = {
179 | active: true
180 | };
181 | } else {
182 | updateProperties = {
183 | highlighted: true
184 | };
185 | }
186 |
187 | chrome.tabs.update(tab.id, updateProperties);
188 | tabManager.onTabClicked();
189 |
190 | });
191 |
192 | addTabOptionListeners(tab, tabManager);
193 | // Add event listener for close button
194 | $('#t-' + tab.id + ' .close-tab-btn').on('click', () => {
195 | // Close the selected tab
196 | chrome.tabs.remove(tab.id);
197 | });
198 | }
199 |
200 | function addTabOptionListeners(tab, tabManager) {
201 | // Add event listener for tab options button
202 | $('#t-' + tab.id + ' .tab-options-btn').on('click', () => {
203 | $('#t-' + tab.id + ' .dropdown-content').show();
204 | }).children().click(() => {
205 | return false;
206 | });
207 |
208 | // Close dropdown on mouse leave
209 | $('#t-' + tab.id + ' .dropdown-content').on('mouseleave', () => {
210 | $('#t-' + tab.id + ' .dropdown-content').hide();
211 | });
212 |
213 | // Add event listener for reload button
214 | $('#t-' + tab.id + ' #t-reload').on('click', () => {
215 | chrome.tabs.reload(tab.id);
216 | $('#t-' + tab.id + ' .dropdown-content').hide();
217 | });
218 |
219 | // Add event listener for copy url button
220 | $('#t-' + tab.id + ' #copy').on('click', () => {
221 | copyStringToClipboard(tab.url.href);
222 | $('#t-' + tab.id + ' .dropdown-content').hide();
223 | });
224 |
225 | // Add event listener for merge to window button
226 | $('#t-' + tab.id + ' #merge').on('click', () => {
227 | $('.modal-bg').empty();
228 | $('.modal-bg').append(``);
229 | $('.select-win-dest').append(renderSendTabModal(tabManager.windows));
230 | addSendTabModalListeners(tab, tabManager.windows);
231 | $('.modal-bg').show();
232 | });
233 | }
234 |
235 | function addTabGroupOptionListeners(tabGroup, tabManager) {
236 | // Add event listener for tab options button
237 | $('#tg-' + tabGroup.id + ' .tab-group-options-btn').on('click', () => {
238 | $('#tg-' + tabGroup.id + ' .dropdown-content').show();
239 | }).children().click(() => {
240 | return false;
241 | });;
242 |
243 | // Close dropdown on mouse leave
244 | $('#tg-' + tabGroup.id + ' .dropdown-content').on('mouseleave', () => {
245 | $('#tg-' + tabGroup.id + ' .dropdown-content').hide();
246 | });
247 |
248 | // Add event listener for reload button
249 | $('#tg-' + tabGroup.id + ' #tg-reload').on('click', () => {
250 | for (tab of tabGroup.tabs) {
251 | chrome.tabs.reload(tab.id);
252 | }
253 | $('#tg-' + tabGroup.id + ' .dropdown-content').hide();
254 | });
255 |
256 | // Add event listener for merge to window button
257 | $('#tg-' + tabGroup.id + ' #merge').on('click', () => {
258 | $('.modal-bg').empty();
259 | $('.modal-bg').append(``);
260 | $('.select-win-dest').append(renderSendTabModal(tabManager.windows));
261 | $('.modal-bg').show();
262 |
263 | addSendTabModalListeners(tabGroup, tabManager.windows);
264 | });
265 | }
266 |
267 | function addWindowOptionListeners(win, tabManager) {
268 | // Add event listener for tab options button
269 | $('#windowWithTabGroups-' + win.id + ' .win-options-btn').on('click', () => {
270 | $('#windowWithTabGroups-' + win.id + ' .dropdown-content').show();
271 | }).children().click(() => {
272 | return false;
273 | });
274 |
275 | // Close dropdown on mouse leave
276 | $('#windowWithTabGroups-' + win.id + ' .dropdown-content').on('mouseleave', () => {
277 | $('#windowWithTabGroups-' + win.id + ' .dropdown-content').hide();
278 | });
279 |
280 | // Add event listener for reload button
281 | $('#windowWithTabGroups-' + win.id + ' #w-reload').on('click', () => {
282 | for (tab of win.tabs) {
283 | chrome.tabs.reload(tab.id);
284 | }
285 | $('#windowWithTabGroups-' + win.id + ' .dropdown-content').hide();
286 | });
287 |
288 | // Add event listener for merge to window button
289 | $('#windowWithTabGroups-' + win.id + ' #merge').on('click', () => {
290 | $('.modal-bg').empty();
291 | $('.modal-bg').append(``);
292 | $('.select-win-dest').append(renderSendTabModal(tabManager.windows));
293 | $('.modal-bg').show();
294 |
295 | addSendTabModalListeners(win, tabManager.windows);
296 | });
297 | }
298 |
299 | function addSendTabModalListeners(element, windows) {
300 |
301 | $('#st-new').off();
302 | $('#st-new').on('click', () => {
303 |
304 | if (element instanceof TabGroup || windows.includes(element)) {
305 | chrome.windows.create({
306 | tabId: element.tabs[0].id
307 | }, (win) => {
308 | for (tab of element.tabs) {
309 | if (tab != element.tabs[0]) {
310 | chrome.tabs.move(tab.id, {
311 | windowId: parseInt(win.id),
312 | index: -1
313 | });
314 | }
315 | }
316 | });
317 | } else { //is tab
318 | chrome.windows.create({
319 | tabId: element.id
320 | });
321 | }
322 | tabManager.reloadPage();
323 | });
324 |
325 | for (win of windows) {
326 | $('#st-' + win.id).off();
327 | $('#st-' + win.id).on('click', function() {
328 |
329 | if (element instanceof TabGroup || windows.includes(element)) {
330 | for (tab of element.tabs) {
331 | chrome.tabs.move(tab.id, {
332 | windowId: parseInt(this.id.split('-')[1]),
333 | index: -1
334 | });
335 | }
336 | } else { //is tab
337 | chrome.tabs.move(element.id, {
338 | windowId: parseInt(this.id.split('-')[1]),
339 | index: -1
340 | });
341 | }
342 | tabManager.reloadPage();
343 | });
344 | }
345 | }
346 |
347 | function addRestoreTabModalListeners(tabManager) {
348 |
349 | function restore(clicked, tabManager) {
350 | let id = clicked.id.substring(1).split('-')[1];
351 | for (let element of tabManager.closedElements) {
352 | if (element instanceof TabGroup) {
353 | if (String(element.id) == id){
354 | tabManager.closedElements = _.without(tabManager.closedElements, _.findWhere(tabManager.closedElements, element));
355 | tabManager.reopenTabGroup(element);
356 | }
357 | } else if (element.type !== undefined) { //isWindow
358 | if (String(element.id) == id){
359 | tabManager.closedElements = _.without(tabManager.closedElements, _.findWhere(tabManager.closedElements, element));
360 | for (tab of element.tabs){
361 | tab.url = tab.url.href;
362 | }
363 | tabManager.reopenWindow(element);
364 | }
365 | } else { // isTab
366 | if (String(element.id) == id){
367 | tabManager.closedElements = _.without(tabManager.closedElements, _.findWhere(tabManager.closedElements, element));
368 | tabManager.reopenTab(element);
369 | }
370 | }
371 | }
372 | }
373 | $('.closed-win').on('click', function() {
374 | restore(this, tabManager);
375 | });
376 |
377 | $('.closed-tg').on('click', function() {
378 | restore(this, tabManager);
379 | });
380 |
381 | $('.closed-t').on('click', function() {
382 | restore(this, tabManager);
383 | });
384 | }
385 |
386 | function addTabGroupListeners(tabGroup, tabManager) {
387 | $('#tg-' + tabGroup.id + ' .closeGroupBtn').on('click', () => {
388 | for (let i = 0; i < tabGroup.tabs.length; i++) {
389 | if (i != tabGroup.tabs.length - 1)
390 | tabGroup.tabs[i].isGroup = true;
391 | chrome.tabs.remove(tabGroup.tabs[i].id);
392 | }
393 | $(tabGroup.hostname).remove();
394 | tabManager.closedElements = _.difference(tabManager.closedElements, tabGroup.tabs);
395 | tabManager.closedElements.push(tabGroup);
396 | });
397 | addTabGroupOptionListeners(tabGroup, tabManager);
398 | }
399 |
400 | function addWinListeners(win, tabManager) {
401 | $('#windowWithTabGroups-' + win.id + ' .closeWindowBtn').on('click', () => {
402 | tabManager.closedElements = _.difference(tabManager.closedElements, win.tabs);
403 | tabManager.closedElements.push(win);
404 | chrome.windows.remove(win.id);
405 | });
406 |
407 | $('.closeAllBtn').off();
408 | $('.closeAllBtn').on('click', function() {
409 | if (confirm("Are you sure you want to close all windows?")) {
410 | for (win of tabManager.windows) {
411 | chrome.windows.remove(win.id);
412 | }
413 | }
414 | });
415 | addWindowOptionListeners(win, tabManager);
416 | }
417 |
418 | function addModalListeners() {
419 | let selectWinDestBg = $('.modal-bg');
420 | $('.modal-bg').on('click', function() {
421 | $('.modal-bg').hide();
422 | });
423 | $('#modal-close').on('click', () => {
424 | $('.modal-bg').hide();
425 | });
426 | }
427 |
428 | function addTabManagerListeners(tabManager) {
429 | // Prevent duplicate listeners
430 | $('#win-btn-all').off();
431 | // Add listeners for window select buttons
432 | for ($winBtn of $(".win-btn")) {
433 | let btnID = $winBtn.id.split('-')[2];
434 | $('#win-btn-' + btnID).on('click', () => {
435 | chrome.storage.local.set({
436 | 'winSrc': btnID
437 | });
438 | if (tabManager.settings['classicMode']) {
439 | $("#search-input").val('');
440 | tabManager.reloadPage();
441 | } else {
442 | tabManager.settings['winSrc'] = btnID;
443 | tabManager.getSortedTabGroups();
444 | tabManager.renderHTMLContent();
445 | addTabManagerListeners(tabManager);
446 | if (btnID == 'all') {
447 | $('.window-overflow-container').animate({
448 | scrollTop: 0
449 | }, 0);
450 | } else {
451 | document.querySelector("#windowWithTabGroups-" + tabManager.windows[btnID - 1].id).scrollIntoView({
452 | behavior: 'smooth',
453 | block: 'start'
454 | });
455 | let $targetWindow = $('#windowWithTabGroups-' + tabManager.windows[btnID - 1].id);
456 | $targetWindow
457 | .addClass('selected-window', 250)
458 | .delay(350)
459 | .removeClass('selected-window', 500);
460 | }
461 | }
462 | });
463 | }
464 |
465 | // Add listeners for windows
466 | tabManager.windows.forEach((win) => {
467 | addWinListeners(win, tabManager);
468 | });
469 |
470 | // Add listeners for tabGroups and tabs
471 | for (tabGroup of tabManager.tabGroups) {
472 | addTabGroupListeners(tabGroup, tabManager);
473 | tabGroup.tabs.forEach((tab) => addTabListeners(tab, tabManager));
474 | }
475 |
476 | // Add listeners for addModalListeners
477 | addModalListeners();
478 |
479 | // Add listener for seach bar
480 | $("#search-input").off();
481 | $("#search-input").keyup(function() {
482 | tabManager.getSortedTabGroups();
483 | tabManager.renderHTMLContent();
484 | addTabManagerListeners(tabManager);
485 | });
486 |
487 | // Add listener for scrolling
488 | $(".window-overflow-container").on("scroll", function(event) {
489 | if (tabManager.settings['winSrc'] != 'all') {
490 | var scrollPos = $(".window-overflow-container").offset().top;
491 | let i = 1;
492 | for ($win of $(".window")) {
493 | var currLink = $('#win-btn-' + i);
494 | var refElement = $('#' + $win.id);
495 | if (refElement.offset().top <= scrollPos + 10 && refElement.offset().top + refElement.height() > scrollPos - 100) {
496 | $('.win-btn').removeClass("window-select-active");
497 | currLink.addClass("window-select-active");
498 | chrome.storage.local.set({
499 | 'winSrc': i
500 | });
501 | } else {
502 | currLink.removeClass("window-select-active");
503 | currLink.addClass("window-select-btn");
504 | }
505 | i++;
506 | }
507 | }
508 | });
509 | }
510 |
511 | function arrangeTabs() {
512 | tabManager.windows.forEach((win) => {
513 | arrangeWindowTabs(win);
514 | });
515 | }
516 |
517 | function toggleSettings() {
518 | let settingsWidth = "192px";
519 | if ($('.settings').css('width') != settingsWidth) {
520 | $('.main-content').css({
521 | 'margin-left': settingsWidth
522 | });
523 | $('.settings').css({
524 | 'width': settingsWidth
525 | });
526 | } else {
527 | $('.main-content').css({
528 | 'margin-left': '0px'
529 | });
530 | $('.settings').css({
531 | 'width': '0px'
532 | });
533 | }
534 | // $("#slider-value").html($sliderMaxTabsPerGroup.prop("valueAsNumber"));
535 | }
536 |
--------------------------------------------------------------------------------
/scripts/src/main.js:
--------------------------------------------------------------------------------
1 | document.addEventListener("DOMContentLoaded", function() {
2 | tabManager = new TabManager();
3 | addListeners(tabManager);
4 | tabManager.reloadPage();
5 | });
6 |
--------------------------------------------------------------------------------
/scripts/src/renderHTML.js:
--------------------------------------------------------------------------------
1 | function renderWindow(windowId) {
2 | return `
3 |
4 | `;
5 | }
6 |
7 | function renderWindowTitle(wid, customTitle = "") {
8 | let title = customTitle || "Window " + wid;
9 | return `