diff --git a/funiter-answer.js.js b/funiter-answer.js.js new file mode 100644 index 0000000..1cfd5c3 --- /dev/null +++ b/funiter-answer.js.js @@ -0,0 +1,19 @@ + +let answerButtonWrapper = document.createElement('nav') +answerButtonWrapper.style.position = 'fixed' +answerButtonWrapper.style.bottom = '0' +answerButtonWrapper.style.width = '100%' +answerButtonWrapper.style.zIndex = '666' +answerButtonWrapper.style.textAlign = 'center' + +let answerButton = document.createElement('button') +answerButton.innerHTML = 'Répondre' +answerButton.classList.add("btn-primary", "btn", "btn-icon-text") + +answerButtonWrapper.append(answerButton) +document.body.append(answerButtonWrapper) + +answerButton.addEventListener('click', function () { + alert('coucou') +}) + diff --git a/funiter.js b/funiter.js new file mode 100644 index 0000000..6b6e3ad --- /dev/null +++ b/funiter.js @@ -0,0 +1,252 @@ +const gateway = 'gateway.pinata.cloud'; +// const gateway = 'ipfs.copylaradio.com'; +// const gateway = 'libra.copylaradio.com'; + +const answersId = 'Qmde15Aqjvz59s38ma3UhGTbKnwJtS5wYDwKRuQQrrc7mD'; +let feedUrl = 'http://' + gateway + '/ipfs/' + answersId; +// let url = 'ipfs:///ipfs/' + answersId; + +let jsToDOM = function (rootElt, children) { + + for (const child of children) { + + let elt = document.createElement(child.tag) + + if (child.classList !== undefined) { + + for (const aCSSClass of child.classList) { + + elt.classList.add(aCSSClass) + } + } + + if (child.props !== undefined) { + + for (const property in child.props) { + + elt[property] = child.props[property] + } + } + + if (child.children !== undefined) { + + elt = jsToDOM(elt, child.children) + + } else { + + if (child.innerHTML !== undefined) { + + elt.innerHTML = child.innerHTML + } + } + + rootElt.append(elt) + } + + return rootElt +} + +let vaChercher = async function (pageUrl) { + + var myHeaders = new Headers(); + + let options = { + method: 'GET', // *GET, POST, PUT, DELETE, etc. + // mode: 'no-cors', // no-cors, *cors, same-origin + cache: 'default', // *default, no-cache, reload, force-cache, only-if-cached + credentials: 'omit', // include, *same-origin, omit + // headers: myHeaders, + headers: { "Content-Type": "application/json" }, + redirect: 'follow', // manual, *follow, error + referrerPolicy: 'no-referrer' // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url + }; + + // console.log(url); + + fetch(feedUrl, options) + .then(r => { + + if (!r.ok) { + + throw new Error('Network response was not OK'); + } + + return r.json() + }) + .then(jason => { + + for (const item of jason) { + + let whereChild = document.querySelector('[data-post-id="'+item.position+'"]') + let where = whereChild.parentNode + + let message = { + + author : 'boris' + , relativeDate : '2022-12-27' + , contents : item.message + , userAvatarSrc : browser.runtime.getURL("icons/tails.png") + } + + let freeUserSymbol = browser.runtime.getURL("icons/funiter-48.png") + + let messageWrapperElt = document.createElement("div") + messageWrapperElt.classList.add("topic-post", "clearfix", "regular", "sticky-avatar") + + let template = [ + { + tag : 'article' + , classList : ['boxed', 'onscreen-post'] + , children : [ + { + tag : 'div' + , classList : ['row'] + , children : [ + { + tag : 'div' + , classList : ['topic-avatar'] + , children : [ + { + tag : 'div' + , classList : ['post-avatar'] + , children : [ + { + tag : 'a' + , classList : ['trigger-user-card', 'main-avatar'] + , children : [ + { + tag : 'img' + , classList : ['avatar'] + , props : { + src : message.userAvatarSrc + , width : 45 + , height : 45 + } + } + ] + } + ] + } + ] + } + , { + tag : 'div' + , classList : ['topic-body', 'clearfix'] + , children : [ + { + tag : 'div' + , classList : ['topic-meta-data'] + , children : [ + { + tag : 'div' + , classList : ['names', 'trigger-user-card'] + , children : [ + { + tag : 'span' + , classList : ['first', 'username'] + , children : [ + { + tag : 'a' + , innerHTML : message.author + } + + , { + tag : 'span' + , classList : ['svg-icon-title'] + , props : { + title : 'This user is free' + }, children : [ + { + tag : 'img' + , props : { + width : 16 + , height : 16 + , src : freeUserSymbol + } + } + ] + } + ] + } + ] + } + , { + tag : 'div' + , classList : ['post-infos'] + , children : [ + { + tag : 'div' + , classList : ['post-info', 'post-date'] + , children : [ + { + tag : 'a' + , classList : ['widget-link', 'post-date'] + , children : [ + { + tag : 'span' + , classList : ['relative-date'] + , innerHTML : message.relativeDate + } + ] + } + ] + } + ] + } + ] + } + , { + tag : 'div' + , classList : ['regular', 'contents'] + , children : [ + { + tag : 'div' + , classList : 'cooked' + , innerHTML : message.contents + } + ] + } + ] + } + ] + } + ] + } + ] + + messageWrapperElt = jsToDOM(messageWrapperElt, template) + + where.insertAdjacentElement('afterend', messageWrapperElt) + } + }) + .catch(err => { + + console.error(err) + }) +} + +let pageUrl = window.location.href + +if (pageUrl.match(/\/[0-9]+(\/[0-9]+)?$/)) { + + vaChercher(pageUrl) +} + +let tabUpdateHandler = function () { + + + /* + console.log("j'écoute") + + + */ +} + +console.log('coucou') + +// DOMContentLoaded +document.addEventListener('DOMContentLoaded', (event) => { + + console.log('coucou 2') + tabUpdateHandler() +}) diff --git a/icons/funiter-48.png b/icons/funiter-48.png new file mode 100644 index 0000000..7183a6f Binary files /dev/null and b/icons/funiter-48.png differ diff --git a/icons/funiter-48.xcf b/icons/funiter-48.xcf new file mode 100644 index 0000000..63c21b0 Binary files /dev/null and b/icons/funiter-48.xcf differ diff --git a/icons/tails.png b/icons/tails.png new file mode 100644 index 0000000..a2a9621 Binary files /dev/null and b/icons/tails.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..a0a6194 --- /dev/null +++ b/index.html @@ -0,0 +1,38 @@ + + + + Funiter + + + +

