Merge branch 'options'
@ -1,19 +1,56 @@
|
||||
const nitter = "https://nitter.net";
|
||||
const invidious = "https://invidio.us";
|
||||
const youtubeRegex = /((www|m)\.)?youtube(-nocookie)?\.com/
|
||||
'use strict';
|
||||
|
||||
const nitterDefault = 'https://nitter.net';
|
||||
const invidiousDefault = 'https://invidio.us';
|
||||
const youtubeRegex = /((www|m)\.)?youtube(-nocookie)?\.com/;
|
||||
const pathRegex = /^https?:\/\/[^\/]+([\S\s]*)/;
|
||||
|
||||
let nitterInstance;
|
||||
let invidiousInstance;
|
||||
let disableNitter;
|
||||
let disableInvidious;
|
||||
|
||||
chrome.storage.sync.get(
|
||||
['disableNitter', 'disableInvidious', 'nitterInstance', 'invidiousInstance'],
|
||||
(result) => {
|
||||
disableNitter = result.disableNitter;
|
||||
disableInvidious = result.disableInvidious;
|
||||
nitterInstance = result.nitterInstance || nitterDefault;
|
||||
invidiousInstance = result.invidiousInstance || invidiousDefault;
|
||||
}
|
||||
);
|
||||
|
||||
chrome.storage.onChanged.addListener(function (changes) {
|
||||
if ('nitterInstance' in changes) {
|
||||
nitterInstance = changes.nitterInstance.newValue || nitterDefault;
|
||||
}
|
||||
if ('invidiousInstance' in changes) {
|
||||
invidiousInstance = changes.invidiousInstance.newValue || invidiousDefault;
|
||||
}
|
||||
if ('disableNitter' in changes) {
|
||||
disableNitter = changes.disableNitter.newValue;
|
||||
}
|
||||
if ('disableInvidious' in changes) {
|
||||
disableInvidious = changes.disableInvidious.newValue;
|
||||
}
|
||||
});
|
||||
|
||||
chrome.webRequest.onBeforeRequest.addListener(
|
||||
function (details) {
|
||||
if (details.url.match(youtubeRegex)) {
|
||||
return {
|
||||
redirectUrl:
|
||||
invidious + details.url.match(/^https?:\/\/[^\/]+([\S\s]*)/)[1]
|
||||
};
|
||||
if (!disableInvidious) {
|
||||
return {
|
||||
redirectUrl:
|
||||
invidiousInstance + details.url.match(pathRegex)[1]
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
redirectUrl:
|
||||
nitter + details.url.match(/^https?:\/\/[^\/]+([\S\s]*)/)[1]
|
||||
};
|
||||
if (!disableNitter) {
|
||||
return {
|
||||
redirectUrl:
|
||||
nitterInstance + details.url.match(pathRegex)[1]
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
|
Before Width: | Height: | Size: 406 KiB After Width: | Height: | Size: 406 KiB |
Before Width: | Height: | Size: 792 KiB After Width: | Height: | Size: 792 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 976 B After Width: | Height: | Size: 976 B |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
BIN
images/logo.png
Normal file
After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
@ -1,20 +1,22 @@
|
||||
{
|
||||
"name": "Privacy Redirect",
|
||||
"description": "Redirects Twitter & Youtube requests to privacy friendly alternatives (Nitter & Invidious).",
|
||||
"version": "1.0.1",
|
||||
"version": "1.1.1",
|
||||
"manifest_version": 2,
|
||||
"background": {
|
||||
"scripts": [
|
||||
"background.js"
|
||||
]
|
||||
],
|
||||
"persistent": true
|
||||
},
|
||||
"icons": {
|
||||
"16": "img/icon16.png",
|
||||
"32": "img/icon32.png",
|
||||
"48": "img/icon48.png",
|
||||
"128": "img/icon128.png"
|
||||
"16": "images/icon16.png",
|
||||
"32": "images/icon32.png",
|
||||
"48": "images/icon48.png",
|
||||
"128": "images/icon128.png"
|
||||
},
|
||||
"permissions": [
|
||||
"storage",
|
||||
"webRequest",
|
||||
"webRequestBlocking",
|
||||
"*://twitter.com/*",
|
||||
@ -25,5 +27,23 @@
|
||||
"*://youtube-nocookie.com/*",
|
||||
"*://www.youtube-nocookie.com/*",
|
||||
"*://m.youtube.com/"
|
||||
]
|
||||
],
|
||||
"browser_action": {
|
||||
"default_popup": "pages/popup/popup.html",
|
||||
"default_icon": {
|
||||
"16": "images/icon16.png",
|
||||
"32": "images/icon32.png",
|
||||
"48": "images/icon48.png",
|
||||
"128": "images/icon128.png"
|
||||
}
|
||||
},
|
||||
"options_ui": {
|
||||
"page": "pages/options/options.html",
|
||||
"open_in_tab": false
|
||||
},
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
"id": "{b7f9d2cd-d772-4302-8c3f-eb941af36f76}"
|
||||
}
|
||||
}
|
||||
}
|
47
pages/options/options.html
Normal file
@ -0,0 +1,47 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title></title>
|
||||
<link href="../styles.css" rel="stylesheet">
|
||||
<title>Privacy Redirect Options</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<section class="options settings_block">
|
||||
<div class="onoffswitch switch" aria-label="Toggle Nitter redirects">
|
||||
<h1>Nitter Redirects</h1>
|
||||
<input aria-hidden="true" id="disableNitter" type="checkbox" checked>
|
||||
<label for="disableNitter" class="checkbox-label">
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="options settings_block">
|
||||
<div class="onoffswitch switch" aria-label="Toggle Invidious redirects">
|
||||
<h1>Invidious Redirects</h1>
|
||||
<input aria-hidden="true" id="disableInvidious" type="checkbox" checked>
|
||||
<label for="disableInvidious" class="checkbox-label">
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="options settings_block">
|
||||
<h1>Nitter Instance</h1>
|
||||
<input id="nitterInstance" type="url" placeholder="https://nitter.net">
|
||||
<h1>Invidious Instance</h1>
|
||||
<input id="invidiousInstance" type="url" placeholder="https://invidio.us">
|
||||
</section>
|
||||
|
||||
<footer>
|
||||
<a class="button" id="save">Save</a>
|
||||
</footer>
|
||||
|
||||
<script src="./options.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
26
pages/options/options.js
Normal file
@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
let disableNitter = document.querySelector('#disableNitter');
|
||||
let disableInvidious = document.querySelector('#disableInvidious');
|
||||
let nitterInstance = document.querySelector('#nitterInstance');
|
||||
let invidiousInstance = document.querySelector('#invidiousInstance');
|
||||
|
||||
chrome.storage.sync.get(
|
||||
['disableNitter', 'disableInvidious', 'nitterInstance', 'invidiousInstance'],
|
||||
(result) => {
|
||||
disableNitter.checked = !result.disableNitter;
|
||||
disableInvidious.checked = !result.disableInvidious;
|
||||
nitterInstance.value = result.nitterInstance || '';
|
||||
invidiousInstance.value = result.invidiousInstance || '';
|
||||
}
|
||||
);
|
||||
|
||||
document.querySelector('#save').addEventListener('click', () => {
|
||||
chrome.storage.sync.set({
|
||||
disableNitter: !disableNitter.checked,
|
||||
disableInvidious: !disableInvidious.checked,
|
||||
nitterInstance: nitterInstance.value,
|
||||
invidiousInstance: invidiousInstance.value
|
||||
});
|
||||
window.close();
|
||||
});
|
47
pages/popup/popup.html
Normal file
@ -0,0 +1,47 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title></title>
|
||||
<link href="../styles.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<div class="logo-container">
|
||||
<img src="../../images/logo.png" alt="Privacy Redirect logo">
|
||||
</div>
|
||||
<small>
|
||||
<span>Version</span>: 1.1.1</span>
|
||||
</small>
|
||||
</header>
|
||||
|
||||
<section class="options settings_block">
|
||||
<div class="onoffswitch switch" aria-label="Toggle Nitter redirects">
|
||||
<h1>Nitter Redirects</h1>
|
||||
<input aria-hidden="true" id="disableNitter" type="checkbox" checked>
|
||||
<label for="disableNitter" class="checkbox-label">
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="options settings_block">
|
||||
<div class="onoffswitch switch" aria-label="Toggle Invidious redirects">
|
||||
<h1>Invidious Redirects</h1>
|
||||
<input aria-hidden="true" id="disableInvidious" type="checkbox" checked>
|
||||
<label for="disableInvidious" class="checkbox-label">
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<footer>
|
||||
<a class="button" id="options" target="_blank">Options</a>
|
||||
</footer>
|
||||
|
||||
<script src="./popup.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
28
pages/popup/popup.js
Normal file
@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
let disableNitter = document.querySelector('#disableNitter');
|
||||
let disableInvidious = document.querySelector('#disableInvidious');
|
||||
|
||||
chrome.storage.sync.get(
|
||||
['disableNitter', 'disableInvidious'],
|
||||
(result) => {
|
||||
disableNitter.checked = !result.disableNitter;
|
||||
disableInvidious.checked = !result.disableInvidious;
|
||||
}
|
||||
);
|
||||
|
||||
disableNitter.addEventListener('change', (event) => {
|
||||
chrome.storage.sync.set({ disableNitter: !event.target.checked });
|
||||
});
|
||||
|
||||
disableInvidious.addEventListener('change', (event) => {
|
||||
chrome.storage.sync.set({ disableInvidious: !event.target.checked });
|
||||
});
|
||||
|
||||
document.querySelector('#options').addEventListener('click', () => {
|
||||
if (chrome.runtime.openOptionsPage) {
|
||||
chrome.runtime.openOptionsPage();
|
||||
} else {
|
||||
window.open(chrome.runtime.getURL('../options/options.html'));
|
||||
}
|
||||
});
|
146
pages/styles.css
Normal file
@ -0,0 +1,146 @@
|
||||
:root {
|
||||
--text-main: #FFF;
|
||||
--text-secondary: #000;
|
||||
--dark-grey: #3C4043;
|
||||
--white: #FFF;
|
||||
--active: #FF5B56;
|
||||
--space: 5px;
|
||||
}
|
||||
|
||||
body {
|
||||
color: var(--text-secondary);
|
||||
margin: 0;
|
||||
max-width: 400px;
|
||||
min-width: 240px;
|
||||
background-color: var(--dark-grey)
|
||||
}
|
||||
|
||||
header {
|
||||
background-color: var(--white);
|
||||
color: var(--text-secondary);
|
||||
display: flex;
|
||||
padding: var(--space);
|
||||
}
|
||||
|
||||
header h1 {
|
||||
font-size: 2em;
|
||||
}
|
||||
|
||||
header .logo-container {
|
||||
margin: var(--space);
|
||||
}
|
||||
|
||||
header .logo-container img {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
header small {
|
||||
display: block;
|
||||
font-size: .70em;
|
||||
font-weight: bold;
|
||||
margin: 1%;
|
||||
width: 100%;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 14px;
|
||||
margin: var(--space) auto
|
||||
}
|
||||
|
||||
h2 {
|
||||
clear: both;
|
||||
font-size: 12px;
|
||||
font-weight: normal;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2 {
|
||||
color: var(--text-main);
|
||||
}
|
||||
|
||||
footer {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
footer a.button {
|
||||
margin: var(--space);
|
||||
}
|
||||
|
||||
/* Elements */
|
||||
|
||||
input[type=url] {
|
||||
width: 100%;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
input[type=checkbox] {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.checkbox-label {
|
||||
background: grey;
|
||||
border-radius: 25px;
|
||||
color: var(--text-main);
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
float: right;
|
||||
font-weight: bold;
|
||||
height: 30px;
|
||||
position: relative;
|
||||
text-indent: -400px;
|
||||
width: 50px;
|
||||
}
|
||||
|
||||
.checkbox-label:after {
|
||||
background: #fff;
|
||||
border-radius: 90px;
|
||||
content: '';
|
||||
height: 20px;
|
||||
left: 5px;
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
transition: 0.3s; /* Acts on transform below */
|
||||
width: 20px;
|
||||
}
|
||||
input:checked+label {
|
||||
background: var(--active);
|
||||
}
|
||||
/* position when active*/
|
||||
input:checked+label:after {
|
||||
left: calc(100% - 5px);
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
|
||||
.settings_block {
|
||||
display: block;
|
||||
padding: 5px 1em 20px 1em;
|
||||
border-bottom: var(--dark-grey) solid 1px;
|
||||
}
|
||||
|
||||
.settings_block h1 {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.button {
|
||||
border: var(--active) solid 1px;
|
||||
color: var(--text-main);
|
||||
display: block;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
margin: var(--space) auto;
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
background-color: var(--active);
|
||||
color: #fff
|
||||
}
|
||||
|