-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f58ab9
commit b03299a
Showing
10 changed files
with
170 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Random Tabber Options</title> | ||
</head> | ||
<body> | ||
<label> | ||
COMING SOON! Switch to tab in: | ||
<select id="switch-in" disabled> | ||
<option value="current">Current window</option> | ||
<option value="all">All windows</option> | ||
</select> | ||
</label> | ||
<br /> | ||
<label> | ||
<input type="checkbox" id="close-current" /> Close current tab</label | ||
> | ||
|
||
<br /><br /> | ||
<button id="save">Save</button> | ||
|
||
<script src="options.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,30 @@ | ||
interface Settings { | ||
'switch-in': 'current' | 'all'; | ||
'close-current': boolean; | ||
} | ||
|
||
const defaultSettings: Settings = { | ||
'switch-in': 'current', | ||
'close-current': true, | ||
}; | ||
|
||
export const getSettings = async (): Promise<Settings> => | ||
(await chrome.storage.sync.get(defaultSettings)) as Settings; | ||
|
||
chrome.action.onClicked.addListener(async ({ windowId, id }) => { | ||
const settings = await getSettings(); | ||
|
||
const allTabs = await chrome.tabs.query({ windowId }); | ||
const allOtherTabs = allTabs.filter((tab) => tab.id !== id); | ||
const randomTab = | ||
allOtherTabs[Math.floor(Math.random() * allOtherTabs.length)]; | ||
|
||
await chrome.tabs.highlight({ tabs: randomTab.index }); | ||
await chrome.tabs.highlight({ | ||
windowId: randomTab.windowId, | ||
tabs: randomTab.index, | ||
}); | ||
|
||
if (settings['close-current']) { | ||
await chrome.tabs.remove(id); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
interface Settings { | ||
'switch-in': 'current' | 'all'; | ||
'close-current': boolean; | ||
} | ||
|
||
const defaultSettings: Settings = { | ||
'switch-in': 'current', | ||
'close-current': true, | ||
}; | ||
|
||
export const getSettings = async (): Promise<Settings> => | ||
(await chrome.storage.sync.get(defaultSettings)) as Settings; | ||
|
||
async function saveOptions() { | ||
(document.getElementById('save') as HTMLButtonElement).innerText = | ||
'Saving...'; | ||
|
||
const switchIn = (document.getElementById('switch-in') as HTMLSelectElement) | ||
.value; | ||
const closeCurrent = ( | ||
document.getElementById('close-current') as HTMLInputElement | ||
).checked; | ||
|
||
await chrome.storage.sync.set({ | ||
'switch-in': switchIn, | ||
'close-current': closeCurrent, | ||
}); | ||
|
||
(document.getElementById('save') as HTMLButtonElement).innerText = 'Saved!'; | ||
} | ||
|
||
async function restoreOptions() { | ||
const settings = await getSettings(); | ||
|
||
(document.getElementById('switch-in') as HTMLSelectElement).value = | ||
settings['switch-in']; | ||
(document.getElementById('close-current') as HTMLInputElement).checked = | ||
settings['close-current']; | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', restoreOptions); | ||
document.getElementById('save').addEventListener('click', saveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "ES2022", | ||
"moduleResolution": "node", | ||
"target": "ESNext", | ||
"resolveJsonModule": true, | ||
"sourceMap": true | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
"include": ["src/**/*"], | ||
"exclude": ["node_modules"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters