Skip to content

Commit

Permalink
add firefox support
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Mar 12, 2023
1 parent 46bd22d commit 71b2873
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
CHROME_DST = ~/text-saver-chrome.zip
FIREFOX_DST = ~/text-saver-firefox.zip

build:
zip -r ~/text-saver.zip *.js libs/* *.json *.html imgs/logo.png
rm -f $(CHROME_DST)
zip -r $(CHROME_DST) option.html *.js libs/* manifest.json imgs/logo.png

buildf:
rm -f $(FIREFOX_DST)
node build.mjs
zip -r $(FIREFOX_DST) option.html *.js libs/* manifest.json imgs/logo.png

lint:
find . -type f -maxdepth 1 | grep -v org | grep -v Makefile | xargs npx prettier@2.7.1 --write
3 changes: 3 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

[[https://github.com/jiacai2050/text-saver/actions/workflows/CI.yml][https://github.com/jiacai2050/text-saver/actions/workflows/CI.yml/badge.svg]]
[[https://chrome.google.com/webstore/detail/text-saver/egelicndigijclebpggemngfhpnkeglk][https://img.shields.io/chrome-web-store/v/egelicndigijclebpggemngfhpnkeglk.svg?style=plastic]]
[[https://addons.mozilla.org/firefox/addon/text-saver/][https://img.shields.io/amo/v/text-saver.svg?style=plastic]]
#+begin_quote
A browser extension to save texts anytime, anywhere.
#+end_quote
Expand All @@ -25,10 +26,12 @@ All saved texts can be viewed in option page, and users can export their saved t

* Install
- [[https://chrome.google.com/webstore/detail/text-saver/egelicndigijclebpggemngfhpnkeglk][Chrome Web Store]]
- [[https://addons.mozilla.org/firefox/addon/text-saver/][Firefox Add-ons]]
* Screenshots
[[file:imgs/640x400.png]]
[[file:imgs/1280x800.png]]
* Changelog
- v1.1.0 (2023-03-12) :: Add option settings
- v1.0.1 (2023-03-11) :: First release
* License
[[http://liujiacai.net/license/MIT.html?year=2023][MIT License]] © Jiacai Liu
23 changes: 16 additions & 7 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,24 @@ chrome.contextMenus.onClicked.addListener(async (item) => {
},
};
await chrome.storage.local.set(row);
await chrome.notifications.create(null, {
type: 'basic',
title: pageUrl,
contextMessage: 'Saved',
message: selectionText,
iconUrl: 'imgs/logo.png',
});
if (await getNotification())
await chrome.notifications.create(null, {
type: 'basic',
title: pageUrl,
contextMessage: 'Saved',
message: selectionText,
iconUrl: 'imgs/logo.png',
});
});

chrome.action.onClicked.addListener(function () {
chrome.runtime.openOptionsPage();
});

// Firefox doesn't support module background.js directly
// So this fn is duplicated with Options
async function getNotification() {
const key = 'enable-notification';
const opt = await chrome.storage.sync.get({ [key]: false });
return opt[key];
}
19 changes: 19 additions & 0 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import manifest from './manifest.json' assert { type: 'json' };
import { writeFileSync } from 'fs';

const overwrite = {
background: {
scripts: ['background.js'],
},
browser_specific_settings: {
gecko: {
id: 'liujiacai@yandex.com',
},
},
};

for (const [key, value] of Object.entries(overwrite)) {
manifest[key] = value;
}

writeFileSync('./manifest.json', JSON.stringify(manifest, null, 2));
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Text Saver",
"version": "1.0.1",
"version": "1.1.0",
"description": "Save texts anytime, anywhere",
"homepage_url": "https://github.com/jiacai2050/text-saver",
"author": "liujiacai@yandex.com",
Expand Down

0 comments on commit 71b2873

Please sign in to comment.