├── .github └── workflows │ └── codeql-analysis.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── History.md ├── LICENSE ├── Makefile ├── README.md ├── dist ├── icon128.png ├── icon16.png ├── icon32.png ├── icon48.png ├── manifest.json ├── rearrange.js └── updated.html ├── icon128.png ├── icon16.png ├── icon32.png ├── icon48.png ├── manifest.json ├── rearrange.js └── updated.html /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | name: "Code scanning - action" 2 | 3 | on: 4 | push: 5 | pull_request: 6 | schedule: 7 | - cron: '0 8 * * 4' 8 | 9 | jobs: 10 | CodeQL-Build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - name: Checkout repository 16 | uses: actions/checkout@v2 17 | with: 18 | # We must fetch at least the immediate parents so that if this is 19 | # a pull request then we can checkout the head. 20 | fetch-depth: 2 21 | 22 | # If this run was triggered by a pull request event, then checkout 23 | # the head of the pull request instead of the merge commit. 24 | - run: git checkout HEAD^2 25 | if: ${{ github.event_name == 'pull_request' }} 26 | 27 | # Initializes the CodeQL tools for scanning. 28 | - name: Initialize CodeQL 29 | uses: github/codeql-action/init@v1 30 | # Override language selection by uncommenting this and choosing your languages 31 | # with: 32 | # languages: go, javascript, csharp, python, cpp, java 33 | 34 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 35 | # If this step fails, then you should remove it and run the build manually (see below) 36 | - name: Autobuild 37 | uses: github/codeql-action/autobuild@v1 38 | 39 | # ℹ️ Command-line programs to run using the OS shell. 40 | # 📚 https://git.io/JvXDl 41 | 42 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 43 | # and modify them (or add more) to build your code if your project 44 | # uses a compiled language 45 | 46 | #- run: | 47 | # make bootstrap 48 | # make release 49 | 50 | - name: Perform CodeQL Analysis 51 | uses: github/codeql-action/analyze@v1 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | rearrange_tabs.zip 3 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at hi@iam.mt. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | 2 | 3.0.0 / 2023-02-14 (Valentine's Day Release) 3 | ================== 4 | 5 | * Complete rewrite! 6 | * Fixes bugs and performance issues 7 | * Changes default key combo for Mac users to avoid conflict 8 | * Dropped support for tabs cycling around the extremities 9 | 10 | 2.1.7 / 2020-04-26 11 | ================== 12 | 13 | * Fix errors on mac chrome 81.0.4044.92 14 | 15 | 2.1.6 / 2018-08-19 16 | ================== 17 | 18 | * update commands in script to reflect the new namespace 19 | 20 | 2.1.5 / 2018-08-19 21 | ================== 22 | 23 | * namespace the shortcuts with the "rt-" prefix. This fixes the bug that caused the shortcuts to reset after installing of 2.1.2. This only affected users who were upgrading from an existing version of rearrange tabs extension. New installs are not affected. 24 | 25 | 2.1.2 / 2018-08-11 26 | ================== 27 | 28 | * Fix versioning 29 | 30 | 2.1.0 / 2018-07-05 31 | ================== 32 | 33 | * Add feature to move tabs to the front or the end of the tab bar (Issue #3) 34 | 35 | 2.0.0 / 2017-10-21 36 | ================== 37 | 38 | * removing permission block from manifest since it is not needed to rearrange tabs (Issue #19) 39 | * Create CODE_OF_CONDUCT.md 40 | * update license 41 | * include lifehacker and changelog links 42 | 43 | 1.4.1 / 2016-11-18 44 | ================== 45 | 46 | * change icon color 47 | 48 | 1.4.0 / 2016-10-11 49 | ================== 50 | 51 | - Add support for moving several tabs at once 52 | - Fixed an issue where tab move did not cycle when tab is the rightmost tab and is moved to the right 53 | 54 | 1.2.0 / 2016-04-15 55 | ================== 56 | 57 | * Add support for pinned tabs 58 | * prioritize mac over windows 59 | 60 | 1.1.0 / 2015-06-03 61 | ================== 62 | 63 | * update key on Mac to Ctrl+Shift+ to avoid conflict with the shortcut to highlight a single word 64 | 65 | 1.0.0 / 2015-03-22 66 | ================== 67 | 68 | * Initial release 69 | * Add support for rearranging tabs using keyboard shortcuts 70 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2020 Mohnish Thallavajhula <hi@iam.mt> 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | 'Software'), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | dist: 2 | @mkdir -p dist 3 | @cp icon*.png manifest.json rearrange.js updated.html dist/ 4 | @zip -r rearrange_tabs.zip dist/ 5 | 6 | clean: 7 | rm -fr ./dist/ 8 | 9 | .PHONY: dist clean 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rearrange Tabs 2 | 3 | ![](https://img.shields.io/chrome-web-store/v/ccnnhhnmpoffieppjjkhdakcoejcpbga?style=for-the-badge) 4 | ![](https://img.shields.io/chrome-web-store/users/ccnnhhnmpoffieppjjkhdakcoejcpbga?style=for-the-badge) 5 | ![](https://img.shields.io/chrome-web-store/rating/ccnnhhnmpoffieppjjkhdakcoejcpbga?style=for-the-badge) 6 | 7 | 8 | ![](http://i.imgur.com/BFar404.png) 9 | 10 | Rearrange Tabs is a tiny Google Chrome Extension that allows users 11 | to rearrange the position of the tabs in a window by moving them 12 | around using keyboard shortcuts. 13 | 14 | Rearrange Tabs has been featured on [LifeHacker](http://lifehacker.com/this-extension-rearranges-chrome-tabs-with-keyboard-sho-1791622486) and [Changelog](http://email.changelog.com/t/t-9A7FDF4C536D63BF) :smile: 15 | 16 | - To move selected tab(s) left 17 | 18 | - `Mac`: Ctrl-CMD-Left 19 | - `Windows`: Shift-Alt-Left 20 | 21 | - To move selected tab(s) right 22 | 23 | - `Mac`: Ctrl-CMD-Right 24 | - `Windows`: Shift-Alt-Right 25 | 26 | - To move selected tab(s) to the front (leftmost position) 27 | 28 | - `Mac`: Ctrl-CMD-Up 29 | - `Windows`: Shift-Alt-Up 30 | 31 | - To move selected tab(s) to the back (rightmost position) 32 | 33 | - `Mac`: Ctrl-CMD-Down 34 | - `Windows`: Shift-Alt-Down 35 | 36 | It's as simple as that. Here's how it looks like: [https://www.youtube.com/watch?v=A1X3geKtF8A](https://www.youtube.com/watch?v=A1X3geKtF8A) 37 | 38 | Here's the introduction blog post: [https://iam.mt/rearrange-tabs](https://iam.mt/rearrange-tabs) 39 | 40 | Shortcuts are configurable via `chrome://extensions/shortcuts` page. 41 | 42 | ## Installation 43 | 44 | Install the extension by visiting this Chrome Web Store link: **[Chrome Web Store](https://chrome.google.com/webstore/detail/rearrange-tabs/ccnnhhnmpoffieppjjkhdakcoejcpbga)** 45 | 46 | ## Customize Shortcut 47 | 48 | 1. Go to `chrome://extensions/shortcuts`. 49 | 2. Scroll down to locate `Rearrange Tabs`. 50 | 3. Click in the greyed fields. 51 | 6. Press the desired key combination to create a new shortcut. 52 | 53 | ![image](https://user-images.githubusercontent.com/138171/218686343-b09abd8a-c259-4d49-8282-d58c461d85b1.png) 54 | 55 | ## Features 56 | 57 | - Move regular tabs around in a window 58 | - Move pinned tabs around in a window 59 | - Move multiple selected tabs around in a window 60 | - Move selected tabs to the leftmost or the rightmost positions 61 | 62 | ## Development 63 | 64 | - Once the changes have been made to the the extension, run `make dist`. This will update the `dist` directory with the new files 65 | - If for some reason you want to remove the `dist` directory, run `make clean` 66 | - It might be necessary to install `make` before you can use it. If you encounter an error, open the terminal and run `sudo apt-get install zip make` 67 | 68 | ## Compatibility 69 | 70 | ✅ Brave browser 71 | 72 | ✅ Edge browser 73 | 74 | ❌ Arc browser 75 | 76 | ## Contributors 77 | 78 | - Mohinsh Thallavajhula (@mohnish) 79 | - Anže Videnič (@avidenic) 80 | - Tomas Juočepis (@TomasJuocepis) 81 | - Sandeep Appikonda (@appikonda) 82 | - Rob Yang (@unknownbreaker) 83 | - Roland Synnestvedt (@rsynnest) 84 | - Junho Park (@cnaa97) 85 | - Ross Hale (@rosshale) 86 | 87 | 88 | 89 | 90 | 91 | ## License 92 | 93 | (The MIT License) 94 | 95 | Copyright (c) 2023 Mohnish Thallavajhula <hi@iam.mt> 96 | 97 | Permission is hereby granted, free of charge, to any person obtaining 98 | a copy of this software and associated documentation files (the 99 | 'Software'), to deal in the Software without restriction, including 100 | without limitation the rights to use, copy, modify, merge, publish, 101 | distribute, sublicense, and/or sell copies of the Software, and to 102 | permit persons to whom the Software is furnished to do so, subject to 103 | the following conditions: 104 | 105 | The above copyright notice and this permission notice shall be 106 | included in all copies or substantial portions of the Software. 107 | 108 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 109 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 110 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 111 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 112 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 113 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 114 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 115 | -------------------------------------------------------------------------------- /dist/icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohnish/rearrange-tabs/09736134af64ef06c6b89899b41b5e0c8c8eaed5/dist/icon128.png -------------------------------------------------------------------------------- /dist/icon16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohnish/rearrange-tabs/09736134af64ef06c6b89899b41b5e0c8c8eaed5/dist/icon16.png -------------------------------------------------------------------------------- /dist/icon32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohnish/rearrange-tabs/09736134af64ef06c6b89899b41b5e0c8c8eaed5/dist/icon32.png -------------------------------------------------------------------------------- /dist/icon48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohnish/rearrange-tabs/09736134af64ef06c6b89899b41b5e0c8c8eaed5/dist/icon48.png -------------------------------------------------------------------------------- /dist/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Rearrange Tabs", 3 | "version": "3.0.0", 4 | "description": "Allows users to rearrange tabs using keyboard shortcuts", 5 | "author": "Mohnish Thallavajhula", 6 | "manifest_version": 3, 7 | "short_name": "Rearrange Tabs", 8 | "background": { 9 | "service_worker": "rearrange.js" 10 | }, 11 | "commands": { 12 | "rtl": { 13 | "suggested_key": { 14 | "default": "Shift+Alt+Left", 15 | "windows": "Shift+Alt+Left", 16 | "mac": "Command+MacCtrl+Left" 17 | }, 18 | "description": "Move selected tab(s) left" 19 | }, 20 | "rtr": { 21 | "suggested_key": { 22 | "default": "Shift+Alt+Right", 23 | "windows": "Shift+Alt+Right", 24 | "mac": "Command+MacCtrl+Right" 25 | }, 26 | "description": "Move selected tab(s) right" 27 | }, 28 | "rtf": { 29 | "suggested_key": { 30 | "default": "Shift+Alt+Up", 31 | "windows": "Shift+Alt+Up", 32 | "mac": "Command+MacCtrl+Up" 33 | }, 34 | "description": "Move selected tab(s) to the front" 35 | }, 36 | "rtb": { 37 | "suggested_key": { 38 | "default": "Shift+Alt+Down", 39 | "windows": "Shift+Alt+Down", 40 | "mac": "Command+MacCtrl+Down" 41 | }, 42 | "description": "Move selected tab(s) to the back" 43 | } 44 | }, 45 | "action": { 46 | "default_icon": "icon16.png" 47 | }, 48 | "icons": { 49 | "16": "icon16.png", 50 | "32": "icon32.png", 51 | "48": "icon48.png", 52 | "128": "icon128.png" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /dist/rearrange.js: -------------------------------------------------------------------------------- 1 | chrome.runtime.onInstalled.addListener(async ({ reason, previousVersion }) => { 2 | let version; 3 | 4 | try { 5 | version = Number(previousVersion.split('.')[0]); 6 | } catch(e) { 7 | version = 3; 8 | } 9 | 10 | // Display only when updating from v2 to v3 11 | if (reason == 'update' && version == 2) { 12 | await chrome.tabs.create({ 'url': chrome.runtime.getURL('updated.html' )}); 13 | } 14 | }); 15 | 16 | chrome.commands.onCommand.addListener(async (cmd) => { 17 | const MOVE_LEFT = 'rtl'; 18 | const MOVE_RIGHT = 'rtr'; 19 | const MOVE_FRONT = 'rtf'; 20 | const MOVE_BACK = 'rtb'; 21 | 22 | let all = await chrome.tabs.query({ currentWindow: true }); 23 | let pinned = await chrome.tabs.query({ currentWindow: true, pinned: true }); 24 | let highlightedTabs = await chrome.tabs.query({ currentWindow: true, highlighted: true, pinned: false }); 25 | let highlightedPinnedTabs = await chrome.tabs.query({ currentWindow: true, highlighted: true, pinned: true }); 26 | 27 | // We attempt to move pinned tabs only if they're available 28 | switch (cmd) { 29 | case MOVE_LEFT: 30 | if (highlightedPinnedTabs.length > 0) moveLeft(highlightedPinnedTabs, 0); 31 | moveLeft(highlightedTabs, pinned.length); 32 | break; 33 | case MOVE_RIGHT: 34 | if (highlightedPinnedTabs.length > 0) moveRight(highlightedPinnedTabs, pinned.length); 35 | moveRight(highlightedTabs, all.length); 36 | break; 37 | case MOVE_BACK: 38 | if (highlightedPinnedTabs.length > 0) moveBack(highlightedPinnedTabs, pinned.length); 39 | moveBack(highlightedTabs, all.length); 40 | break; 41 | case MOVE_FRONT: 42 | if (highlightedPinnedTabs.length > 0) moveFront(highlightedPinnedTabs, 0); 43 | moveFront(highlightedTabs, pinned.length); 44 | break; 45 | default: 46 | } 47 | }); 48 | 49 | /** 50 | * Each tab has its own range. This depends on the type, pinned 51 | * or unpinned. It also depends on how many tabs are currently 52 | * highlighted. 53 | * pinned tabs: to 54 | * unpinned tabs: to 55 | * When moving left, we update highlighted tabs from left to right, the natural order 56 | * When moving right, we update highlighted tabs from right to left - this avoids a lot of UI bugs 57 | */ 58 | 59 | function moveLeft(highlightedTabs, offset) { 60 | moveTabs(highlightedTabs.map((highlightedTab, i) => [highlightedTab.id, Math.max(offset + i, highlightedTab.index - 1)])); 61 | } 62 | 63 | function moveFront(highlightedTabs, offset) { 64 | moveTabs(highlightedTabs.map((highlightedTab, i) => [highlightedTab.id, offset + i])); 65 | } 66 | 67 | function moveRight(highlightedTabs, lengthOfAllTabsOfCurrentType) { 68 | let offset = lengthOfAllTabsOfCurrentType - highlightedTabs.length; 69 | let tabs = Array(highlightedTabs.length); 70 | 71 | for (let i = highlightedTabs.length - 1; i >= 0; i--) { 72 | tabs[highlightedTabs.length - i - 1] = [highlightedTabs[i].id, Math.min(offset + i, highlightedTabs[i].index + 1)]; 73 | } 74 | 75 | moveTabs(tabs); 76 | } 77 | 78 | function moveBack(highlightedTabs, lengthOfAllTabsOfCurrentType) { 79 | let tabs = Array(highlightedTabs.length); 80 | 81 | for (let i = highlightedTabs.length - 1; i >= 0; i--) { 82 | let idx = highlightedTabs.length - i - 1; 83 | tabs[idx] = [highlightedTabs[i].id, lengthOfAllTabsOfCurrentType - idx - 1]; 84 | } 85 | 86 | moveTabs(tabs); 87 | } 88 | 89 | function moveTab(id, pos) { 90 | chrome.tabs.move(id, { index: pos }); 91 | } 92 | 93 | function moveTabs(tabs) { 94 | for (let [id, pos] of tabs) { 95 | moveTab(id, pos); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /dist/updated.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Rearrange Tabs Chrome Extension Updated! 7 | 170 | 171 | 172 |

