Browse Source

add filters for common and video-watch scopes, for view counts, replies and likes

main v0.0.1
Rigel Kent 3 years ago
parent
commit
2d3de7d1b0
No known key found for this signature in database
GPG Key ID: 5E53E96A494E452F
  1. 5
      README.md
  2. 0
      assets/style.css
  3. 37
      client/common-client-plugin.js
  4. 46
      client/video-watch-client-plugin.js
  5. 3
      languages/fr.json
  6. 28
      main.js
  7. 4
      package-lock.json
  8. 32
      package.json
  9. 0
      public/images/.gitkeep
  10. 18
      webpack.config.js

5
README.md

@ -1 +1,4 @@ @@ -1 +1,4 @@
# PeerTube plugin Quickstart
# Ungamify
PeerTube uses slight gamification (i.e.: like buttons), and even if it is a far cry from Facebook's or Google's,
less or no gamification at all is a choice users like you might want to make. This plugin is for you.

0
assets/style.css

37
client/common-client-plugin.js

@ -1,7 +1,42 @@ @@ -1,7 +1,42 @@
function register ({ registerHook, peertubeHelpers }) {
initUngamify(registerHook, peertubeHelpers)
.catch(err => console.error('Cannot initialize ungamify plugin', err))
}
export {
register
}
function initUngamify (registerHook, peertubeHelpers) {
return peertubeHelpers.getSettings()
.then(s => {
const clean = () => {
if (s["ungamify-views-counter"] === "true") {
[
"views"
].map(className =>
[...document.getElementsByClassName(className)].forEach(node => node.style.visibility = "hidden")
)
}
}
var mutationObserver = new MutationObserver(function(mutations) {
clean()
})
mutationObserver.observe(document.documentElement, {
attributes: true,
characterData: true,
childList: true,
subtree: true,
attributeOldValue: true,
characterDataOldValue: true
})
setTimeout(clean, 50)
registerHook({
target: "action:router.navigation-end",
handler: params => clean()
})
})
}

46
client/video-watch-client-plugin.js

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
function register ({ registerHook, peertubeHelpers }) {
initUngamify(registerHook, peertubeHelpers)
.catch(err => console.error('Cannot initialize ungamify plugin', err))
}
export {
register
}
function initUngamify (registerHook, peertubeHelpers) {
return peertubeHelpers.getSettings()
.then(s => {
registerHook({
target: "action:video-watch.player.loaded",
handler: _ => {
if (s["ungamify-likes"] === "true") {
[
"action-button-like",
"action-button-dislike",
"video-info-likes-dislikes-bar"
].map(className =>
[...document.getElementsByClassName(className)].forEach(node => node.style.visibility = "hidden")
)
}
if (s["ungamify-views-counter"] === "true") {
[
"views"
].map(className =>
[...document.getElementsByClassName(className)].forEach(node => node.style.visibility = "hidden")
)
}
if (s["ungamify-replies-counter"] === "true") {
[
"view-replies"
].map(className =>
[...document.getElementsByClassName(className)].forEach(node => {
const innerElements = node.innerHTML.split("<!---->")
innerElements[1] = innerElements[1].replace(/[0-9]/g, '').trim()
node.innerHTML = innerElements.join("<!---->")
})
)
}
}
})
})
}

3
languages/fr.json

@ -1,3 +0,0 @@ @@ -1,3 +0,0 @@
{
"Hello world": "Hello le monde"
}

28
main.js

@ -1,13 +1,27 @@ @@ -1,13 +1,27 @@
async function register ({
registerHook,
registerSetting,
settingsManager,
storageManager,
videoCategoryManager,
videoLicenceManager,
videoLanguageManager
}) {
registerSetting({
name: "ungamify-likes",
label: "Hide likes and like buttons",
type: "input",
private: false,
default: "true"
})
registerSetting({
name: "ungamify-views-counter",
label: "Hide views counter",
type: "input",
private: false,
default: "true"
})
registerSetting({
name: "ungamify-replies-counter",
label: "Hide replies counter",
type: "input",
private: false,
default: "true"
})
}
async function unregister () {

4
package-lock.json generated

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
{
"name": "peertube-plugin-quickstart",
"version": "0.0.2",
"name": "peertube-plugin-ungamify",
"version": "0.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

32
package.json

@ -1,20 +1,24 @@ @@ -1,20 +1,24 @@
{
"name": "peertube-plugin-quickstart",
"description": "PeerTube plugin quickstart",
"version": "0.0.2",
"author": "Chocobozzz",
"bugs": "https://framagit.org/framasoft/peertube/peertube-plugin-quickstart/issues",
"name": "peertube-plugin-ungamify",
"description": "PeerTube plugin that removes eventual gamifications (i.e.: like counters)",
"version": "0.0.1",
"author": "Rigel Kent",
"bugs": "https://framagit.org/rigelk/peertube-plugin-ungamify/issues",
"clientScripts": [
{
"script": "dist/common-client-plugin.js",
"scopes": [
"common"
]
},
{
"script": "dist/video-watch-client-plugin.js",
"scopes": [
"video-watch"
]
}
],
"css": [
"assets/style.css"
],
"css": [],
"devDependencies": {
"@purtuga/esm-webpack-plugin": "^1.1.1",
"webpack": "^4.41.2",
@ -23,19 +27,17 @@ @@ -23,19 +27,17 @@
"engine": {
"peertube": ">=1.3.0"
},
"homepage": "https://framagit.org/framasoft/peertube/peertube-plugin-quickstart",
"homepage": "https://framagit.org/rigelk/peertube-plugin-ungamify",
"keywords": [
"peertube",
"plugin"
],
"library": "./main.js",
"license": "AGPL-3.0-or-later",
"repository": "https://framagit.org/rigelk/peertube-plugin-ungamify",
"scripts": {
"build": "webpack --mode=production"
},
"staticDirs": {
"images": "public/images"
},
"translations": {
"fr-FR": "./languages/fr.json"
}
"staticDirs": {},
"translations": {}
}

0
public/images/.gitkeep

18
webpack.config.js

@ -2,7 +2,7 @@ const path = require("path") @@ -2,7 +2,7 @@ const path = require("path")
const EsmWebpackPlugin = require("@purtuga/esm-webpack-plugin")
let config = {
let commonConfig = {
entry: "./client/common-client-plugin.js",
output: {
path: path.resolve(__dirname, "./dist"),
@ -13,4 +13,18 @@ let config = { @@ -13,4 +13,18 @@ let config = {
plugins: [new EsmWebpackPlugin()]
}
module.exports = config
let videoWatchConfig = {
entry: "./client/video-watch-client-plugin.js",
output: {
path: path.resolve(__dirname, "./dist"),
filename: "./video-watch-client-plugin.js",
library: "script",
libraryTarget: "var"
},
plugins: [new EsmWebpackPlugin()]
}
module.exports = [
commonConfig,
videoWatchConfig
]

Loading…
Cancel
Save