Proactively remove Twitter servie worker
This commit is contained in:
parent
1f205990eb
commit
f5eac66d70
|
@ -0,0 +1,44 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const nitterDefault = 'https://nitter.net';
|
||||||
|
|
||||||
|
let disableNitter;
|
||||||
|
let nitterInstance;
|
||||||
|
|
||||||
|
window.browser = window.browser || window.chrome;
|
||||||
|
|
||||||
|
function redirectTwitter(url) {
|
||||||
|
if (url.host.split('.')[0] === 'pbs') {
|
||||||
|
return `${nitterInstance}/pic/${encodeURIComponent(url.href)}`;
|
||||||
|
} else if (url.host.split('.')[0] === 'video') {
|
||||||
|
return `${nitterInstance}/gif/${encodeURIComponent(url.href)}`;
|
||||||
|
} else {
|
||||||
|
return `${nitterInstance}${url.pathname}${url.search}`;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
browser.storage.sync.get(
|
||||||
|
['nitterInstance', 'disableNitter', 'removeTwitterSW'],
|
||||||
|
(result) => {
|
||||||
|
if (!result.removeTwitterSW) {
|
||||||
|
disableNitter = result.disableNitter;
|
||||||
|
nitterInstance = result.nitterInstance || nitterDefault;
|
||||||
|
navigator.serviceWorker.getRegistrations().then(registrations => {
|
||||||
|
for (let registration of registrations) {
|
||||||
|
if (registration.scope === 'https://twitter.com/') {
|
||||||
|
registration.unregister();
|
||||||
|
console.log('Unregistered Twitter SW', registration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const url = new URL(window.location);
|
||||||
|
if (!disableNitter && url.host !== nitterInstance) {
|
||||||
|
const redirect = redirectTwitter(url);
|
||||||
|
console.info(
|
||||||
|
'Redirecting', `"${url.href}"`, '=>', `"${redirect}"`
|
||||||
|
);
|
||||||
|
window.location = redirect;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "Privacy Redirect",
|
"name": "Privacy Redirect",
|
||||||
"description": "Redirects Twitter, YouTube, Instagram & Google Maps requests to privacy friendly alternatives.",
|
"description": "Redirects Twitter, YouTube, Instagram & Google Maps requests to privacy friendly alternatives.",
|
||||||
"version": "1.1.16",
|
"version": "1.1.17",
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"background": {
|
"background": {
|
||||||
"scripts": [
|
"scripts": [
|
||||||
|
@ -31,6 +31,21 @@
|
||||||
"128": "images/icon128.png"
|
"128": "images/icon128.png"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"content_scripts": [
|
||||||
|
{
|
||||||
|
"matches": [
|
||||||
|
"*://twitter.com/*",
|
||||||
|
"*://www.twitter.com/*",
|
||||||
|
"*://mobile.twitter.com/*",
|
||||||
|
"*://pbs.twimg.com/*",
|
||||||
|
"*://video.twimg.com/*"
|
||||||
|
],
|
||||||
|
"js": [
|
||||||
|
"content-script.js"
|
||||||
|
],
|
||||||
|
"run_at": "document_start"
|
||||||
|
}
|
||||||
|
],
|
||||||
"options_ui": {
|
"options_ui": {
|
||||||
"page": "pages/options/options.html",
|
"page": "pages/options/options.html",
|
||||||
"open_in_tab": false
|
"open_in_tab": false
|
||||||
|
|
|
@ -111,6 +111,15 @@
|
||||||
</select>
|
</select>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section class="options settings_block">
|
||||||
|
<div class="onoffswitch switch" aria-label="Proactively remove Twitter service worker">
|
||||||
|
<h1>Proactively remove Twitter service worker</h1>
|
||||||
|
<input aria-hidden="true" id="remove-twitter-sw" type="checkbox" checked>
|
||||||
|
<label for="remove-twitter-sw" class="checkbox-label">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<script src="./options.js"></script>
|
<script src="./options.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -11,6 +11,7 @@ let disableOsm = document.querySelector('#disable-osm');
|
||||||
let alwaysProxy = document.querySelector('#always-proxy');
|
let alwaysProxy = document.querySelector('#always-proxy');
|
||||||
let onlyEmbeddedVideo = document.querySelector('#only-embed');
|
let onlyEmbeddedVideo = document.querySelector('#only-embed');
|
||||||
let videoQuality = document.querySelector('#video-quality');
|
let videoQuality = document.querySelector('#video-quality');
|
||||||
|
let removeTwitterSW = document.querySelector('#remove-twitter-sw');
|
||||||
|
|
||||||
window.browser = window.browser || window.chrome;
|
window.browser = window.browser || window.chrome;
|
||||||
|
|
||||||
|
@ -26,7 +27,8 @@ browser.storage.sync.get(
|
||||||
'disableOsm',
|
'disableOsm',
|
||||||
'alwaysProxy',
|
'alwaysProxy',
|
||||||
'onlyEmbeddedVideo',
|
'onlyEmbeddedVideo',
|
||||||
'videoQuality'
|
'videoQuality',
|
||||||
|
'removeTwitterSW'
|
||||||
],
|
],
|
||||||
result => {
|
result => {
|
||||||
nitterInstance.value = result.nitterInstance || '';
|
nitterInstance.value = result.nitterInstance || '';
|
||||||
|
@ -40,6 +42,7 @@ browser.storage.sync.get(
|
||||||
alwaysProxy.checked = result.alwaysProxy;
|
alwaysProxy.checked = result.alwaysProxy;
|
||||||
onlyEmbeddedVideo.checked = result.onlyEmbeddedVideo;
|
onlyEmbeddedVideo.checked = result.onlyEmbeddedVideo;
|
||||||
videoQuality.value = result.videoQuality || '';
|
videoQuality.value = result.videoQuality || '';
|
||||||
|
removeTwitterSW.checked = !result.removeTwitterSW;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -123,3 +126,7 @@ videoQuality.addEventListener('change', event => {
|
||||||
videoQuality: event.target.options[videoQuality.selectedIndex].value
|
videoQuality: event.target.options[videoQuality.selectedIndex].value
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
removeTwitterSW.addEventListener('change', event => {
|
||||||
|
browser.storage.sync.set({ removeTwitterSW: !event.target.checked });
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue