-
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
0 parents
commit f66a1f8
Showing
51 changed files
with
3,280 additions
and
0 deletions.
There are no files selected for viewing
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,36 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
.DS_Store | ||
dist | ||
dist-ssr | ||
coverage | ||
*.local | ||
|
||
/cypress/videos/ | ||
/cypress/screenshots/ | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
*.tsbuildinfo | ||
|
||
|
||
/node_modules | ||
*/newtab | ||
/.vscode | ||
*.zip |
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,10 @@ | ||
{ | ||
"extensionName": { | ||
"message": "My New TAb", | ||
"description": "扩展名" | ||
}, | ||
"extensionDescription": { | ||
"message": "增强新标签页功能,可同时显示多个搜索引擎,正在逐步完善", | ||
"description": "扩展描述" | ||
} | ||
} |
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,43 @@ | ||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { | ||
if (request.type === "GET_REQUEST") { | ||
axios.get(request.url) | ||
.then(response => { | ||
sendResponse({ data: response.data }); | ||
}) | ||
.catch(error => { | ||
sendResponse({ error: error.message }); | ||
}); | ||
return true; // 表示将异步响应 | ||
} | ||
}); | ||
|
||
chrome.runtime.onInstalled.addListener(() => { | ||
chrome.storage.local.set({ 'singleNewTabEnabled': false }) | ||
}) | ||
|
||
// 监听标签页创建事件,决定是否只保留一个新标签页 | ||
chrome.tabs.onCreated.addListener(async function (tab) { | ||
const singleNewTabEnabled = (await chrome.storage.local.get('singleNewTabEnabled')).singleNewTabEnabled === true ? true : false | ||
if (singleNewTabEnabled === false) { | ||
return | ||
} | ||
const newTabUrl1 = "chrome://newtab/"; | ||
const newTabUrl2 = "edge://newtab/"; | ||
if (tab.pendingUrl === newTabUrl1 || tab.pendingUrl === newTabUrl2) { | ||
chrome.tabs.query({ currentWindow: true }, function (tabs) { | ||
let newTabExists = null; | ||
// 遍历所有标签页,找到已经存在的新标签页 | ||
for (let i = 0; i < tabs.length - 1; i++) { | ||
if (tabs[i].url === newTabUrl1 || tabs[i].url === newTabUrl2) { | ||
newTabExists = tabs[i]; | ||
break; | ||
} | ||
} | ||
// 如果有新标签页,关闭当前新标签页 | ||
if (newTabExists) { | ||
chrome.tabs.update(newTabExists.id, { active: true }); | ||
chrome.tabs.remove(tab.id); // 关闭当前标签页 | ||
} | ||
}); | ||
} | ||
}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,32 @@ | ||
{ | ||
"manifest_version": 3, | ||
"name": "__MSG_extensionName__", | ||
"version": "1.0.0", | ||
"description": "__MSG_extensionDescription__", | ||
"default_locale": "zh", | ||
"chrome_url_overrides": { | ||
"newtab": "newtab/index.html" | ||
}, | ||
"incognito": "split", | ||
"icons": { | ||
"16": "icons/logo16.png", | ||
"32": "icons/logo32.png", | ||
"48": "icons/logo48.png" | ||
}, | ||
"permissions": [ | ||
"storage", | ||
"bookmarks", | ||
"tabs", | ||
"clipboardWrite", | ||
"clipboardRead" | ||
], | ||
"background": { | ||
"service_worker": "background.js" | ||
}, | ||
"host_permissions": [ | ||
"<all_urls>" | ||
], | ||
"action": { | ||
"default_popup": "popup.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>My New Tab</title> | ||
<style> | ||
body { | ||
display: flex; | ||
width: 250px; | ||
height: 100px; | ||
align-items: center; | ||
justify-content: center; | ||
font-size: large; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<label>是否只保留一个新标签页:<input type="checkbox" id="single-new-tab-checkbox"></label> | ||
<script src="popup.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
!(async function () { | ||
const singleNewTabEnabled = (await chrome.storage.local.get('singleNewTabEnabled')).singleNewTabEnabled === true ? true : false | ||
document.getElementById('single-new-tab-checkbox').checked = singleNewTabEnabled | ||
})() | ||
|
||
document.getElementById('single-new-tab-checkbox').addEventListener('change', function (event) { | ||
const singleNewTabEnabled = event.target.checked; | ||
|
||
// 发送消息给 background.js,告知检测是否启用 | ||
chrome.storage.local.set({ 'singleNewTabEnabled': singleNewTabEnabled }, function () { | ||
console.log('新标签页检测已设置为: ' + singleNewTabEnabled); | ||
}); | ||
}); |
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,29 @@ | ||
# my-new-tab-vue3-js | ||
|
||
This template should help get you started developing with Vue 3 in Vite. | ||
|
||
## Recommended IDE Setup | ||
|
||
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur). | ||
|
||
## Customize configuration | ||
|
||
See [Vite Configuration Reference](https://vite.dev/config/). | ||
|
||
## Project Setup | ||
|
||
```sh | ||
npm install | ||
``` | ||
|
||
### Compile and Hot-Reload for Development | ||
|
||
```sh | ||
npm run dev | ||
``` | ||
|
||
### Compile and Minify for Production | ||
|
||
```sh | ||
npm run build | ||
``` |
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,23 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<link rel="icon" href="/favicon.ico"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>My New Tab</title> | ||
<style> | ||
body { | ||
font-size: medium; | ||
font-family: sans-serif; | ||
margin: 0; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/src/main.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"paths": { | ||
"@/*": ["./src/*"] | ||
} | ||
}, | ||
"exclude": ["node_modules", "dist"] | ||
} |
Oops, something went wrong.