Compare commits

..

12 Commits

Author SHA1 Message Date
mantaohuang
5aad0ed3c5 fix bug where popup height and width cannot be read from storage 2021-01-06 18:13:22 -05:00
mantaohuang
44691d3f86 generalize to other domains, changed icons 2020-12-22 14:15:26 -05:00
mantaohuang
83e01ebb56 request all links from shaarli 2020-11-22 13:07:07 -05:00
mantaohuang
115c71b873 auto login, indicates whether a page is bookmarked 2020-11-21 23:17:28 -05:00
ikipatang
ee03754735 Update Readme 2017-12-17 23:47:52 +01:00
ikipatang
828cf574d8 Release version 2.0.0 for Aeris AMO 2017-12-17 23:17:49 +01:00
ikipatang
d0ac9b7e4a Release v0.2.6 2017-12-07 20:25:41 +01:00
ikipatang
35392dda80 Update changelog 2017-12-07 20:16:57 +01:00
ikipatang
d8282bdcc4 Options: minimum dimension is 45px + UI is updated after save 2017-12-07 20:15:07 +01:00
ikipatang
af99a34045 Storage: add jsdoc 2017-12-07 19:56:21 +01:00
ikipatang
fdd0f7cfae Storage: fix unsaved settings after restart 2017-12-07 19:55:55 +01:00
ikipatang
b6770c0d7a Package.json: add script debug build that rm web-ext-build 2017-12-07 19:29:03 +01:00
22 changed files with 27221 additions and 77 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
examples
web-ext-artifacts
node_modules

3
.web-extension-id Normal file
View File

@ -0,0 +1,3 @@
# This file was created by https://github.com/mozilla/web-ext
# Your auto-generated extension ID for addons.mozilla.org is:
{898e31e7-f847-4444-ab44-06c731027963}

View File

@ -6,6 +6,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
## [2.0.0][] - 2017-12-17
## Changed
- Changed version to match shaarli extension
## [0.2.6][] - 2017-12-07
## Changed
- Extension settings update after save
## Added
- Popup dimensions cannot be less than 45px
## Fixed
- Fixed settings lost after restart
## [0.2.2][] - 2017-11-30
## Added
@ -28,7 +43,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Create toolbar button
- Sharing a link will send user to extension settings if no Shaarli URL is set
[Unreleased]: https://github.com/ikipatang/shaarli-web-extension/compare/v0.2.2...HEAD
[Unreleased]: https://github.com/ikipatang/shaarli-web-extension/compare/v2.0.0...HEAD
[2.0.0]: https://github.com/ikipatang/shaarli-web-extension/compare/v0.2.6...v2.0.0
[0.2.6]: https://github.com/ikipatang/shaarli-web-extension/compare/v0.2.2...v0.2.6
[0.2.2]: https://github.com/ikipatang/shaarli-web-extension/compare/0.1.0...v0.2.2
[0.1.0]: https://github.com/ikipatang/shaarli-web-extension/compare/0.0.2...0.1.0
[0.0.2]: https://github.com/ikipatang/shaarli-web-extension/tree/0.0.2

View File

@ -10,7 +10,7 @@ See [shaarli](https://github.com/shaarli/Shaarli).
So here we go for a Firefox Quantum Web-Extension.
## Where to find it
https://addons.mozilla.org/fr/firefox/addon/web-extension-for-shaarli/
[Aeris/shaarli](https://addons.mozilla.org/fr/firefox/addon/shaarli/) version on firefox library has been updated
## Features
- Share button in toolbar

View File

@ -1,29 +1,36 @@
{
"name": "Web Extension for Shaarli",
"description": "Share your link to your Shaarli on Firefox Quantum",
"version": "0.2.2",
"homepage_url": "https://github.com/ikipatang/shaarli-web-extension",
"name": "Web Extension for Shaarli modified",
"description": "Share your link to your Shaarli, test version",
"version": "2.0.4",
"homepage_url": "https://git.hmthsn.com/mantao/shaarli-web-extension",
"manifest_version": 2,
"icons": {
"48": "resources/icons/icon-48.png"
"48": "resources/icons/leaf_on.svg"
},
"permissions": [
"tabs",
"storage"
"storage",
"contextMenus"
],
"options_ui": {
"page": "src/options/options.html"
},
"background": {
"scripts": ["src/storage.js", "src/background.js"]
"page": "src/background-page.html"
},
"browser_action": {
"default_icon": "resources/icons/icon-24.png",
"default_icon": "resources/icons/leaf_on.svg",
"default_title": "Share"
},
"page_action": {
"browser_style": false,
"default_icon": "resources/icons/icon-24.png",
"default_icon": "resources/icons/leaf_on.svg",
"default_title": "Share"
}
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["src/login_close_helper.js"]
}
]
}

9766
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "shaarli-web-extension",
"version": "0.2.2",
"version": "2.0.0",
"description": "Share your link to your Shaarli on Firefox Quantum",
"main": "src/background.js",
"keywords": [
@ -12,18 +12,23 @@
"type": "git",
"url": "https://github.com/ikipatang/shaarli-web-extension.git"
},
"author": "5412352+ikipatang@users.noreply.github.com",
"author": "ikipatang",
"license": "GPL-3.0",
"devDependencies": {
"version-changelog": "^2.1.0",
"web-ext": "^2.2.2"
"web-ext": "^2.9.3"
},
"scripts": {
"slate": "rm -rf node_modules && yarn install",
"lint": "web-ext lint",
"start": "web-ext run",
"debug:build": "rm -rf web-ext-artifacts/*.zip && npm run build",
"build": "web-ext build",
"test": "echo \"Error: no test specified\" && exit 1",
"version": "version-changelog CHANGELOG.md"
},
"dependencies": {
"browserify": "^17.0.0",
"unirest": "^0.6.0"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 883 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
id="Capa_1"
enable-background="new 0 0 511.993 511.993"
height="512"
viewBox="0 0 511.993 511.993"
width="512"
version="1.1"
sodipodi:docname="leaf_off.svg"
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)">
<metadata
id="metadata11">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs9" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1563"
inkscape:window-height="980"
id="namedview7"
showgrid="false"
inkscape:zoom="1.3964844"
inkscape:cx="256"
inkscape:cy="256"
inkscape:window-x="934"
inkscape:window-y="384"
inkscape:window-maximized="0"
inkscape:current-layer="g4" />
<g
id="g4">
<path
d="m 468.96915,162.0373 -10.701,-53.485 -29.796,11.928 c -26.143,10.465 -54.025,20.268 -83.065,29.209 -12.826,-34.907 -32.205,-69.601003 -57.737,-103.333003 l -32.918,-43.4920005 -21.632,23.7100005 c -34.48,37.794 -73.39,74.532003 -118.953,112.313003 -35.960002,29.818 -61.419002,71.481 -71.688002,117.315 -10.586,47.252 -5.016,95.319 16.109,139.002 l 57.864002,119.652 h 63.29 c 55.325,0 104.264,-8.484 145.455,-25.218 39.054,-15.866 71.373,-39.179 96.06,-69.292 51.519,-62.847 68.463,-154.583 47.712,-258.309 z m -51.072,-5.322 c -19.736,39.773 -44.423,79.234 -73.709,117.704 -30.104,39.543 -65.078,78.129 -103.951,114.687 -40.547,38.133 -77.008,66.134 -99.377,82.236 v -94.987 c 0,-41.682 13.663,-80.93 39.513,-113.501 25.092,-31.617 60.357,-54.319 99.299,-63.925 15.797,-3.897 31.323,-8.001 46.339,-12.243 l 0.026,0.081 13.714,-4.043 c 0.13,-0.038 0.261,-0.076 0.391,-0.114 v -0.001 c 26.915,-7.938 52.962,-16.625 77.755,-25.894 z M 71.753148,262.7613 c 8.824,-39.388 30.688002,-75.179 61.563002,-100.78 45.469,-37.703 84.526,-74.458003 119.281,-112.255003 l 11.153,14.735 c 23.284,30.763 40.994,62.223003 52.8,93.722003 -14.288,4.021 -29.047,7.915 -44.064,11.619 -45.354,11.188 -86.413,37.612 -115.612,74.403 -30.103,37.931 -46.014,83.627 -46.014,132.151 v 58.031 l -25.265002,-52.243 c -18.147,-37.524 -22.933,-78.806 -13.842,-119.383 z m 326.302002,138.567 c -21.476,26.197 -49.787,46.558 -84.149,60.517 -37.589,15.27 -82.728,23.012 -134.164,23.012 h -6.549 c 22.67,-17.036 53.314,-41.699 87.069,-73.4 40.169,-37.725 76.346,-77.598 107.526,-118.512 28.848,-37.854 53.449,-76.695 73.483,-115.928 16.254,90.951 1.03,170.337 -43.216,224.311 z"
id="path2"
style="fill:#000000;fill-opacity:1;stroke:none;stroke-opacity:1" />
<path
style="fill:#969696;fill-opacity:0.25;stroke-width:13.5323"
d="M 98.526127,408.11424 C 92.063189,394.75295 85.251734,380.43748 83.389561,376.3021 67.654847,341.35954 63.66835,301.96838 71.984028,263.60236 c 4.63759,-21.39644 14.193939,-43.69133 26.892849,-62.74082 10.840663,-16.26196 20.600873,-26.61515 43.024303,-45.63825 36.37673,-30.86049 60.11267,-52.85085 90.4321,-83.781583 l 20.51941,-20.933117 9.71606,13.056194 c 18.08531,24.30258 29.3399,42.319046 40.36346,64.614236 8.47993,17.15068 13.43071,29.18386 12.27094,29.82531 -0.79631,0.44043 -9.58602,2.81551 -42.01714,11.35352 -7.68,2.02188 -18.31384,5.29288 -23.63077,7.26888 -68.19227,25.34328 -118.89673,83.76587 -134.22332,154.65451 -3.84201,17.77008 -4.20683,22.73612 -4.64494,63.22741 l -0.41006,37.89885 z"
id="path859"
transform="scale(0.99998633)" />
<path
style="fill:#969696;fill-opacity:0.25;stroke-width:13.5323"
d="m 141.62565,412.7514 0.27747,-57.57378 1.866,-10.02517 c 5.54306,-29.78034 16.49378,-54.83787 34.30986,-78.50806 12.1553,-16.14936 27.28929,-30.41618 44.26508,-41.72871 20.40595,-13.59837 36.07426,-20.23358 65.25402,-27.63373 41.50462,-10.52581 81.89324,-22.72454 116.55075,-35.20229 6.45416,-2.32369 11.88846,-4.07128 12.0762,-3.88353 0.18775,0.18775 -2.31244,5.4335 -5.55597,11.65723 -45.25414,86.83407 -117.43837,174.63117 -206.2271,250.83234 -17.87664,15.34228 -52.54437,42.77212 -61.08535,48.33204 l -2.00843,1.30743 z"
id="path861"
transform="scale(0.99998633)" />
<path
style="fill:#969696;fill-opacity:0.25;stroke-width:13.5323"
d="m 175.82418,483.48192 c 0.5767,-0.52188 6.36547,-5.10048 12.86393,-10.17466 35.1357,-27.43498 67.87836,-56.71765 100.96874,-90.29911 61.3109,-62.22083 108.75826,-125.38797 145.53669,-193.75446 l 6.05194,-11.2498 1.53269,10.53372 c 4.23298,29.09211 5.46863,55.70946 3.69692,79.63582 -9.20281,124.28091 -85.50998,199.31565 -217.32824,213.70424 -14.33223,1.56442 -31.23287,2.5531 -43.64332,2.5531 -8.95661,0 -10.55478,-0.15667 -9.67935,-0.94885 z"
id="path863"
transform="scale(0.99998633)" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
id="Capa_1"
enable-background="new 0 0 512 512"
height="512"
viewBox="0 0 512 512"
width="512"
version="1.1"
sodipodi:docname="leaf_on.svg"
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)">
<metadata
id="metadata15">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs13" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="2075"
inkscape:window-height="1497"
id="namedview11"
showgrid="false"
inkscape:zoom="1.3964844"
inkscape:cx="256"
inkscape:cy="256"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="0"
inkscape:current-layer="Capa_1" />
<g
id="g8"
transform="matrix(0.93896889,0,0,0.94951462,15.623984,12.924257)">
<path
d="M 113.707,512 55.575,391.792 C 11.881,301.441 37.477,195.524 111.417,134.213 157.444,96.047 201.357,55.401 241.656,11.229 L 251.9,0 275.721,31.473 c 29.393,38.834 51.822,80.128 65.073,121.97 z"
fill="#00aa95"
id="path2" />
<path
d="m 468.766,149.938 -7.743,-38.704 C 422.754,201.441 324.597,249.373 268.334,311.617 169.942,420.469 113.707,512 113.707,512 h 58.256 c 258.928,0 334.274,-174.759 296.803,-362.062 z"
fill="#00cc76"
id="path4" />
<path
d="m 461.022,111.234 -14.112,5.649 c -34.771,13.919 -70.217,25.975 -106.117,36.56 v 10e-4 c -21.412,6.314 -42.985,12.104 -64.674,17.454 -93.258,23.005 -162.413,107.214 -162.413,207.575 V 512 c 10e-4,0 242.122,-152.806 347.316,-400.766 z"
fill="#a5e887"
id="path6" />
</g>
<g
id="g4"
transform="matrix(1.0000137,0,0,1.0000137,-1.4234701,0)">
<path
d="m 467.537,159.173 -10.701,-53.485 -29.796,11.928 c -26.143,10.465 -54.025,20.268 -83.065,29.209 C 331.149,111.918 311.77,77.224 286.238,43.492 L 253.32,0 231.688,23.71 c -34.48,37.794 -73.39,74.532 -118.953,112.313 -35.96,29.818 -61.419,71.481 -71.688,117.315 -10.586,47.252 -5.016,95.319 16.109,139.002 l 57.864,119.652 h 63.29 c 55.325,0 104.264,-8.484 145.455,-25.218 39.054,-15.866 71.373,-39.179 96.06,-69.292 51.519,-62.847 68.463,-154.583 47.712,-258.309 z m -51.072,-5.322 c -19.736,39.773 -44.423,79.234 -73.709,117.704 -30.104,39.543 -65.078,78.129 -103.951,114.687 -40.547,38.133 -77.008,66.134 -99.377,82.236 v -94.987 c 0,-41.682 13.663,-80.93 39.513,-113.501 25.092,-31.617 60.357,-54.319 99.299,-63.925 15.797,-3.897 31.323,-8.001 46.339,-12.243 l 0.026,0.081 13.714,-4.043 c 0.13,-0.038 0.261,-0.076 0.391,-0.114 v -0.001 c 26.915,-7.938 52.962,-16.625 77.755,-25.894 z M 70.321,259.897 c 8.824,-39.388 30.688,-75.179 61.563,-100.78 45.469,-37.703 84.526,-74.458 119.281,-112.255 l 11.153,14.735 c 23.284,30.763 40.994,62.223 52.8,93.722 -14.288,4.021 -29.047,7.915 -44.064,11.619 -45.354,11.188 -86.413,37.612 -115.612,74.403 -30.103,37.931 -46.014,83.627 -46.014,132.151 v 58.031 L 84.163,379.28 C 66.016,341.756 61.23,300.474 70.321,259.897 Z m 326.302,138.567 c -21.476,26.197 -49.787,46.558 -84.149,60.517 -37.589,15.27 -82.728,23.012 -134.164,23.012 h -6.549 c 22.67,-17.036 53.314,-41.699 87.069,-73.4 40.169,-37.725 76.346,-77.598 107.526,-118.512 28.848,-37.854 53.449,-76.695 73.483,-115.928 16.254,90.951 1.03,170.337 -43.216,224.311 z"
id="path2-6" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
shaarli-web-extension.xpi Normal file