🎉 Rearrange Tabs Chrome Extension has been updated! 🎉

173 |

Version 3.0.0

174 | 175 |

Important changes

176 |
    177 |
  • Mac users, your default shortcut combination has changed
  • 178 |
  • Move left: Ctrl-CMD-Left
  • 179 |
  • Move right: Ctrl-CMD-Right
  • 180 |
  • Move front (leftmost): Ctrl-CMD-Up
  • 181 |
  • Move back (rightmost): Ctrl-CMD-Down
  • 182 |
  • You can always customize your shortcuts visiting (from your address bar): chrome://extensions/shortcuts
  • 183 |
184 | 185 | 186 | -------------------------------------------------------------------------------- /icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohnish/rearrange-tabs/09736134af64ef06c6b89899b41b5e0c8c8eaed5/icon128.png -------------------------------------------------------------------------------- /icon16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohnish/rearrange-tabs/09736134af64ef06c6b89899b41b5e0c8c8eaed5/icon16.png -------------------------------------------------------------------------------- /icon32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohnish/rearrange-tabs/09736134af64ef06c6b89899b41b5e0c8c8eaed5/icon32.png -------------------------------------------------------------------------------- /icon48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohnish/rearrange-tabs/09736134af64ef06c6b89899b41b5e0c8c8eaed5/icon48.png -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Rearrange Tabs", 3 | "version": "3.0.0", 4 | "description": "Allows users to rearrange tabs using keyboard shortcuts", 5 | "author": "Mohnish Thallavajhula", 6 | "manifest_version": 3, 7 | "short_name": "Rearrange Tabs", 8 | "background": { 9 | "service_worker": "rearrange.js" 10 | }, 11 | "commands": { 12 | "rtl": { 13 | "suggested_key": { 14 | "default": "Shift+Alt+Left", 15 | "windows": "Shift+Alt+Left", 16 | "mac": "Command+MacCtrl+Left" 17 | }, 18 | "description": "Move selected tab(s) left" 19 | }, 20 | "rtr": { 21 | "suggested_key": { 22 | "default": "Shift+Alt+Right", 23 | "windows": "Shift+Alt+Right", 24 | "mac": "Command+MacCtrl+Right" 25 | }, 26 | "description": "Move selected tab(s) right" 27 | }, 28 | "rtf": { 29 | "suggested_key": { 30 | "default": "Shift+Alt+Up", 31 | "windows": "Shift+Alt+Up", 32 | "mac": "Command+MacCtrl+Up" 33 | }, 34 | "description": "Move selected tab(s) to the front" 35 | }, 36 | "rtb": { 37 | "suggested_key": { 38 | "default": "Shift+Alt+Down", 39 | "windows": "Shift+Alt+Down", 40 | "mac": "Command+MacCtrl+Down" 41 | }, 42 | "description": "Move selected tab(s) to the back" 43 | } 44 | }, 45 | "action": { 46 | "default_icon": "icon16.png" 47 | }, 48 | "icons": { 49 | "16": "icon16.png", 50 | "32": "icon32.png", 51 | "48": "icon48.png", 52 | "128": "icon128.png" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /rearrange.js: -------------------------------------------------------------------------------- 1 | chrome.runtime.onInstalled.addListener(async ({ reason, previousVersion }) => { 2 | let version; 3 | 4 | try { 5 | version = Number(previousVersion.split('.')[0]); 6 | } catch(e) { 7 | version = 3; 8 | } 9 | 10 | // Display only when updating from v2 to v3 11 | if (reason == 'update' && version == 2) { 12 | await chrome.tabs.create({ 'url': chrome.runtime.getURL('updated.html' )}); 13 | } 14 | }); 15 | 16 | chrome.commands.onCommand.addListener(async (cmd) => { 17 | const MOVE_LEFT = 'rtl'; 18 | const MOVE_RIGHT = 'rtr'; 19 | const MOVE_FRONT = 'rtf'; 20 | const MOVE_BACK = 'rtb'; 21 | 22 | let all = await chrome.tabs.query({ currentWindow: true }); 23 | let pinned = await chrome.tabs.query({ currentWindow: true, pinned: true }); 24 | let highlightedTabs = await chrome.tabs.query({ currentWindow: true, highlighted: true, pinned: false }); 25 | let highlightedPinnedTabs = await chrome.tabs.query({ currentWindow: true, highlighted: true, pinned: true }); 26 | 27 | // We attempt to move pinned tabs only if they're available 28 | switch (cmd) { 29 | case MOVE_LEFT: 30 | if (highlightedPinnedTabs.length > 0) moveLeft(highlightedPinnedTabs, 0); 31 | moveLeft(highlightedTabs, pinned.length); 32 | break; 33 | case MOVE_RIGHT: 34 | if (highlightedPinnedTabs.length > 0) moveRight(highlightedPinnedTabs, pinned.length); 35 | moveRight(highlightedTabs, all.length); 36 | break; 37 | case MOVE_BACK: 38 | if (highlightedPinnedTabs.length > 0) moveBack(highlightedPinnedTabs, pinned.length); 39 | moveBack(highlightedTabs, all.length); 40 | break; 41 | case MOVE_FRONT: 42 | if (highlightedPinnedTabs.length > 0) moveFront(highlightedPinnedTabs, 0); 43 | moveFront(highlightedTabs, pinned.length); 44 | break; 45 | default: 46 | } 47 | }); 48 | 49 | /** 50 | * Each tab has its own range. This depends on the type, pinned 51 | * or unpinned. It also depends on how many tabs are currently 52 | * highlighted. 53 | * pinned tabs: to 54 | * unpinned tabs: to 55 | * When moving left, we update highlighted tabs from left to right, the natural order 56 | * When moving right, we update highlighted tabs from right to left - this avoids a lot of UI bugs 57 | */ 58 | 59 | function moveLeft(highlightedTabs, offset) { 60 | moveTabs(highlightedTabs.map((highlightedTab, i) => [highlightedTab.id, Math.max(offset + i, highlightedTab.index - 1)])); 61 | } 62 | 63 | function moveFront(highlightedTabs, offset) { 64 | moveTabs(highlightedTabs.map((highlightedTab, i) => [highlightedTab.id, offset + i])); 65 | } 66 | 67 | function moveRight(highlightedTabs, lengthOfAllTabsOfCurrentType) { 68 | let offset = lengthOfAllTabsOfCurrentType - highlightedTabs.length; 69 | let tabs = Array(highlightedTabs.length); 70 | 71 | for (let i = highlightedTabs.length - 1; i >= 0; i--) { 72 | tabs[highlightedTabs.length - i - 1] = [highlightedTabs[i].id, Math.min(offset + i, highlightedTabs[i].index + 1)]; 73 | } 74 | 75 | moveTabs(tabs); 76 | } 77 | 78 | function moveBack(highlightedTabs, lengthOfAllTabsOfCurrentType) { 79 | let tabs = Array(highlightedTabs.length); 80 | 81 | for (let i = highlightedTabs.length - 1; i >= 0; i--) { 82 | let idx = highlightedTabs.length - i - 1; 83 | tabs[idx] = [highlightedTabs[i].id, lengthOfAllTabsOfCurrentType - idx - 1]; 84 | } 85 | 86 | moveTabs(tabs); 87 | } 88 | 89 | function moveTab(id, pos) { 90 | chrome.tabs.move(id, { index: pos }); 91 | } 92 | 93 | function moveTabs(tabs) { 94 | for (let [id, pos] of tabs) { 95 | moveTab(id, pos); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /updated.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Rearrange Tabs Chrome Extension Updated! 7 | 170 | 171 | 172 |

🎉 Rearrange Tabs Chrome Extension has been updated! 🎉

173 |

Version 3.0.0

174 | 175 |

Important changes

176 |
    177 |
  • Mac users, your default shortcut combination has changed
  • 178 |
  • Move left: Ctrl-CMD-Left
  • 179 |
  • Move right: Ctrl-CMD-Right
  • 180 |
  • Move front (leftmost): Ctrl-CMD-Up
  • 181 |
  • Move back (rightmost): Ctrl-CMD-Down
  • 182 |
  • You can always customize your shortcuts visiting (from your address bar): chrome://extensions/shortcuts
  • 183 |
184 | 185 | 186 | --------------------------------------------------------------------------------