Skip to content
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

Manifest V3 draft #96

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 0 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
env:
WEB_EXT_API_KEY: ${{ secrets.WEB_EXT_API_KEY }}
WEB_EXT_API_SECRET: ${{ secrets.WEB_EXT_API_SECRET }}
WEB_EXT_ID: ${{ secrets.WEB_EXT_ID }}
chrome:
name: Chrome
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion dev/copy-libs.sh
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
cp node_modules/webextension-polyfill/dist/browser-polyfill.min.js src/lib/
9 changes: 1 addition & 8 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"web-ext": "^7.12.0"
},
"dependencies": {
"normalize.css": "^8.0.1",
"webextension-polyfill": "^0.12.0"
"normalize.css": "^8.0.1"
},
"webExt": {
"sourceDir": "src/",
Expand Down
9 changes: 8 additions & 1 deletion src/background.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
browser.browserAction.onClicked.addListener(() => browser.runtime.openOptionsPage());
if (typeof browser === 'undefined') {
globalThis.browser = chrome;
}

browser.action.onClicked.addListener(() => browser.runtime.openOptionsPage());

// todo:
// global variable in non-persistent background script potentially problematic
// may need to store requestId in storage to make error handling 100% reliable
const handledRequests = new Map();

browser.webRequest.onBeforeRequest.addListener(({ method, requestBody, requestId, timeStamp, url }) => {
Expand Down
8 changes: 0 additions & 8 deletions src/lib/browser-polyfill.min.js

This file was deleted.

20 changes: 13 additions & 7 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"manifest_version": 2,
"manifest_version": 3,
"name": "Outbox for Tumblr",
"version": "1.0.4",

Expand All @@ -10,7 +10,7 @@
"128": "icons/128.png"
},

"browser_action": {
"action": {
"default_icon": {
"16": "icons/16.png",
"48": "icons/48.png",
Expand All @@ -19,27 +19,33 @@
},

"background": {
"scripts": [ "lib/browser-polyfill.min.js", "background.js" ],
"persistent": true
"scripts": [ "background.js" ],
"service_worker": "background.js",
"persistent": false
},
"homepage_url": "https://github.com/AprilSylph/Outbox-for-Tumblr#readme",
"permissions": [
"storage",
"webRequest",
"webRequest"
],
"host_permissions": [
"*://*.tumblr.com/*"
],
"optional_permissions": [
"<all_urls>"
],
"optional_host_permissions": [
"<all_urls>"
],
"options_ui": {
"page": "outbox.html",
"open_in_tab": true
},

"minimum_chrome_version": "80",
"minimum_chrome_version": "102",
"browser_specific_settings": {
"gecko": {
"strict_min_version": "74.0a1"
"strict_min_version": "127.0"
}
}
}
25 changes: 25 additions & 0 deletions src/outbox.css
Original file line number Diff line number Diff line change
Expand Up @@ -502,3 +502,28 @@ article details summary {
article details[open] summary {
display: none;
}

#permissions-banner {
box-sizing: border-box;
width: 375px;
min-width: 100%;
max-width: 100%;
padding: 8px 4px;
border-bottom: 1px solid rgb(var(--active-grey));

text-align: center;
}

#grant-host-permission {
display: block;
padding: 0.5ch 1ch;
border-radius: 0.5ch;
margin: 8px auto 0;

font-family: 'Courier New', Courier, monospace;
line-height: 1;
}

#grant-host-permission:focus {
outline: 2px solid rgb(var(--accent));
}
12 changes: 11 additions & 1 deletion src/outbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
<link rel="stylesheet" href="lib/npf.css">
<link rel="stylesheet" href="outbox.css">
<link rel="stylesheet" href="https://assets.tumblr.com/fonts/favorit/stylesheet.css">
<script src="lib/browser-polyfill.min.js"></script>
<script type="module" src="outbox.js"></script>
<script type="module" src="lib/navigation.js"></script>
</head>
<body>
<header id="permissions-banner" hidden>
&#x26A0;&#xFE0F; Outbox for Tumblr needs additional permissions in order to save Tumblr asks automatically.
<button id="grant-host-permission">Always allow on www.tumblr.com</button>
</header>
<div id="base-container">
<aside></aside>
<main aria-busy="true"></main>
Expand All @@ -33,6 +36,13 @@ <h1>Links</h1>
<li><a href="https://github.com/AprilSylph/Outbox-for-Tumblr" target="_blank">Source code</a></li>
</ul>
</section>
<section id="all-urls-section" hidden>
<h1>Custom Domains</h1>
<ul>
<!-- todo: this should be an unstyled button -->
<li><a id="grant-all-urls" href="#0">Enable on custom domains</a></li>
</ul>
</section>
</aside>
</div>
</body>
Expand Down
32 changes: 32 additions & 0 deletions src/outbox.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { renderContent } from './lib/npf.js';

if (typeof browser === 'undefined') {
globalThis.browser = chrome;
}

const anonymousAvatarSrc = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAMAAAC7IEhfAAACjlBMVEXq6uoAAADo6Oju7u6srKzz8/Py8vLp6emzs7Orq6uurq6tra0eHh4ZGRnw8PC0tLTn5+clJSW1tbWlpaWxsbHx8fGwsLCmpqYhISHt7e2vr6+ysrInJyeRkZGioqKenp6Wlpa3t7cfHx8dHR0gICAYGBiVlZUICAgmJiYbGxttbW1cXFwaGhqAgIAiIiLs7OyPj48XFxeZmZm+vr7a2trr6+twcHCqqqr09PTh4eEwMDAkJCSSkpIyMjIQEBBZWVkVFRUcHByXl5cREREuLi4qKirc3Nz////v7++BgYGgoKAxMTGTk5Ojo6OcnJxOTk4jIyNISEhxcXGGhobT09OCgoKLi4vm5ubo6OehoaEJCQnAwMDZ2tldXV2NjY06OjosLCzf4N9iYmLg4ODS0tJhYWFRUVFSUlKQkJBDQ0MSEhKJiYn4+PhHR0cWFhZlZWWKioq/v79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195csvU1vI47Dkrw3i0F3g0jp4nVjF2P/CZmOfma5g86t1W+QwmUwEfSF6XOlwoUTfLCw2lBDBgK2z3tLUaLQImiwHumeVqyxSJd0hVOl2Tps7ppHCWoolROlYPa8XlGwxdscihishzAly2cGon76REdpWU0MT5mXWE5hNY2rUlNzUiKhK+/2anGbHxwqwMqGa196mknZ7I4HCaO458ZF1xVxLNWVHfJYUlGaNtzOe3Wn72ze+bAShMTH5cViEnhtNAvgPzrb62ubGCTebJnyKzbgqi+NBTqygjK6q7w+wwmwSUXgG8ngD9qa6cD2OgrThTA+Eph/hR2dZZIUknnLuEFxj70kJKild15//6Xt1uhSYKdqvaamhK1N3WRPkL6H3qfoJ+KtxZaAAAAAElFTkSuQmCC';

const mainElement = document.querySelector('main');
Expand Down Expand Up @@ -175,3 +179,31 @@ browser.storage.onChanged.addListener(onStorageChanged);
updateExportDownload();

importInput.addEventListener('change', onImportInputChanged);

const permissionsBannerElement = document.getElementById('permissions-banner');
const permissionsButton = document.getElementById('grant-host-permission');
const updatePermissionsBannerVisibility = hasHostPermission => {
permissionsBannerElement.hidden = hasHostPermission;
};
permissionsButton.addEventListener('click', () => {
browser.permissions
.request({ origins: ['*://*.tumblr.com/*'] })
.then(updatePermissionsBannerVisibility);
});
browser.permissions
.contains({ origins: ['*://*.tumblr.com/*'] })
.then(updatePermissionsBannerVisibility);

const allUrlsSection = document.getElementById('all-urls-section');
const allUrlsButton = document.getElementById('grant-all-urls');
const updateAllUrlsSectionVisibility = hasHostPermission => {
allUrlsSection.hidden = hasHostPermission;
};
allUrlsButton.addEventListener('click', () => {
browser.permissions
.request({ origins: ['<all_urls>'] })
.then(updateAllUrlsSectionVisibility);
});
browser.permissions
.contains({ origins: ['<all_urls>'] })
.then(updateAllUrlsSectionVisibility);
Loading