Binary file not shown.

13
src/background-page.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="lib/jquery-3.5.1.js"></script>
<script src="lib/crypto-js.js"></script>
<script src="lib/client.js"></script>
<script type="module" src="storage.js"></script>
<script type="module" src="background.js"></script>
</head>
</html>

View File

@ -5,6 +5,7 @@
* @param {number} height -
* @return {void} -
*/
function openInPopup(url, width, height) {
browser.windows.create({
url,
@ -12,9 +13,9 @@ function openInPopup(url, width, height) {
allowScriptsToClose: true,
width,
height,
});
})
}
var last_tab;
/**
* Share Current Tab
* @return {void} -
@ -22,7 +23,7 @@ function openInPopup(url, width, height) {
function shareCurrentTab(tab) {
const url = tab.url;
const title = tab.title || url;
browser.storage.local.get().then((storage) => {
browser.storage.local.get(["url","popupWidth","popupHeight"]).then((storage) => {
if(!storage.url){
browser.runtime.openOptionsPage();
return;
@ -38,7 +39,7 @@ function shareCurrentTab(tab) {
* @return {void} -
*/
function showPageAction(tabId){
browser.storage.local.get().then((storage) => {
browser.storage.local.get("pageAction").then((storage) => {
storage.pageAction ? browser.pageAction.show(tabId) : browser.pageAction.hide(tabId);
});
}
@ -59,9 +60,138 @@ browser.tabs.query({active: true, currentWindow: true}).then((tabs) => {
showPageAction(tabs[0].id);
});
async function getCurrentTab() {
// Get active tabs in current window
var tabs = await browser.tabs.query({
currentWindow: true,
active: true,
});
if (tabs.length < 1) {
throw new Error("no tab available");
}
// Make sure URL protocol supported
var supportedProtocols = ["https:", "http:", "ftp:", "file:"],
activeTab = tabs[0],
url = document.createElement('a');
if (activeTab.url !== "") {
url.href = activeTab.url;
if (supportedProtocols.indexOf(url.protocol) === -1) {
throw new Error(`protocol "${url.protocol}" is not supported`);
}
}
last_tab = activeTab
return activeTab;
}
async function findLocalBookmark(url){
let data = await browser.storage.local.get("links");
let result = data.links.hasOwnProperty(url);
return result
}
async function updateIcon() {
// Set initial icon
var runtimeUrl = await browser.runtime.getURL("/"),
icon = {path: {
16: "../resources/icons/leaf_off.svg",
32: "../resources/icons/leaf_off.svg",
64: "../resources/icons/leaf_off.svg"
}};
// Firefox allows using empty object as default icon.
// This way, Firefox will use default_icon that defined in manifest.json
// if (runtimeUrl.startsWith("moz")) {
// icon = {};
// }
// Get current active tab
try {
var tab = await getCurrentTab()
var local = await findLocalBookmark(tab.url);
if (local) icon.path = {
16: "../resources/icons/leaf_on.svg",
32: "../resources/icons/leaf_on.svg",
64: "../resources/icons/leaf_on.svg"
}
// console.log("tab:", tab);
// icon.tabId = tab.id;
// browser.pageAction.setIcon(icon);
} catch {}
return browser.browserAction.setIcon(icon);
}
function updateActiveTab() {
updateIcon().catch(err => console.error(err.message));
}
/*
Listeners
*/
browser.tabs.onActivated.addListener(tabActivation);
browser.browserAction.onClicked.addListener(shareCurrentTab);
browser.pageAction.onClicked.addListener(shareCurrentTab);
browser.tabs.onUpdated.addListener(updateActiveTab);
browser.tabs.onActivated.addListener(updateActiveTab);
browser.windows.onFocusChanged.addListener(updateActiveTab);
updateActiveTab();
let onCreated = console.log;
browser.contextMenus.create({
id: "log-selection",
title: "Sync bookmarks",
contexts: ["all"]
}, onCreated);
async function sync_links(){
// get server url from storage
var storage_server_url = await browser.storage.local.get("url")
if(!storage_server_url.url){
return
}
let server_url = storage_server_url.url;
// get token from storage
var storage_token = await browser.storage.local.get("token")
if(!storage_token.token){
return
}
let token = storage_token.token;
// construct api url
let api_url = new URL(server_url);
api_url.pathname = "/api/v1/links";
api_url.searchParams.append("limit", "all");
// get links
var result = await getLinks(token, api_url.href);
// generate link dictionary
let links = {}
result.forEach((value)=>{
links[value.url] = true;
})
// save link dictionary
browser.storage.local.set({"links":links});
}
browser.contextMenus.onClicked.addListener(async function(info, tab) {
await sync_links();
})
browser.runtime.onMessage.addListener(async (message) => {
if (message === "sync") {
await new Promise(r => setTimeout(r, 1000));
await sync_links();
await new Promise(r => setTimeout(r, 100));
updateIcon();
}
});
console.log("addon loaded");
sync_links();
browser.storage.local.set({"attempt":0});

26
src/lib/client.js Normal file
View File

@ -0,0 +1,26 @@
var base64url = function(aStr) { return btoa(aStr.replace(/\+/g,'-').replace(/\//g,'_')).replace(/\=+$/m,'') }
function generateToken(secret){
header = base64url(`{
"typ": "JWT",
"alg": "HS512"
}`);
payload = base64url(`{
"iat": ${Math.floor(Date.now() / 1000)}
}`)
var hash = CryptoJS.HmacSHA512(header + '.'+ payload, secret);
var signature = hash.toString(CryptoJS.enc.Base64).replace(/\=+$/m,'').replaceAll('/','_').replaceAll('+','-');
return header + "." + payload + "." + signature
}
async function getLinks(api_token, url){
let token = generateToken(api_token)
var result = await $.ajax(
{
url: url,
type: 'GET',
headers:{"Authorization": 'Bearer ' + token}
} )
return result
}

6059
src/lib/crypto-js.js Normal file

File diff suppressed because it is too large Load Diff

10872
src/lib/jquery-3.5.1.js vendored Normal file

File diff suppressed because it is too large Load Diff

27
src/login_close_helper.js Normal file
View File

@ -0,0 +1,27 @@
(function() {
browser.storage.local.get("url", (storage)=>{
server_url = storage.url;
if(!server_url){
return
}
server_host = new URL(server_url).host;
if(window.location.host==server_host){
if (window.location.pathname=="/login"){
browser.storage.local.get().then(async (storage) => {
if(storage.attempt==0 && storage.login.length && storage.password.length){
await browser.storage.local.set({
attempt: 1
})
document.getElementsByName("login")[0].value=storage.login
document.getElementsByName("password")[0].value=storage.password
document.getElementsByName("loginform")[0].submit()
}
})
}
window.onbeforeunload = function() {
browser.runtime.sendMessage("sync");
}
}
})
})();

View File

@ -1,38 +1,59 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="options.css"/>
</head>
<body>
<div class="main">
<div class="row">
<label>
<span>Shaarli URL</span>
<input id="url" type="text" name="url">
</label>
</div>
<div class="row">
<label>
<span>Popup dimensions (px)</span>
<input id="popupWidth" type="text" name="popupWidth"><input id="popupHeight" type="text" name="popupWidth"> (default : 900 x 600)
</label>
</div>
<div class="row">
<label>
<span>Address bar</span>
<input id="pageAction" type="checkbox" name="pageAction" checked>
</label>
</div>
<div class="row">
<span>&nbsp;</span>
<button id="save-button" type="submit">Save preferences</button>
</div>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="options.css" />
</head>
<body>
<div class="main">
<div class="row">
<label>
<span>Shaarli URL</span>
<input id="url" type="text" name="url">
</label>
</div>
<script src="options.js"></script>
</body>
<div class="row">
<label>
<span>Shaarli API Token</span>
<input id="token" type="text" name="token">
</label>
</div>
<div class="row">
<label>
<span>Shaarli User</span>
<input id="login" type="text" name="login">
</label>
</div>
<div class="row">
<label>
<span>Shaarli Password</span>
<input id="password" type="text" name="password">
</label>
</div>
<div class="row">
<label>
<span>Popup dimensions (px)</span>
<input id="popupWidth" type="text" name="popupWidth"><input id="popupHeight" type="text" name="popupWidth">
(default : 900 x 900)
</label>
</div>
<div class="row">
<label>
<span>Address bar</span>
<input id="pageAction" type="checkbox" name="pageAction" checked>
</label>
</div>
<div class="row">
<span>&nbsp;</span>
<button id="save-button" type="submit">Save preferences</button>
</div>
</div>
<div>Icons made by <a href="https://www.flaticon.com/authors/freepik" title="Freepik">Freepik</a> from <a
href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a></div>
<script src="options.js"></script>
</body>
</html>

View File

@ -1,17 +1,16 @@
/**
* Store options UI using browser.storage.local.
* @return {void} -
* ParseInt with minimum dimension of 45px
* @param {string} dimension -
* @return {int} -
*/
function storeSettings() {
const settings = {
url: document.querySelector("#url").value,
popupWidth: parseInt(document.querySelector("#popupWidth").value),
popupHeight: parseInt(document.querySelector("#popupHeight").value),
pageAction: document.querySelector("#pageAction").checked,
};
// console.log('storeSettings settings');
// console.log(settings);
browser.storage.local.set(settings);
function parseIntDimension(dimension){
const minDimension = 45;
let parsedDimension = parseInt(dimension);
if(isNaN(parsedDimension) || parsedDimension < minDimension){
parsedDimension = minDimension;
}
return parsedDimension;
}
/**
@ -24,16 +23,56 @@ function updateUI(restoredSettings) {
// console.log('restoredSettings');
// console.dir(restoredSettings, { depth: 10, colors: true }); // DEBUG
// Get HTML input
const url = document.querySelector("#url");
url.value = restoredSettings.url;
const popupWidth = document.querySelector("#popupWidth");
popupWidth.value = restoredSettings.popupWidth;
const popupHeight = document.querySelector("#popupHeight");
popupHeight.value = restoredSettings.popupHeight;
const pageAction = document.querySelector("#pageAction");
const token = document.querySelector("#token");
const login = document.querySelector("#login");
const password = document.querySelector("#password");
// Set HTML input with stored values
url.value = restoredSettings.url;
popupWidth.value = restoredSettings.popupWidth;
popupHeight.value = restoredSettings.popupHeight;
pageAction.checked = restoredSettings.pageAction;
token.value = restoredSettings.token;
login.value = restoredSettings.login;
password.value = restoredSettings.password;
}
/**
* Store options UI using browser.storage.local.
* @return {void} -
*/
function storeSettings() {
const url = document.querySelector("#url");
const popupWidth = document.querySelector("#popupWidth");
const popupHeight = document.querySelector("#popupHeight");
const pageAction = document.querySelector("#pageAction");
const token = document.querySelector("#token");
const login = document.querySelector("#login");
const password = document.querySelector("#password");
const settings = {
url: url.value,
popupWidth: parseIntDimension(popupWidth.value),
popupHeight: parseIntDimension(popupHeight.value),
pageAction: pageAction.checked,
token: token.value,
login: login.value,
password: password.value,
attempt: 0
};
// console.log('storeSettings settings');
// console.log(settings);
// Store in storage
browser.storage.local.set(settings);
// Update UI
updateUI(settings);
}
/**

View File

@ -5,22 +5,30 @@ var storage = {
url: '',
pageAction: false,
popupWidth: 900,
popupHeight: 600,
popupHeight: 900,
login: "",
password: "",
token: "",
attempt: 0
}
/*
Generic error logger.
*/
/**
* Generic error logger.
* @param {object} e -
* @return {void} -
*/
function onError(e) {
console.error(e);
}
/*
On startup, check whether we have stored settings.
If we don't, then store the default settings.
*/
/**
* On startup, check whether we have stored settings.
* If we don't, then store the default settings.
* @param {object} storedSettings -
* @return {void} -
*/
function checkStoredSettings(storedSettings) {
if (!storedSettings.storage) {
if (storedSettings.url === undefined) {
browser.storage.local.set(storage);
}
}