Skip to content
This repository has been archived by the owner on Jun 17, 2023. It is now read-only.

Commit

Permalink
feat: export Image as Phone Width, add options for request
Browse files Browse the repository at this point in the history
- 导出图片时可设置图片宽度,计划有两个选项,一个是“如所见”,as seeing,另一个是“手机宽”, phone width,取iPhone 13的宽度,为375px;
- 为之前添加的“在Chrome上使用New Bing”以及“避免跳转到cn.bing.com”添加选项
  • Loading branch information
gantrol authored Mar 1, 2023
2 parents 922b9c9 + 8ea0159 commit 6efd0e3
Show file tree
Hide file tree
Showing 19 changed files with 524 additions and 134 deletions.
65 changes: 64 additions & 1 deletion background.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
import { getUUID } from "~utils/uuid";
import { Chat, db, Message } from "~utils/store/indexedDB";
import { Messages } from "~utils/constants";
import { Messages, Settings } from "~utils/constants";
import { ip_rule, ua_rule } from '~utils/rules';
import { chromeSyncGet } from "~utils/store/chrome";


chrome.declarativeNetRequest.updateDynamicRules({
// remove exist rules
// TODO: 1 is the rule in rules.json...check if it's necessary
removeRuleIds: [1, ip_rule.id, ua_rule.id]
}).then(r => {
console.log(r);
chromeSyncGet(Settings.REQUEST_IP).then(r => {
console.log(r);
if (r) {
chrome.declarativeNetRequest.updateDynamicRules({
addRules: [ip_rule]
}).then(r => {
console.log(r);
});
}
});
chromeSyncGet(Settings.REQUEST_UA).then(r => {
console.log(r);
if (r) {
chrome.declarativeNetRequest.updateDynamicRules({
addRules: [ua_rule]
}).then(r => {
console.log(r);
});
}
});
});

