1
0
Fork 0

ENERGIZE!

This commit is contained in:
smpl 2022-05-05 05:13:58 +02:00
commit 54765b9138
8 changed files with 345 additions and 0 deletions

22
_locales/en/messages.json Normal file
View file

@ -0,0 +1,22 @@
{
"menuItemShareLink": {
"message": "Share Link",
"description": "Share the right-clicked link."
},
"menuItemSharePage": {
"message": "Share Page",
"description": "Share current page."
},
"menuItemShareImage": {
"message": "Share Link to Image",
"description": "Share link to the right-clicked image."
},
"menuItemShareFrame": {
"message": "Share Link to IFrame",
"description": "Share link to the right-clicked iframe."
},
"menuItemShareSelection": {
"message": "Share Selected Text",
"description": "Share the selected text."
}
}

View file

@ -0,0 +1,38 @@
<?xml version="1.0" standalone="no"?>
<svg
xmlns="http://www.w3.org/2000/svg"
version="1.1"
viewBox="0 0 57.883159 57.88316"
height="57.88316mm"
width="57.88316mm">
<rect
ry="6.0133438"
y="7.293541"
x="0.85941321"
height="43.296078"
width="56.164337"
style="fill:#282c37;stroke:#1b1e25;stroke-width:1.71882558;" />
<path
style="fill:#3088d4"
d="m 36.173854,31.935902 c -0.412679,2.12307 -3.696111,4.44656 -7.467135,4.89685 -1.966427,0.23464 -3.902531,0.4503 -5.96706,0.3556 -3.376344,-0.15469 -6.040514,-0.80589 -6.040514,-0.80589 0,0.32868 0.02027,0.64164 0.06081,0.93432 0.438947,3.33208 3.304025,3.53169 6.017975,3.62476 2.739247,0.0937 5.178349,-0.67536 5.178349,-0.67536 l 0.112534,2.47639 c 0,0 -1.915997,1.02886 -5.329151,1.2181 -1.882107,0.10345 -4.219053,-0.0474 -6.940949,-0.7678 -5.903334,-1.5625 -6.918572,-7.85516 -7.073914,-14.24009 -0.04735,-1.89573 -0.01816,-3.6833 -0.01816,-5.17835 0,-6.52892 4.277753,-8.44265 4.277753,-8.44265 2.156956,-0.99058 5.858093,-1.40716 9.705815,-1.43862 h 0.09453 c 3.847723,0.0315 7.551293,0.44804 9.708087,1.43862 0,0 4.27759,1.91373 4.27759,8.44265 0,0 0.05367,4.81707 -0.59656,8.16147" />
<path
style="fill:#ffffff"
d="m 31.724706,24.280932 v 7.90543 h -3.131981 v -7.67307 c 0,-1.61747 -0.680555,-2.43845 -2.041827,-2.43845 -1.505102,0 -2.259437,0.97389 -2.259437,2.89962 v 4.19991 h -3.113495 v -4.19991 c 0,-1.92573 -0.754497,-2.89962 -2.259599,-2.89962 -1.361272,0 -2.041827,0.82098 -2.041827,2.43845 v 7.67307 h -3.131981 v -7.90543 c 0,-1.61569 0.411381,-2.89962 1.237712,-3.84951 0.852113,-0.94989 1.968048,-1.43683 3.353319,-1.43683 1.602719,0 2.816432,0.61602 3.618925,1.84822 l 0.780117,1.30776 0.780279,-1.30776 c 0.802332,-1.2322 2.016046,-1.84822 3.618926,-1.84822 1.385109,0 2.501044,0.48694 3.353319,1.43683 0.826168,0.94989 1.23755,2.23382 1.23755,3.84951" />
<path
style="fill:none;stroke:#3088d4;stroke-width:2.11666656"
d="m 48.419887,32.162002 -9.710952,6.3391 11.059692,3.91135" />
<g style="fill:#3088d4;">
<circle
cx="49.161694"
cy="31.555061"
r="3.5741699" />
<circle
r="3.5741699"
cy="38.56852"
cx="38.911243" />
<circle
cx="49.688114"
cy="42.478706"
r="3.5741699" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.2 KiB

View file

