Refining Send support #67
This commit is contained in:
parent
519f9e9594
commit
09c9a67337
|
@ -84,7 +84,6 @@ async function init() {
|
|||
"translate",
|
||||
"maps",
|
||||
"wikipedia",
|
||||
"medium",
|
||||
];
|
||||
|
||||
autoRedirect = r.autoRedirect ?? false;
|
||||
|
@ -118,6 +117,7 @@ let allPopupFrontends = [
|
|||
"maps",
|
||||
"wikipedia",
|
||||
"medium",
|
||||
"sendTargets"
|
||||
];
|
||||
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ async function init() {
|
|||
"pixivProtocol"
|
||||
],
|
||||
r => {
|
||||
disable = r.disablePixiv ?? false;
|
||||
disable = r.disablePixiv ?? true;
|
||||
|
||||
protocol = r.pixivProtocol ?? "normal";
|
||||
|
||||
|
|
|
@ -105,6 +105,34 @@ function setProtocol(val) {
|
|||
console.log("sendTargetsProtocol: ", val)
|
||||
}
|
||||
|
||||
function changeInstance(url) {
|
||||
let protocolHost = `${url.protocol}//${url.host}`;
|
||||
|
||||
let sendList = [
|
||||
...redirects.send.normal,
|
||||
...redirects.send.tor,
|
||||
...sendNormalCustomRedirects,
|
||||
...sendTorCustomRedirects,
|
||||
];
|
||||
|
||||
if (!sendList.includes(protocolHost)) return;
|
||||
|
||||
if (url.pathname != '/') return;
|
||||
|
||||
let instancesList;
|
||||
if (protocol == 'normal') instancesList = [...sendNormalRedirectsChecks, ...sendNormalCustomRedirects];
|
||||
else if (protocol == 'tor') instancesList = [...sendTorRedirectsChecks, ...sendTorCustomRedirects];
|
||||
|
||||
console.log("instancesList", instancesList);
|
||||
let index = instancesList.indexOf(protocolHost);
|
||||
if (index > -1) instancesList.splice(index, 1);
|
||||
|
||||
if (instancesList.length === 0) return null;
|
||||
|
||||
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
}
|
||||
|
||||
function redirect(url, type, initiator) {
|
||||
|
||||
if (disable) return null;
|
||||
|
@ -183,6 +211,8 @@ export default {
|
|||
getSendNormalCustomRedirects,
|
||||
setSendNormalCustomRedirects,
|
||||
|
||||
changeInstance,
|
||||
|
||||
redirect,
|
||||
init,
|
||||
};
|
||||
|
|
|
@ -207,6 +207,7 @@
|
|||
<div>Maps<input type="checkbox" id="maps" /></div>
|
||||
<div>Wikipedia<input type="checkbox" id="wikipedia" /></div>
|
||||
<div>Medium<input type="checkbox" id="medium" /></div>
|
||||
<div>Send Files<input type="checkbox" id="sendTargets" /></div>
|
||||
</div>
|
||||
<hr>
|
||||
|
||||
|
|
|
@ -134,6 +134,17 @@
|
|||
<input id="disable-osm" type="checkbox" checked />
|
||||
</div>
|
||||
|
||||
<div id="sendTargets" class="some-block">
|
||||
<div class="title">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
|
||||
<path
|
||||
d="M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM14 13v4h-4v-4H7l5-5 5 5h-3z" />
|
||||
</svg>
|
||||
<h4>Send Files</h4>
|
||||
</div>
|
||||
<input id="disable-sendTargets" type="checkbox" checked />
|
||||
</div>
|
||||
|
||||
<div class="buttons-popup">
|
||||
<a class="button" id="change-instance">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
|
||||
|
|
|
@ -15,6 +15,7 @@ import mediumHelper from "../../assets/javascripts/helpers/medium.js";
|
|||
import imgurHelper from "../../assets/javascripts/helpers/imgur.js";
|
||||
import tiktokHelper from "../../assets/javascripts/helpers/tiktok.js";
|
||||
import pixivHelper from "../../assets/javascripts/helpers/pixiv.js";
|
||||
import sendTargetsHelper from "../../assets/javascripts/helpers/sendTargets.js";
|
||||
import generalHelper from "../../assets/javascripts/helpers/general.js";
|
||||
|
||||
let disableTwitterElement = document.getElementById("disable-nitter");
|
||||
|
@ -27,6 +28,7 @@ let disableSearchElement = document.getElementById("disable-search");
|
|||
let disableElement = document.getElementById("disable-simplyTranslate");
|
||||
let disableWikipediaElement = document.getElementById("disable-wikipedia");
|
||||
let disableMediumElement = document.getElementById("disable-medium");
|
||||
let disableSendTargetsElement = document.getElementById("disable-sendTargets");
|
||||
let disableImgurElement = document.getElementById("disable-imgur");
|
||||
let disableTiktokElement = document.getElementById("disable-tiktok");
|
||||
let disablePixivElement = document.getElementById("disable-pixiv");
|
||||
|
@ -44,6 +46,7 @@ async function wholeInit() {
|
|||
await imgurHelper.init()
|
||||
await tiktokHelper.init()
|
||||
await pixivHelper.init()
|
||||
await sendTargetsHelper.init()
|
||||
await mediumHelper.init()
|
||||
};
|
||||
|
||||
|
@ -115,10 +118,15 @@ disableMediumElement.addEventListener("change",
|
|||
event => mediumHelper.setDisable(!event.target.checked)
|
||||
);
|
||||
|
||||
disableSendTargetsElement.addEventListener("change",
|
||||
event => sendTargetsHelper.setDisable(!event.target.checked)
|
||||
);
|
||||
|
||||
document.getElementById("more-options").addEventListener("click",
|
||||
() => browser.runtime.openOptionsPage()
|
||||
);
|
||||
|
||||
|
||||
function changeInstance() {
|
||||
browser.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
||||
let currTab = tabs[0];
|
||||
|
@ -143,6 +151,8 @@ function changeInstance() {
|
|||
|
||||
if (!newUrl) newUrl = mediumHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = sendTargetsHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = imgurHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = wikipediaHelper.changeInstance(tabUrl)
|
||||
|
|
Loading…
Reference in New Issue