Skip to content

Commit 898cc56

Browse files
authored
feat: Chrome extension 1.3.1 release (#12)
## Background The 1.3.0 version was published inadvertently with prettier installed in the dev-dependencies, bloating the release package. The version 1.3.1 fixes this issue and adds an initial CI/CD pipeline for the chrome extension ## Changes - Add tooling scripts to format and package a new extension - Add a Github workflow, currently meant to ensure proper formatting only ## Notes Will be merged once the extension has been approved / published
1 parent 9d4b2b8 commit 898cc56

File tree

10 files changed

+126
-40
lines changed

10 files changed

+126
-40
lines changed
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Chrome Extension
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- chrome-extension/**
9+
- .github/workflows/chrome-extension.yaml
10+
pull_request:
11+
branches:
12+
- main
13+
paths:
14+
- chrome-extension/**
15+
- .github/workflows/chrome-extension.yaml
16+
17+
jobs:
18+
test:
19+
runs-on: ubuntu-latest
20+
defaults:
21+
run:
22+
working-directory: chrome-extension
23+
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: "22"
32+
33+
- name: Install dependencies
34+
run: npm ci
35+
36+
- name: Formatting
37+
run: npm run test:format

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ node_modules
22
dist
33
dev
44

5+
# Wordpress extension
56
wordpress/svn/.svn
7+
8+
# Chrome extension
9+
chrome-extension/release/
10+
chrome-extension/release.zip

chrome-extension/.prettierignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
images/
2+
release/
3+
release.zip
4+
5+
.prettierignore
6+
.prettierrc
7+
.DS_Store

chrome-extension/.prettierrc

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"bracketSpacing": true,
5+
"printWidth": 120,
6+
"tabWidth": 2,
7+
"useTabs": false,
8+
"semi": true,
9+
"parser": "typescript",
10+
"overrides": [
11+
{
12+
"files": "*.css",
13+
"options": {
14+
"parser": "css"
15+
}
16+
},
17+
{
18+
"files": "*.json",
19+
"options": {
20+
"parser": "json"
21+
}
22+
},
23+
{
24+
"files": "*.html",
25+
"options": {
26+
"parser": "html"
27+
}
28+
}
29+
]
30+
}
31+

chrome-extension/background.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// User preferences change
22
chrome.storage.onChanged.addListener((changes, areaName) => {
3-
const hasPreferencesChanged = areaName === "local" && changes.userPreferences;
3+
const hasPreferencesChanged = areaName === 'local' && changes.userPreferences;
44

55
if (!hasPreferencesChanged) {
66
return;
@@ -16,7 +16,7 @@ chrome.tabs.onActivated.addListener(() => {
1616

1717
// Current tab URL change
1818
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
19-
if (changeInfo.status !== "complete") {
19+
if (changeInfo.status !== 'complete') {
2020
return;
2121
}
2222

@@ -31,21 +31,19 @@ function toggleAutoOpenPDFLinksOnCurrentTab() {
3131
return;
3232
}
3333

34-
const isUnsupportedURL =
35-
currentTab.url.startsWith("chrome://") ||
36-
currentTab.url.startsWith("edge://");
34+
const isUnsupportedURL = currentTab.url.startsWith('chrome://') || currentTab.url.startsWith('edge://');
3735

3836
if (isUnsupportedURL) {
3937
return;
4038
}
4139

42-
chrome.storage.local.get("userPreferences", ({ userPreferences }) => {
40+
chrome.storage.local.get('userPreferences', ({ userPreferences }) => {
4341
const preferences = userPreferences ?? { autoOpen: false };
4442

4543
chrome.scripting.executeScript(
4644
{
4745
target: { tabId: currentTab.id },
48-
files: ["./node_modules/@simplepdf/web-embed-pdf/dist/index.js"],
46+
files: ['./node_modules/@simplepdf/web-embed-pdf/dist/index.js'],
4947
},
5048
() => {
5149
if (chrome.runtime.lastError) {
@@ -61,7 +59,7 @@ function toggleAutoOpenPDFLinksOnCurrentTab() {
6159

6260
window.simplePDF.setConfig({
6361
autoOpen: preferences.autoOpen,
64-
companyIdentifier: "chrome",
62+
companyIdentifier: 'chrome',
6563
});
6664
},
6765
args: [preferences],

chrome-extension/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "__MSG_app_name__",
33
"description": "__MSG_app_description__",
44
"default_locale": "en",
5-
"version": "1.3.0",
5+
"version": "1.3.1",
66
"manifest_version": 3,
77
"permissions": ["activeTab", "scripting", "storage"],
88
"host_permissions": ["<all_urls>"],

chrome-extension/package-lock.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chrome-extension/package.json

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
{
2+
"author": "SimplePDF",
3+
"repository": {
4+
"type": "git",
5+
"url": "git+https://github.com/SimplePDF/simplepdf-embed/tree/main/chrome-extension"
6+
},
7+
"license": "MIT",
8+
"scripts": {
9+
"prettier": "prettier .",
10+
"test:format": "npm run prettier -- --check",
11+
"format": "npm run prettier -- --write",
12+
"package": "npm ci --production && zip -r release.zip . -x .prettierignore .prettierrc package-lock.json"
13+
},
214
"dependencies": {
315
"@simplepdf/web-embed-pdf": "^1.8.1"
416
},

chrome-extension/popup.js

+25-30
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ chrome.tabs.query({ active: true, currentWindow: true }).then(([tab]) => {
33
{
44
target: { tabId: tab.id },
55
func: () => {
6-
return { isPDF: document.contentType === "application/pdf" };
6+
return { isPDF: document.contentType === 'application/pdf' };
77
},
88
},
99
(tab) => {
10-
preferencesHeader.textContent =
11-
chrome.i18n.getMessage("preferencesHeader");
12-
autoOpenLabel.textContent = chrome.i18n.getMessage("autoOpenLabel");
10+
preferencesHeader.textContent = chrome.i18n.getMessage('preferencesHeader');
11+
autoOpenLabel.textContent = chrome.i18n.getMessage('autoOpenLabel');
1312

1413
if (!tab) {
15-
openEditorButton.textContent = chrome.i18n.getMessage("openEditor");
14+
openEditorButton.textContent = chrome.i18n.getMessage('openEditor');
1615
return;
1716
}
1817

@@ -23,8 +22,8 @@ chrome.tabs.query({ active: true, currentWindow: true }).then(([tab]) => {
2322
] = tab;
2423

2524
openEditorButton.textContent = isPDF
26-
? chrome.i18n.getMessage("editWithSimplePDF")
27-
: chrome.i18n.getMessage("openEditor");
25+
? chrome.i18n.getMessage('editWithSimplePDF')
26+
: chrome.i18n.getMessage('openEditor');
2827
},
2928
);
3029
});
@@ -33,7 +32,7 @@ async function handleOpenEditor() {
3332
const openEditor = () => {
3433
const currentURL = document.location.href;
3534

36-
const isPDF = document.contentType === "application/pdf";
35+
const isPDF = document.contentType === 'application/pdf';
3736

3837
const href = isPDF ? currentURL : null;
3938

@@ -49,7 +48,7 @@ async function handleOpenEditor() {
4948
await chrome.scripting.executeScript(
5049
{
5150
target: { tabId: tab.id },
52-
files: ["./node_modules/@simplepdf/web-embed-pdf/dist/index.js"],
51+
files: ['./node_modules/@simplepdf/web-embed-pdf/dist/index.js'],
5352
},
5453
() => {
5554
if (chrome.runtime.lastError) {
@@ -64,7 +63,7 @@ async function handleOpenEditor() {
6463
}
6564

6665
window.simplePDF.setConfig({
67-
companyIdentifier: "chrome",
66+
companyIdentifier: 'chrome',
6867
});
6968
},
7069
});
@@ -78,25 +77,22 @@ async function handleOpenEditor() {
7877

7978
window.close();
8079
} catch (e) {
81-
chrome.tabs.create({ url: "https://simplePDF.com/editor", active: false });
82-
openEditorButton.style.display = "none";
83-
errorDetails.textContent = chrome.i18n.getMessage(
84-
"unableToOpenInCurrentTab",
85-
);
86-
errorMessage.textContent = chrome.i18n.getMessage("openedInOtherTab");
80+
chrome.tabs.create({ url: 'https://simplePDF.com/editor', active: false });
81+
openEditorButton.style.display = 'none';
82+
errorDetails.textContent = chrome.i18n.getMessage('unableToOpenInCurrentTab');
83+
errorMessage.textContent = chrome.i18n.getMessage('openedInOtherTab');
8784

88-
await fetch("https://chrome.simplePDF.com/graphql", {
89-
method: "POST",
85+
await fetch('https://chrome.simplePDF.com/graphql', {
86+
method: 'POST',
9087
headers: {
91-
"Content-Type": "application/json",
88+
'Content-Type': 'application/json',
9289
},
9390
body: JSON.stringify({
94-
query:
95-
"mutation Track($input: TrackEventInput!) { track(input: $input) }",
91+
query: 'mutation Track($input: TrackEventInput!) { track(input: $input) }',
9692
variables: {
9793
input: {
98-
type: "ERROR",
99-
name: "Chrome extension error",
94+
type: 'ERROR',
95+
name: 'Chrome extension error',
10096
data: JSON.stringify({ name: e.name, message: e.message }),
10197
},
10298
},
@@ -105,10 +101,9 @@ async function handleOpenEditor() {
105101
}
106102
}
107103

108-
document.addEventListener("DOMContentLoaded", () => {
109-
chrome.storage.local.get("userPreferences", ({ userPreferences }) => {
110-
const isAutoOpenedDefined =
111-
userPreferences && typeof userPreferences.autoOpen !== "undefined";
104+
document.addEventListener('DOMContentLoaded', () => {
105+
chrome.storage.local.get('userPreferences', ({ userPreferences }) => {
106+
const isAutoOpenedDefined = userPreferences && typeof userPreferences.autoOpen !== 'undefined';
112107

113108
if (isAutoOpenedDefined) {
114109
autoOpenRadio.checked = userPreferences.autoOpen;
@@ -119,7 +114,7 @@ document.addEventListener("DOMContentLoaded", () => {
119114
});
120115

121116
setTimeout(() => {
122-
toggle.classList.add("withTransition");
117+
toggle.classList.add('withTransition');
123118
}, 200);
124119
});
125120

@@ -130,5 +125,5 @@ const handleChangeAutoOpenPreferences = (e) => {
130125
chrome.storage.local.set({ userPreferences: preferences });
131126
};
132127

133-
openEditorButton.addEventListener("click", handleOpenEditor);
134-
autoOpenRadio.addEventListener("change", handleChangeAutoOpenPreferences);
128+
openEditorButton.addEventListener('click', handleOpenEditor);
129+
autoOpenRadio.addEventListener('change', handleChangeAutoOpenPreferences);

chrome-extension/styles.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
border-radius: 50%;
118118
background-color: #fff;
119119
bottom: 2px;
120-
content: "";
120+
content: '';
121121
height: 17px;
122122
left: 2px;
123123
position: absolute;

0 commit comments

Comments
 (0)