@ -0,0 +1,38 @@
<?xml version="1.0" standalone="no"?>
<svg
xmlns="http://www.w3.org/2000/svg"
version="1.1"
viewBox="0 0 57.883159 57.88316"
height="57.88316mm"
width="57.88316mm">
<rect
ry="6.0133438"
y="7.293541"
x="0.85941321"
height="43.296078"
width="56.164337"
style="fill:#d9e1e8;stroke:#c6d2dc;stroke-width:1.71882558" />
<path
style="fill:#3088d4"
d="m 36.173854,31.935902 c -0.412679,2.12307 -3.696111,4.44656 -7.467135,4.89685 -1.966427,0.23464 -3.902531,0.4503 -5.96706,0.3556 -3.376344,-0.15469 -6.040514,-0.80589 -6.040514,-0.80589 0,0.32868 0.02027,0.64164 0.06081,0.93432 0.438947,3.33208 3.304025,3.53169 6.017975,3.62476 2.739247,0.0937 5.178349,-0.67536 5.178349,-0.67536 l 0.112534,2.47639 c 0,0 -1.915997,1.02886 -5.329151,1.2181 -1.882107,0.10345 -4.219053,-0.0474 -6.940949,-0.7678 -5.903334,-1.5625 -6.918572,-7.85516 -7.073914,-14.24009 -0.04735,-1.89573 -0.01816,-3.6833 -0.01816,-5.17835 0,-6.52892 4.277753,-8.44265 4.277753,-8.44265 2.156956,-0.99058 5.858093,-1.40716 9.705815,-1.43862 h 0.09453 c 3.847723,0.0315 7.551293,0.44804 9.708087,1.43862 0,0 4.27759,1.91373 4.27759,8.44265 0,0 0.05367,4.81707 -0.59656,8.16147" />
<path
style="fill:#ffffff"
d="m 31.724706,24.280932 v 7.90543 h -3.131981 v -7.67307 c 0,-1.61747 -0.680555,-2.43845 -2.041827,-2.43845 -1.505102,0 -2.259437,0.97389 -2.259437,2.89962 v 4.19991 h -3.113495 v -4.19991 c 0,-1.92573 -0.754497,-2.89962 -2.259599,-2.89962 -1.361272,0 -2.041827,0.82098 -2.041827,2.43845 v 7.67307 h -3.131981 v -7.90543 c 0,-1.61569 0.411381,-2.89962 1.237712,-3.84951 0.852113,-0.94989 1.968048,-1.43683 3.353319,-1.43683 1.602719,0 2.816432,0.61602 3.618925,1.84822 l 0.780117,1.30776 0.780279,-1.30776 c 0.802332,-1.2322 2.016046,-1.84822 3.618926,-1.84822 1.385109,0 2.501044,0.48694 3.353319,1.43683 0.826168,0.94989 1.23755,2.23382 1.23755,3.84951" />
<path
style="fill:none;stroke:#3088d4;stroke-width:2.11666656"
d="m 48.419887,32.162002 -9.710952,6.3391 11.059692,3.91135" />
<g style="fill:#3088d4;">
<circle
cx="49.161694"
cy="31.555061"
r="3.5741699" />
<circle
r="3.5741699"
cy="38.56852"
cx="38.911243" />
<circle
cx="49.688114"
cy="42.478706"
r="3.5741699" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.2 KiB

38
manifest.json Normal file
View file

@ -0,0 +1,38 @@
{
"manifest_version": 2,
"name": "Mastodon Share",
"version": "0.1",
"default_locale": "en",
"description": "Share links on Mastodon",
"browser_specific_settings": {
"gecko": {
"id": "mastodonshare@slamkode.ml",
"strict_min_version": "57.0"
}
},
"background": {
"scripts": ["mastodonshare.js"]
},
"permissions": ["contextMenus", "storage"],
"browser_action": {
"default_icon": "icons/mastodon-share-light.svg",
"default_title": "Share on Mastodon",
"default_popup": "popup.html",
"theme_icons": [
{
"light": "icons/mastodon-share-light.svg",
"dark": "icons/mastodon-share-dark.svg",
"size": 16
},
{
"light": "icons/mastodon-share-light.svg",
"dark": "icons/mastodon-share-dark.svg",
"size": 32
}
]
}
}

110
mastodonshare.js Normal file
View file

@ -0,0 +1,110 @@
var data = {
account: "",
sharebase: ""
};
function SetupAccount(result)
{
if(!result.account) {
console.log("No account in storage.");
return;
}
data.account = result.account;
if(data.account.charAt(0) == '@') {
data.account = data.account.substring(1);
}
var uriparts = data.account.split('@');
if(uriparts.length < 2)
return;
data.sharebase = 'https://' + uriparts[1] + '/share?text=';
}
browser.storage.local.get("account").then(SetupAccount);
browser.contextMenus.create({
id: "share-link",
title: browser.i18n.getMessage("menuItemShareLink"),
contexts: ["link"]
});
browser.contextMenus.create({
id: "share-page",
title: browser.i18n.getMessage("menuItemSharePage"),
contexts: ["page"]
});
browser.contextMenus.create({
id: "share-image",
title: browser.i18n.getMessage("menuItemShareImage"),
contexts: ["image"]
});
browser.contextMenus.create({
id: "share-frame",
title: browser.i18n.getMessage("menuItemShareFrame"),
contexts: ["frame"]
});
browser.contextMenus.create({
id: "share-selection",
title: browser.i18n.getMessage("menuItemShareSelection"),
contexts: ["selection"]
});
browser.contextMenus.onClicked.addListener((info, tab) =>
{
var text;
if(data.account === "") {
console.log("Error: No account.");
return;
}
switch (info.menuItemId) {
case "share-link": {
text = info.linkUrl;
break;
}
case "share-page": {
text = info.pageUrl
break;
}
case "share-image": {
text = info.srcUrl;
break;
}
case "share-frame": {
text = info.frameUrl;
break;
}
case "share-selection": {
text = info.selectionText;
break;
}
default: {
return;
}
}
browser.tabs.update({
"url": data.sharebase + encodeURIComponent(text)
});
});
browser.runtime.onMessage.addListener( async (msg) => {
if(msg.key === "getAccount") {
browser.storage.local.get("account").then(SetupAccount);
return data.account;
}
if(msg.key === "setAccount") {
browser.storage.local.set({
account: msg.value
}).then( result => {
data.account = msg.value;
});
return;
}
});

63
popup.css Normal file
View file

@ -0,0 +1,63 @@
@media (prefers-color-scheme: dark) {
body {
background: #282c37 !important;
color: #9baec8 !important;
}
.mastodon-widget-title {
color: #fff !important;
}
.mastodon-widget-input {
background: #131419 !important;
color: #fff !important;
}
}
body {
background: #d9e1e8;
color: #282c37;
}
.mastodon-widget-container {
font-family: "Roboto",Roboto,sans-serif;
margin: 2px auto;
padding: 20px;
font-weight: 400;
font-size: 13px;
line-height: 18px;
}
.mastodon-widget-input {
border: 0;
border-radius: 4px;
margin: 8px 0;
padding: 10px;
width: 100%;
box-sizing: border-box;
font-family: inherit;
font-weight: 500;
font-size: 18px;
background: #f9fafb;
color: #000;
}
.mastodon-widget-title {
text-align: center;
font-size: 18px;
font-weight: 500;
margin: 0;
color: #282c37;
}
.mastodon-widget-button {
display: block;
width: 100%;
border: 0;
border-radius: 4px;
margin: 8px 0;
padding: 10px;
background: #2b90d9;
color: #fff;
font-family: inherit;
font-weight: 500;
font-size: 18px;
line-height: inherit;
text-align: center;
text-transform: uppercase;
box-sizing: border-box;
cursor: pointer;
}

11
popup.html Normal file
View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="popup.css" type="text/css" />
<body>
<div class="mastodon-widget-container">
<p class="mastodon-widget-title">Mastodon Account</p>
<input class="mastodon-widget-input" type="text" name="account" />
<button class="mastodon-widget-button">Save</button>
</div>
<script src="popup.js" type="application/javascript"></script>
</body>

25
popup.js Normal file
View file

@ -0,0 +1,25 @@
function saveOptions(e)
{
browser.runtime.sendMessage(
{
"key": "setAccount",
"value": document.querySelector(".mastodon-widget-input").value
}
).then(
response => {
window.close();
}
);
}
document.addEventListener("DOMContentLoaded", function() {
document.removeEventListener("DOMContentLoaded", this);
browser.runtime.sendMessage({"key": "getAccount"}).then(
response => {
document.querySelector(".mastodon-widget-input").value = response;
}
);
document.querySelector(".mastodon-widget-button").addEventListener("click", saveOptions);
});