Skip to content

Commit 8604544

Browse files
committed
fixes image and link snippets
1 parent c13288f commit 8604544

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

extension/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ chrome.tabs.onActivated.addListener(async function(activeInfo) {
1212
enabled: true
1313
});
1414
});
15+
chrome.runtime.onConnect.addListener(function (port) {
16+
if (port.name === 'mySidepanel') {
17+
port.onDisconnect.addListener(async () => {
18+
console.log('Sidepanel closed.');
19+
chrome.storage.local.remove(["snip_content", "snip_type"]);
20+
21+
});
22+
}
23+
});
1524

1625
chrome.action.onClicked.addListener(async function(){
1726
await chrome.sidePanel.setOptions({

popup/src/App.jsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ async function getCurrentSelectionData() {
1313
target: { tabId: currentTab.id },
1414
func: async () => {
1515
let selectionText = await chrome.storage.local.get(["snip_content", "snip_type"]);
16-
disableListener = true; // Temporarily disable
17-
await chrome.storage.local.remove(["snip_content", "snip_type"]);
18-
disableListener = false; // Re-enable
16+
1917
if (!window.location.href.endsWith(".pdf") && selectionText.snip_content === undefined) {
18+
console.log(window.getSelection().toString())
2019
return {
2120
snip_content: window.getSelection().toString(),
2221
snip_type: "text",
@@ -38,6 +37,7 @@ async function getCurrentSelectionData() {
3837

3938
function App() {
4039
const [snipd, setSnipd] = useState();
40+
chrome.runtime.connect({ name: 'mySidepanel' });
4141

4242
useEffect(() => {
4343
const updateSnipdFromSelection = () => {
@@ -49,17 +49,6 @@ function App() {
4949

5050
updateSnipdFromSelection();
5151

52-
// const listener = (changes, namespace) => {
53-
// if (namespace === 'local') {
54-
// updateSnipdFromSelection();
55-
// }
56-
// };
57-
58-
// const listener = (changes, namespace) => {
59-
// if (namespace === "local" && (changes.snip_content || changes.snip_type)) {
60-
// updateSnipdFromSelection();
61-
// }
62-
// };
6352

6453
const listener = (changes, namespace) => {
6554
if (namespace === 'local' && !disableListener) {

0 commit comments

Comments
 (0)