First demo is possible

This commit is contained in:
Quentin 2022-03-23 18:25:29 +01:00
parent 1a08e1a4e5
commit 9b7ec52ef6
7 changed files with 274 additions and 65 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
*.swp *.swp
popup/config.js

View file

@ -6,8 +6,12 @@
"browser_action": { "browser_action": {
"default_icon": "icons/fanzine-32.png", "default_icon": "icons/fanzine-32.png",
"default_title": "Fanzine", "default_title": "Fanzine",
"default_popup": "popup/choose_action.html#home" "default_popup": "popup/fanzine.html#home"
}, },
"permissions": [
"*://garage.deuxfleurs.fr/*",
"webRequest"
],
"browser_specific_settings": { "browser_specific_settings": {
"gecko": { "gecko": {
"id": "fanzine@deuxfleurs.fr" "id": "fanzine@deuxfleurs.fr"

95
popup/aws-sdk.js Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,64 +0,0 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
* {
font-family: Helvetica, Verdana, Arial, sans-serif;
}
body {
min-width: 300px;
}
.menu-elem, .menu-title {
padding: 0.2rem 0.5rem 0.4rem 0.5rem;
margin: 0.3rem;
user-select: none;
}
.menu-title {
font-weight: bold;
border-bottom: 2px solid #1eb35a;
}
.menu-elem {
border-radius: 5px;
}
.menu-elem:hover {
background-color: #ddd;
}
.menu-elem:after {
content: ">";
text-align: right;
float:right;
}
section {
display: none;
}
section:target {
display: block;
}
</style>
</head>
<body>
<section id="home">
<div class="menu-title">Publier sur mon site web</div>
<div class="menu-elem">Texte brut</div>
<div class="menu-elem">Brève</div>
<div class="menu-elem">Galerie photo</div>
<div class="menu-elem">Fichiers</div>
<div class="menu-elem">Podcast</div>
</section>
<section id="plain-text">
<div class="menu-title">Text brut</div>
</section>
</body>
</html>

7
popup/config.sample.js Normal file
View file

@ -0,0 +1,7 @@
const bucketName = "quentin.dufour.io";
const bucketRegion = "garage";
const key = 'xxx';
const secret = 'xxx';
const host = 'https://quentin.dufour.io';
const endpoint = 'https://garage.deuxfleurs.fr';

121
popup/fanzine.html Normal file
View file

@ -0,0 +1,121 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
:root {
--main-color: #1eb35a;
}
/* Generic parameters */
* {
font-family: Helvetica, Verdana, Arial, sans-serif;
}
body {
min-width: 300px;
}
/* Navigation logic */
section {
display: none;
}
section:target {
display: block;
}
/* Components definition */
a {
text-decoration: none;
color: #111;
border-radius: 5px;
}
a:hover {
background-color: #ddd;
}
a.primary {
padding: 0.2rem 0.5rem 0.4rem 0.5rem;
display: block;
text-align: center;
color: #fff;
background-color: var(--main-color);
}
textarea {
font-family: monospace;
margin: 1rem 0rem;
resize: none;
box-sizing: border-box;
width: 100%;
height: 300px;
padding: 0.5rem;
line-height: 1.5;
border-radius: 5px;
border: 1px solid #ccc;
/*box-shadow: 1px 1px 1px #999;*/
}
/* Menu interface */
.menu-elem, .menu-title {
display: block;
padding: 0.2rem 0.5rem 0.4rem 0.5rem;
margin: 0.3rem;
user-select: none;
}
.menu-title {
font-weight: bold;
border-bottom: 2px solid var(--main-color);
}
.menu-title > a {
padding: 0.2rem 0.5rem 0.4rem 0.5rem;
margin: 0.3rem;
}
.menu-elem:after {
content: ">";
text-align: right;
float:right;
}
hr {
border: none;
border-bottom: 1px solid #ccc;
}
</style>
</head>
<body>
<section id="home">
<div class="menu-title">Publier sur mon site web</div>
<a class="menu-elem" href="#plain-text">Texte brut</a>
<div class="menu-elem">Brève</div>
<div class="menu-elem">Galerie photo</div>
<div class="menu-elem">Fichiers</div>
<div class="menu-elem">Podcast</div>
<hr>
<div class="menu-elem">Manuellement</div>
<div class="menu-elem">Paramètres</div>
</section>
<section id="plain-text">
<div class="menu-title"><a href="#home">&lt;</a> Texte brut</div>
<textarea id="plain-text-content" placeholder="Collez votre texte à partager ici"></textarea>
<a class="primary" id="plain-text-send" href="#plain-text-done">Envoyer</a>
</section>
<section id="plain-text-done">
<div id="output">Please wait...</div>
</section>
<script src="aws-sdk.js"></script>
<script src="config.js"></script>
<script src="fanzine.js"></script>
</body>
</html>

45
popup/fanzine.js Normal file
View file

@ -0,0 +1,45 @@
AWS.config.update({
region: bucketRegion,
s3: { endpoint: endpoint },
credentials: new AWS.Credentials({
accessKeyId: key,
secretAccessKey: secret,
})
});
const s3 = new AWS.S3({
apiVersion: "2006-03-01",
params: { Bucket: bucketName }
});
document
.querySelector("#plain-text-send")
.addEventListener("click", () => {
const identifier = new Uint8Array(30);
window.crypto.getRandomValues(identifier);
const ib64 = btoa(String.fromCharCode(...identifier));
const path = `paste/${ib64}.txt`;
const params = {
Bucket: bucketName,
Key: path,
ContentType: 'text/plain',
Body: document.querySelector("#plain-text-content").value
};
// Uploading files to the bucket
s3.upload(params, function(err, data) {
if (err) {
throw err;
}
const url = `${host}/${path}`;
browser.tabs.create({
url: url,
active: true,
})
document.querySelector("#output").innerHTML = `Succès, votre texte est disponible à cette adresse : ${url}`;
});
})