First commit
This commit is contained in:
commit
881b5941a9
6 changed files with 135 additions and 0 deletions
25
dialog.html
Normal file
25
dialog.html
Normal file
|
@ -0,0 +1,25 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<form id="form">
|
||||
<fieldset>
|
||||
<legend>Redirect configuration</legend>
|
||||
<input type="checkbox" id="enabled" class="control"><label for="enabled">Enable redirect</label><br>
|
||||
<label for="instance">Nitter domain</label><br>
|
||||
<input type="text" id="instance" class="control" required>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Authentication</legend>
|
||||
<label for="username">Username</label><br>
|
||||
<input type="text" id="username" class="control"><br>
|
||||
<label for="password">Password</label><br>
|
||||
<input type="password" id="password" class="control"><br>
|
||||
</fieldset>
|
||||
<input type="submit" value="Update settings" id="submit" disabled>
|
||||
<form>
|
||||
<script src="dialog.js"></script>
|
||||
</body>
|
||||
</html>
|
81
dialog.js
Normal file
81
dialog.js
Normal file
|
@ -0,0 +1,81 @@
|
|||
'use strict';
|
||||
if (window.browser === undefined) {
|
||||
window.browser = window.chrome;
|
||||
}
|
||||
|
||||
function createRedirect(id, from, transform) {
|
||||
return {
|
||||
id: id,
|
||||
action: {
|
||||
type: "redirect",
|
||||
redirect: { transform: transform },
|
||||
},
|
||||
condition: {
|
||||
urlFilter: from,
|
||||
resourceTypes: ["main_frame", "sub_frame"],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function updateRedirects(settings) {
|
||||
const transform = {
|
||||
host: settings.instance,
|
||||
};
|
||||
if (settings.username !== '') {
|
||||
transform.username = settings.username;
|
||||
}
|
||||
if (settings.password !== '') {
|
||||
transform.password = settings.password;
|
||||
}
|
||||
const redirects = [];
|
||||
if (settings.enabled) {
|
||||
redirects.push(createRedirect(1, '||twitter.com', transform));
|
||||
redirects.push(createRedirect(2, '||x.com', transform));
|
||||
}
|
||||
browser.declarativeNetRequest.updateDynamicRules({
|
||||
addRules: redirects,
|
||||
removeRuleIds: [1, 2],
|
||||
});
|
||||
}
|
||||
|
||||
function setupSettingsForm(settings) {
|
||||
const enabled = document.getElementById('enabled');
|
||||
const instance = document.getElementById('instance');
|
||||
const username = document.getElementById('username');
|
||||
const password = document.getElementById('password');
|
||||
const submit = document.getElementById('submit');
|
||||
|
||||
enabled.checked = settings.enabled;
|
||||
instance.value = settings.instance;
|
||||
username.value = settings.username;
|
||||
password.value = settings.password;
|
||||
|
||||
document.getElementById('form').addEventListener('submit', (event) => {
|
||||
event.preventDefault();
|
||||
settings.enabled = enabled.checked;
|
||||
settings.instance = instance.value;
|
||||
settings.username = username.value;
|
||||
settings.password = password.value;
|
||||
submit.disabled = true;
|
||||
browser.storage.local.set(settings);
|
||||
updateRedirects(settings);
|
||||
});
|
||||
|
||||
for (let element of document.getElementsByClassName('control')) {
|
||||
element.addEventListener('input', () => {
|
||||
const different =
|
||||
enabled.checked !== settings.enabled ||
|
||||
instance.value !== settings.instance ||
|
||||
username.value !== settings.username ||
|
||||
password.value !== settings.password;
|
||||
submit.disabled = !different;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
browser.storage.local.get({
|
||||
enabled: false,
|
||||
instance: '',
|
||||
username: '',
|
||||
password: '',
|
||||
}).then(setupSettingsForm);
|
BIN
icon-16.png
Normal file
BIN
icon-16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 409 B |
BIN
icon-32.png
Normal file
BIN
icon-32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 758 B |
BIN
icon-64.png
Normal file
BIN
icon-64.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
29
manifest.json
Normal file
29
manifest.json
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"manifest_version": 3,
|
||||
"name": "Private Nitter redirector",
|
||||
"icons": {
|
||||
"16": "icon-16.png",
|
||||
"32": "icon-32.png",
|
||||
"64": "icon-64.png"
|
||||
},
|
||||
"description": "Redirect to and authenticate with a private Nitter instance",
|
||||
"version": "1.0",
|
||||
"permissions": [
|
||||
"declarativeNetRequestWithHostAccess",
|
||||
"storage"
|
||||
],
|
||||
"host_permissions": [
|
||||
"*://twitter.com/*",
|
||||
"*://www.twitter.com/*",
|
||||
"*://mobile.twitter.com/*",
|
||||
"*://x.com/*"
|
||||
],
|
||||
"action": {
|
||||
"default_icon": {
|
||||
"16": "icon-16.png",
|
||||
"32": "icon-32.png",
|
||||
"64": "icon-64.png"
|
||||
},
|
||||
"default_popup": "dialog.html"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue