Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LaLa-HaHa-Hei committed Oct 18, 2024
0 parents commit f66a1f8
Show file tree
Hide file tree
Showing 51 changed files with 3,280 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .gitignore
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
10 changes: 10 additions & 0 deletions MyNewTab/_locales/zh/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extensionName": {
"message": "My New TAb",
"description": "扩展名"
},
"extensionDescription": {
"message": "增强新标签页功能,可同时显示多个搜索引擎,正在逐步完善",
"description": "扩展描述"
}
}
43 changes: 43 additions & 0 deletions MyNewTab/background.js
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); // 关闭当前标签页
}
});
}
})
Binary file added MyNewTab/icons/logo16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MyNewTab/icons/logo32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MyNewTab/icons/logo48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions MyNewTab/manifest.json
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"
}
}
24 changes: 24 additions & 0 deletions MyNewTab/popup.html
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>
13 changes: 13 additions & 0 deletions MyNewTab/popup.js
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);
});
});
29 changes: 29 additions & 0 deletions README.md
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
```
23 changes: 23 additions & 0 deletions index.html
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>
8 changes: 8 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"paths": {
"@/*": ["./src/*"]
}
},
"exclude": ["node_modules", "dist"]
}
Loading

0 comments on commit f66a1f8

Please sign in to comment.