Funiter

+ +
+
+

+ Post 1 +

+
+
+ + +
+
+

+ Post 2 +

+
+
+ + +
+
+

+ Post 3 +

+
+
+ + + + \ No newline at end of file diff --git a/intentions.md b/intentions.md new file mode 100644 index 0000000..66988a6 --- /dev/null +++ b/intentions.md @@ -0,0 +1,7 @@ + + +- index.html de feed de tout ce que j'ai publié partout + +- passer en IPNS + +- interface de paramétrage des gens suivis (comme pour LightBeams) \ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..c59f671 --- /dev/null +++ b/manifest.json @@ -0,0 +1,29 @@ +{ + + "manifest_version": 2 + ,"name": "Funiter - Chevaucher le cochon" + ,"version": "1.0" + + ,"description": "Funiter, qui est le diminutif de “Freedom uniter”, ou « distributeur de liberté » en bon françois, est un plugin Firefox qui sert à afficher sur l'instance du logiciel Discourse installé à forum.duniter.org les messages publiés par quelques gens qui n'aiment ni être bâillonné, ni voir leurs écrits travestis sans leur permission. Lesdits messages sont accédés via des passerelles IPFS. Merci à vit et Hugo de m'avoir motivé à créer ce plugin." + + ,"icons": { + "48": "icons/funiter-48.png" + } + + ,"content_scripts": [ + { + "matches": ["*://forum.duniter.org/*", "*://funiter/*"], + "js": ["funiter.js"] + } + ] + + ,"permissions": [ + "*://libra.copylaradio.com/*", + "*://gateway.pinata.cloud/*" + ] + + ,"web_accessible_resources": [ + "icons/funiter-48.png" + ] + +} diff --git a/tests/boris_feeds.json b/tests/boris_feeds.json new file mode 100644 index 0000000..3f5b37a --- /dev/null +++ b/tests/boris_feeds.json @@ -0,0 +1,22 @@ +{ + "pseudo" : "boris" + , "avatar" : "" + , "feeds" : [ + { + "url" : "forum.duniter.org" + , "feed" : "ipfs:///ipfs/Qmde15Aqjvz59s38ma3UhGTbKnwJtS5wYDwKRuQQrrc7mD" + } + ,{ + "url" : "forum.monnaie-libre.org" + , "feed" : "ipfs:///ipns/..." + } + ,{ + "url" : "community.snowdrift.coop" + , "feed" : "ipfs:///ipns/..." + } + ,{ + "url" : "talk.tiddlywiki.org" + , "feed" : "ipfs:///ipns/..." + } + ] +} \ No newline at end of file diff --git a/tests/data.json b/tests/data.json new file mode 100644 index 0000000..d96c3fa --- /dev/null +++ b/tests/data.json @@ -0,0 +1,7 @@ +[ + { + + "position": "87603", + "message": "Eh, merde, tu es tombé dedans aussi ^^" + } +] \ No newline at end of file diff --git a/tests/duniter-topics.json b/tests/duniter-topics.json new file mode 100644 index 0000000..4ace40d --- /dev/null +++ b/tests/duniter-topics.json @@ -0,0 +1,6 @@ +[ + { + "id" : "9424" + , "feed" : "ipfs:///ipfs/Qmde15Aqjvz59s38ma3UhGTbKnwJtS5wYDwKRuQQrrc7mD" + } +] \ No newline at end of file diff --git a/tests/post.html b/tests/post.html new file mode 100644 index 0000000..9035b8b --- /dev/null +++ b/tests/post.html @@ -0,0 +1,37 @@ +
+
+
+
+
+ +
+
+
+ +
+
+

moi je touche pas aux images, chacun son truc :slight_smile:

+
+

Je trouve ça beaucoup mieux comme ça, il reste toute la partie gauche où on peut ajouter ce qu’on veut, toujours discret bien sûr, mais je sais pas quoi. un D pour duniter, mais bon …

+
+
+ +
+
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/tests/post2.html b/tests/post2.html new file mode 100644 index 0000000..c1301df --- /dev/null +++ b/tests/post2.html @@ -0,0 +1,70 @@ + +
+
+ +
+
+ +
+
+
+ + poka + + + + + +
+ + +
+ +
+
+

moi je touche pas aux images, chacun son truc :slight_smile:

+
+

Je trouve ça beaucoup mieux comme ça, il reste toute la partie gauche où on peut ajouter ce qu’on veut, toujours discret bien sûr, mais je sais pas quoi. un D pour duniter, mais bon …

+
+ +
+ +
+
+ +
+
+ +
+
diff --git a/tests/tails.png b/tests/tails.png new file mode 100644 index 0000000..a2a9621 Binary files /dev/null and b/tests/tails.png differ