Skip to content

Commit

Permalink
Formatting wiht prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
ManeraKai committed Jul 21, 2024
1 parent 8bf2595 commit cf8216d
Show file tree
Hide file tree
Showing 19 changed files with 3,292 additions and 3,324 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src/_locales/
.github/
.gitea/
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 120,
"semi": false,
"singleQuote": false,
"trailingComma": "es5",
"arrowParens": "avoid"
}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,50 @@ A browser extension that redirects YouTube, Twitter, TikTok... requests to alter
</a>

## Translate

<a href="https://hosted.weblate.org/projects/libredirect/extension">
<img src ="./img/weblate.svg">
</a>

## Development

Install [Node.js](https://nodejs.org/)

```bash
git clone https://github.com/libredirect/browser_extension
cd browser_extension
npm install
npm run html # Generates html using Pug
```

#### Run on Firefox

```bash
npm run start
```

#### Build a zip package for Firefox

```bash
npm run build
```

#### Install the zip package on Firefox (temporarily)

1. Type in the address bar: `about:debugging#/runtime/this-firefox`
2. Press `Load Temporary Add-on...`
3. Select `libredirect-VERSION.zip` from `web-ext-artifacts` folder

#### Install the zip package on Firefox ESR, Developer Edition, Nightly

1. Type in the address bar: `about:config`
2. Set `xpinstall.signatures.required` to `false`
3. Type in the address bar: `about:addons`
4. Click on the gear shaped `settings` button and select `Install Add-on From File...`
5. Select `libredirect-VERSION.zip` from `web-ext-artifacts` folder

#### Run on Chromium

1. Open `chrome://extensions`
2. Enable `dev mode`
3. Select `load unpacked extension`
Expand Down
74 changes: 37 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
{
"name": "libredirect",
"description": "Redirects YouTube, Twitter, TikTok and more to privacy friendly frontends.",
"engines": {
"node": ">=16.13.1",
"npm": ">=8.1.2"
},
"scripts": {
"start": "web-ext run",
"nightly": "web-ext run --firefox=/home/esmail/software/firefox_nightly/firefox",
"android": "web-ext run -t firefox-android --adb-device emulator-5554 --firefox-apk org.mozilla.fenix",
"build": "web-ext build",
"test": "web-ext lint",
"html": "pug --basedir ./ --obj ./src/config.json src/pages/options/index.pug --out src/pages/options/ && pug --basedir ./ --obj ./src/config.json src/pages/popup/popup.pug --out src/pages/popup/"
},
"repository": {
"type": "git",
"url": "git+https://github.com/libredirect/libredirect.git"
},
"author": "LibRedirect",
"license": "GPL-3.0-only",
"bugs": {
"url": "https://github.com/libredirect/libredirect/issues"
},
"homepage": "https://libredirect.github.io",
"devDependencies": {
"pug-cli": "^1.0.0-alpha6",
"web-ext": "^7.2.0"
},
"webExt": {
"sourceDir": "./src/",
"run": {
"browserConsole": true
},
"build": {
"overwriteDest": true
}
}
"name": "libredirect",
"description": "Redirects YouTube, Twitter, TikTok and more to privacy friendly frontends.",
"engines": {
"node": ">=16.13.1",
"npm": ">=8.1.2"
},
"scripts": {
"start": "web-ext run",
"nightly": "web-ext run --firefox=/home/esmail/software/firefox_nightly/firefox",
"android": "web-ext run -t firefox-android --adb-device emulator-5554 --firefox-apk org.mozilla.fenix",
"build": "web-ext build",
"test": "web-ext lint",
"html": "pug --basedir ./ --obj ./src/config.json src/pages/options/index.pug --out src/pages/options/ && pug --basedir ./ --obj ./src/config.json src/pages/popup/popup.pug --out src/pages/popup/"
},
"repository": {
"type": "git",
"url": "git+https://github.com/libredirect/libredirect.git"
},
"author": "LibRedirect",
"license": "GPL-3.0-only",
"bugs": {
"url": "https://github.com/libredirect/libredirect/issues"
},
"homepage": "https://libredirect.github.io",
"devDependencies": {
"pug-cli": "^1.0.0-alpha6",
"web-ext": "^7.2.0"
},
"webExt": {
"sourceDir": "./src/",
"run": {
"browserConsole": true
},
"build": {
"overwriteDest": true
}
}
}
50 changes: 25 additions & 25 deletions src/assets/javascripts/localise.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
window.browser = window.browser || window.chrome

function localisePage() {
/**
* @param {string} tag
*/
function getMessage(tag) {
return tag.replace(/__MSG_(\w+)__/g, (_match, v1) => {
return v1 ? browser.i18n.getMessage(v1) : null
})
}
/**
* @param {string} tag
*/
function getMessage(tag) {
return tag.replace(/__MSG_(\w+)__/g, (_match, v1) => {
return v1 ? browser.i18n.getMessage(v1) : null
})
}

const elements = document.querySelectorAll("[data-localise]")
for (let i in elements)
if (elements.hasOwnProperty(i)) {
const obj = elements[i]
const tag = obj.getAttribute("data-localise").toString()
const msg = getMessage(tag)
if (msg && msg !== tag) obj.textContent = msg
}
const elements = document.querySelectorAll("[data-localise]")
for (let i in elements)
if (elements.hasOwnProperty(i)) {
const obj = elements[i]
const tag = obj.getAttribute("data-localise").toString()
const msg = getMessage(tag)
if (msg && msg !== tag) obj.textContent = msg
}

const placeholders = document.querySelectorAll("[data-localise-placeholder]")
for (let i in placeholders)
if (placeholders.hasOwnProperty(i)) {
const obj = placeholders[i]
const tag = obj.getAttribute("data-localise-placeholder").toString()
const msg = getMessage(tag)
if (msg && msg !== tag) obj.placeholder = msg
}
const placeholders = document.querySelectorAll("[data-localise-placeholder]")
for (let i in placeholders)
if (placeholders.hasOwnProperty(i)) {
const obj = placeholders[i]
const tag = obj.getAttribute("data-localise-placeholder").toString()
const msg = getMessage(tag)
if (msg && msg !== tag) obj.placeholder = msg
}
}

export default {
localisePage,
localisePage,
}
Loading

0 comments on commit cf8216d

Please sign in to comment.