Skip to content

chore: Chrome extension 1.3.1 release #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/chrome-extension.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Chrome Extension

on:
push:
branches:
- main
paths:
- chrome-extension/**
- .github/workflows/chrome-extension.yaml
pull_request:
branches:
- main
paths:
- chrome-extension/**
- .github/workflows/chrome-extension.yaml

jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: chrome-extension

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "22"

- name: Install dependencies
run: npm ci

- name: Formatting
run: npm run test:format
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ node_modules
dist
dev

# Wordpress extension
wordpress/svn/.svn

# Chrome extension
chrome-extension/release/
chrome-extension/release.zip
7 changes: 7 additions & 0 deletions chrome-extension/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
images/
release/
release.zip

.prettierignore
.prettierrc
.DS_Store
31 changes: 31 additions & 0 deletions chrome-extension/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"parser": "typescript",
"overrides": [
{
"files": "*.css",
"options": {
"parser": "css"
}
},
{
"files": "*.json",
"options": {
"parser": "json"
}
},
{
"files": "*.html",
"options": {
"parser": "html"
}
}
]
}

14 changes: 6 additions & 8 deletions chrome-extension/background.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// User preferences change
chrome.storage.onChanged.addListener((changes, areaName) => {
const hasPreferencesChanged = areaName === "local" && changes.userPreferences;
const hasPreferencesChanged = areaName === 'local' && changes.userPreferences;

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

// Current tab URL change
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status !== "complete") {
if (changeInfo.status !== 'complete') {
return;
}

Expand All @@ -31,21 +31,19 @@ function toggleAutoOpenPDFLinksOnCurrentTab() {
return;
}

const isUnsupportedURL =
currentTab.url.startsWith("chrome://") ||
currentTab.url.startsWith("edge://");
const isUnsupportedURL = currentTab.url.startsWith('chrome://') || currentTab.url.startsWith('edge://');

if (isUnsupportedURL) {
return;
}

chrome.storage.local.get("userPreferences", ({ userPreferences }) => {
chrome.storage.local.get('userPreferences', ({ userPreferences }) => {
const preferences = userPreferences ?? { autoOpen: false };

chrome.scripting.executeScript(
{
target: { tabId: currentTab.id },
files: ["./node_modules/@simplepdf/web-embed-pdf/dist/index.js"],
files: ['./node_modules/@simplepdf/web-embed-pdf/dist/index.js'],
},
() => {
if (chrome.runtime.lastError) {
Expand All @@ -61,7 +59,7 @@ function toggleAutoOpenPDFLinksOnCurrentTab() {

window.simplePDF.setConfig({
autoOpen: preferences.autoOpen,
companyIdentifier: "chrome",
companyIdentifier: 'chrome',
});
},
args: [preferences],
Expand Down
2 changes: 1 addition & 1 deletion chrome-extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "__MSG_app_name__",
"description": "__MSG_app_description__",
"default_locale": "en",
"version": "1.3.0",
"version": "1.3.1",
"manifest_version": 3,
"permissions": ["activeTab", "scripting", "storage"],
"host_permissions": ["<all_urls>"],
Expand Down
1 change: 1 addition & 0 deletions chrome-extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions chrome-extension/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
{
"author": "SimplePDF",
"repository": {
"type": "git",
"url": "git+https://github.com/SimplePDF/simplepdf-embed/tree/main/chrome-extension"
},
"license": "MIT",
"scripts": {
"prettier": "prettier .",
"test:format": "npm run prettier -- --check",
"format": "npm run prettier -- --write",
"package": "npm ci --production && zip -r release.zip . -x .prettierignore .prettierrc package-lock.json"
},
"dependencies": {
"@simplepdf/web-embed-pdf": "^1.8.1"
},
Expand Down
55 changes: 25 additions & 30 deletions chrome-extension/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ chrome.tabs.query({ active: true, currentWindow: true }).then(([tab]) => {
{
target: { tabId: tab.id },
func: () => {
return { isPDF: document.contentType === "application/pdf" };
return { isPDF: document.contentType === 'application/pdf' };
},
},
(tab) => {
preferencesHeader.textContent =
chrome.i18n.getMessage("preferencesHeader");
autoOpenLabel.textContent = chrome.i18n.getMessage("autoOpenLabel");
preferencesHeader.textContent = chrome.i18n.getMessage('preferencesHeader');
autoOpenLabel.textContent = chrome.i18n.getMessage('autoOpenLabel');

if (!tab) {
openEditorButton.textContent = chrome.i18n.getMessage("openEditor");
openEditorButton.textContent = chrome.i18n.getMessage('openEditor');
return;
}

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

openEditorButton.textContent = isPDF
? chrome.i18n.getMessage("editWithSimplePDF")
: chrome.i18n.getMessage("openEditor");
? chrome.i18n.getMessage('editWithSimplePDF')
: chrome.i18n.getMessage('openEditor');
},
);
});
Expand All @@ -33,7 +32,7 @@ async function handleOpenEditor() {
const openEditor = () => {
const currentURL = document.location.href;

const isPDF = document.contentType === "application/pdf";
const isPDF = document.contentType === 'application/pdf';

const href = isPDF ? currentURL : null;

Expand All @@ -49,7 +48,7 @@ async function handleOpenEditor() {
await chrome.scripting.executeScript(
{
target: { tabId: tab.id },
files: ["./node_modules/@simplepdf/web-embed-pdf/dist/index.js"],
files: ['./node_modules/@simplepdf/web-embed-pdf/dist/index.js'],
},
() => {
if (chrome.runtime.lastError) {
Expand All @@ -64,7 +63,7 @@ async function handleOpenEditor() {
}

window.simplePDF.setConfig({
companyIdentifier: "chrome",
companyIdentifier: 'chrome',
});
},
});
Expand All @@ -78,25 +77,22 @@ async function handleOpenEditor() {

window.close();
} catch (e) {
chrome.tabs.create({ url: "https://simplePDF.com/editor", active: false });
openEditorButton.style.display = "none";
errorDetails.textContent = chrome.i18n.getMessage(
"unableToOpenInCurrentTab",
);
errorMessage.textContent = chrome.i18n.getMessage("openedInOtherTab");
chrome.tabs.create({ url: 'https://simplePDF.com/editor', active: false });
openEditorButton.style.display = 'none';
errorDetails.textContent = chrome.i18n.getMessage('unableToOpenInCurrentTab');
errorMessage.textContent = chrome.i18n.getMessage('openedInOtherTab');

await fetch("https://chrome.simplePDF.com/graphql", {
method: "POST",
await fetch('https://chrome.simplePDF.com/graphql', {
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: JSON.stringify({
query:
"mutation Track($input: TrackEventInput!) { track(input: $input) }",
query: 'mutation Track($input: TrackEventInput!) { track(input: $input) }',
variables: {
input: {
type: "ERROR",
name: "Chrome extension error",
type: 'ERROR',
name: 'Chrome extension error',
data: JSON.stringify({ name: e.name, message: e.message }),
},
},
Expand All @@ -105,10 +101,9 @@ async function handleOpenEditor() {
}
}

document.addEventListener("DOMContentLoaded", () => {
chrome.storage.local.get("userPreferences", ({ userPreferences }) => {
const isAutoOpenedDefined =
userPreferences && typeof userPreferences.autoOpen !== "undefined";
document.addEventListener('DOMContentLoaded', () => {
chrome.storage.local.get('userPreferences', ({ userPreferences }) => {
const isAutoOpenedDefined = userPreferences && typeof userPreferences.autoOpen !== 'undefined';

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

setTimeout(() => {
toggle.classList.add("withTransition");
toggle.classList.add('withTransition');
}, 200);
});

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

openEditorButton.addEventListener("click", handleOpenEditor);
autoOpenRadio.addEventListener("change", handleChangeAutoOpenPreferences);
openEditorButton.addEventListener('click', handleOpenEditor);
autoOpenRadio.addEventListener('change', handleChangeAutoOpenPreferences);
2 changes: 1 addition & 1 deletion chrome-extension/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
border-radius: 50%;
background-color: #fff;
bottom: 2px;
content: "";
content: '';
height: 17px;
left: 2px;
position: absolute;
Expand Down
Loading