chrome.runtime.onMessage.addListener(
async (request, sender, sendResponse) => {
console.log(sender.tab ?
Expand All @@ -12,6 +42,39 @@ chrome.runtime.onMessage.addListener(
// TODO: 完善日志体系……
await saveChatToDB(request.body);
sendResponse({ success: true });
} else if (request.type === Messages.RESIZE_WINDOW) {
console.log(request.body);
const r1 = await chrome.windows.update(request.body.id, {
width: request.body.width,
height: request.body.height,
state: request.body.state,
}).catch(error => {
console.log(error);
}
);
await sendResponse(r1);
} else if (request.type === Messages.RESIZE_WINDOW_2) {
// Have no idea why RESIZE_WINDOW is not working when resizing from small to large
await chrome.windows.update(request.body.id, {
width: request.body.width,
height: request.body.height,
}).catch(error => {
console.log(error);
}
);
const r2 = await chrome.windows.update(request.body.id, {
state: request.body.state,
}).catch(error => {
console.log(error);
}
)
await sendResponse(r2);

} else if (request.type === Messages.GET_WINDOW_SIZE) {
chrome.windows.getCurrent((currentWindow) => {
console.log(currentWindow);
sendResponse(currentWindow);
});
}
}
);
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions components/PromiseWaiting.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script>
import { popupPageI18nValue } from "~utils/constants";
export let promises;
</script>

{#await Promise.all(promises)}
<p>{popupPageI18nValue.WAITING}</p>
{:then _}
<slot></slot>
{:catch err}
<p>{err}</p>
{/await}
15 changes: 15 additions & 0 deletions components/SimpleSelect.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script>
export let bind_value;
export let keys;
export let values;
</script>

<select
class="select"
bind:value="{bind_value}">
{#each Object.keys(keys) as key}
<option value={keys[key]}>
{values[key]}
</option>
{/each}
</select>
41 changes: 41 additions & 0 deletions components/popup/DebugQuickButtons.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<script>
import Collapse from "~components/Collapse.svelte";
import LinkButton from "~components/LinkButton.svelte";
import { LinkType, Messages, popupPageI18nValue } from "~utils/constants";
</script>

<Collapse
title="debug Tools"
default_open={true}
>
<button class="btn" on:click={async () => {
let prev_size;
const size = await chrome.runtime.sendMessage({
type: Messages.GET_WINDOW_SIZE
});
console.log(size)

prev_size = {...size};
size.width = 375;
size.state = 'normal';
const response = await chrome.runtime.sendMessage({
type: Messages.RESIZE_WINDOW,
body: size
});
console.log(response)
console.log(prev_size)
chrome.runtime.sendMessage({
type: Messages.RESIZE_WINDOW_2,
body: prev_size
}).catch((error) => {
console.error(error);
})
}}>
RESIZE
</button>
<LinkButton
url="https://www.bing.com/search?q=I%20need%20to%20throw%20a%20dinner%20party%20for%206%20people%20who%20are%20vegetarian.%20Can%20you%20suggest%20a%203-course%20menu%20with%20a%20chocolate%20dessert?&iscopilotedu=1&form=MA13G7"
text={popupPageI18nValue.BING_DEMO_LINK}
type={LinkType.BING}
/>
</Collapse>
53 changes: 53 additions & 0 deletions components/popup/ExportSettings.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<script>
import Collapse from "~components/Collapse.svelte";
import { exportSettingsI18nValue, exportTypes, exportWidthTemplateKeys, popupPageI18nValue } from "~utils/constants";
import { exportSettings } from "~utils/store/stores";
import PromiseWaiting from "~components/PromiseWaiting.svelte";
let promises = [
exportSettings.init(),
];
</script>

<PromiseWaiting {promises}>
<Collapse
title={popupPageI18nValue.EXPORT_SETTINGS_TITLE}
default_open={true}
>
{#each $exportSettings as message, i}
<div class="form-control">
<div class="input-group">
<label class="label cursor-pointer">
<input type="checkbox" bind:checked={message.on} class="checkbox checkbox-primary" />
</label>
<select
class="select"
bind:value="{message.type}">
{#each Object.keys(exportTypes) as key}
<option value={exportTypes[key]}>
{exportTypes[key]}
</option>
{/each}
</select>
<select
class="select"
bind:value="{message.size_template}">
{#each Object.keys(exportWidthTemplateKeys) as key}
<option value={exportWidthTemplateKeys[key]}>
{exportSettingsI18nValue[key]}
</option>
{/each}
</select>

<!-- <SimpleSelect-->
<!-- bind:bind_value="{message.size_template}"-->
<!-- keys={exportWidthTemplateKeys}-->
<!-- values={exportSettingsI18nValue}-->
<!-- />-->
</div>
</div>
{/each}
</Collapse>
</PromiseWaiting>

30 changes: 30 additions & 0 deletions components/popup/RequestSettings.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script>
import Collapse from "~components/Collapse.svelte";
import SimpleCheckbox from "~components/SimpleCheckbox.svelte";
import { popupPageI18nValue } from "~utils/constants";
import { requestIpSetting, requestUserAgentSetting } from "~utils/store/stores";
import PromiseWaiting from "~components/PromiseWaiting.svelte";
let promises = [
requestIpSetting.init(),
requestUserAgentSetting.init(),
];
</script>

<PromiseWaiting {promises}>
<Collapse
title={popupPageI18nValue.REQUEST_SETTING}
default_open={true}
>
<div class="form-control">
<SimpleCheckbox
isChecked={requestUserAgentSetting}
text={popupPageI18nValue.REQUEST_BROWSER}
/>
<!--TODO: ADD self config ip-->
<SimpleCheckbox
isChecked={requestIpSetting}
text={popupPageI18nValue.REQUEST_IP}
/>
</div>
</Collapse>
</PromiseWaiting>
28 changes: 28 additions & 0 deletions components/popup/TopLinks.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script>
import Collapse from "~components/Collapse.svelte";
import LinkButton from "~components/LinkButton.svelte";
import { LinkType, popupPageI18nValue } from "~utils/constants";
</script>

<Collapse
title={popupPageI18nValue.LINK_TITLE}
default_open={true}
>
<LinkButton
url="/tabs/chats.html"
text={popupPageI18nValue.CHAT_RECORD_LINK}
type={LinkType.INNER}
/>

<LinkButton
url="https://www.bing.com/search?q=Bing+AI&showconv=1&FORM=hpcodx"
text={popupPageI18nValue.BING_CHAT_LINK}
type={LinkType.BING}
/>
<LinkButton
url="https://www.bing.com/new"
text={popupPageI18nValue.BING_NEW_LINK}
type={LinkType.BING}
/>

</Collapse>
30 changes: 30 additions & 0 deletions components/popup/UISettings.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script>
import Collapse from "~components/Collapse.svelte";
import { popupPageI18nValue } from "~utils/constants";
import SimpleCheckbox from "~components/SimpleCheckbox.svelte";
import { feedbackHiddenSetting, welcomeHiddenSetting } from "~utils/store/stores";
import PromiseWaiting from "~components/PromiseWaiting.svelte";
let promises = [
welcomeHiddenSetting.init(),
feedbackHiddenSetting.init(),
];
</script>

<PromiseWaiting {promises}>
<Collapse
title={popupPageI18nValue.UI_SETTINGS_TITLE}
default_open={true}
>
<div class="form-control">
<SimpleCheckbox
isChecked={welcomeHiddenSetting}
text={popupPageI18nValue.HIDDEN_WELCOME}
/>
<SimpleCheckbox
isChecked={feedbackHiddenSetting}
text={popupPageI18nValue.HIDDEN_FEEDBACK}
/>
</div>
</Collapse>
</PromiseWaiting>
1 change: 0 additions & 1 deletion content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const init = async () => {


const addButtonGroups = (actionsArea, WaitingButton) => {
// TODO: i18n
addButton(actionsArea, WaitingButton, exportActions.ALL);
addButton(actionsArea, WaitingButton, exportActions.PREVIEW);
};
Expand Down
2 changes: 1 addition & 1 deletion docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,4 @@ X-Forwarded-For: 1.36.5.8

https://github.com/mixmark-io/turndown/


TODO: pdf
24 changes: 24 additions & 0 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
"message": "Bing Chat Demo",
"description": "Bing New Website button"
},
"popup_bing_demo_website_button": {
"message": "Bing Chat Demo1",
"description": "Bing Demo Website button"
},
"popup_link_title": {
"message": "Links",
"description": "Link title"
Expand Down Expand Up @@ -67,6 +71,26 @@
"message": "JSON",
"description": "Export JSON button"
},
"popup_request_setting": {
"message": "Request Settings",
"description": "Request Setting"
},
"popup_export_type_as_seen": {
"message": "As Seen",
"description": "Export as seen button"
},
"popup_export_type_mobile": {
"message": "Phone Width",
"description": "Export Mobile button"
},
"popup_request_browser": {
"message": "Chrome uses New Bing",
"description": "Request browser"
},
"popup_request_ip": {
"message": "Not jump to cn.bing.com",
"description": "Request IP"
},
"end": {
"message": "End",
"description": "Just for end"
Expand Down
24 changes: 24 additions & 0 deletions locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
"message": "必应官方示例",
"description": "Bing New Website button"
},
"popup_bing_demo_website_button": {
"message": "必应官方示例1",
"description": "Bing Demo Website button"
},
"popup_link_title": {
"message": "置顶链接",
"description": "Link title"
Expand Down Expand Up @@ -67,6 +71,26 @@
"message": "JSON",
"description": "Export JSON button"
},
"popup_export_type_as_seen": {
"message": "如所见",
"description": "Export as seen button"
},
"popup_export_type_mobile": {
"message": "手机宽",
"description": "Export mobile button"
},
"popup_request_setting": {
"message": "请求设置",
"description": "Request setting"
},
"popup_request_browser": {
"message": "在谷歌浏览器用新必应",
"description": "Request browser"
},
"popup_request_ip": {
"message": "避免跳转到cn.bing.com",
"description": "Request IP"
},
"end": {
"message": "End",
"description": "结尾的占位符"
Expand Down
Loading

0 comments on commit 6efd0e3

Please sign in to comment.