Fixed maps. RTL to default instances checklist. Unify not working in chrmoium

This commit is contained in:
ManeraKai 2022-06-09 10:32:09 +03:00
parent 8c1b5509c0
commit 22b687876a
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
4 changed files with 67 additions and 51 deletions

View File

@ -127,9 +127,8 @@ function redirect(url, initiator) {
prefs.marker = coords;
prefs.layer = "mapnik";
let prefsEncoded = new URLSearchParams(prefs).toString();
if (mapsFrontend == 'osm') { resolve(`${randomInstance}/export/embed.html?${prefsEncoded}`); return; }
if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${query}`); return; }
if (mapsFrontend == 'osm') return `${randomInstance}/export/embed.html?${prefsEncoded}`;
if (mapsFrontend == 'facil') return `${randomInstance}/#q=${query}`;
} else if (url.pathname.includes("/dir")) { // Handle Google Maps Directions
// https://www.google.com/maps/dir/?api=1&origin=Space+Needle+Seattle+WA&destination=Pike+Place+Market+Seattle+WA&travelmode=bicycling
@ -145,8 +144,8 @@ function redirect(url, initiator) {
prefs.route = `${org};${dest}`;
let prefsEncoded = new URLSearchParams(prefs).toString();
if (mapsFrontend == 'osm') { resolve(`${randomInstance}/directions?${prefsEncoded}${mapCentre}`); return; }
if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${orgVal}%20to%20${destVal}%20by%20${travelModesFacil[travMod]}`); return; }
if (mapsFrontend == 'osm') return `${randomInstance}/directions?${prefsEncoded}${mapCentre}`;
if (mapsFrontend == 'facil') return `${randomInstance}/#q=${orgVal}%20to%20${destVal}%20by%20${travelModesFacil[travMod]}`;
} else if (url.pathname.includes("data=") && url.pathname.match(dataLatLngRegex)) { // Get marker from data attribute
// https://www.google.com/maps/place/41%C2%B001'58.2%22N+40%C2%B029'18.2%22E/@41.032833,40.4862063,17z/data=!3m1!4b1!4m6!3m5!1s0x0:0xf64286eaf72fc49d!7e2!8m2!3d41.0328329!4d40.4883948
@ -154,8 +153,8 @@ function redirect(url, initiator) {
let [, mlat, mlon] = url.pathname.match(dataLatLngRegex);
if (mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query=${mlat}%2C${mlon}`); return; }
if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${mlat}%2C${mlon}`); return; }
if (mapsFrontend == 'osm') return `${randomInstance}/search?query=${mlat}%2C${mlon}`;
if (mapsFrontend == 'facil') return `${randomInstance}/#q=${mlat}%2C${mlon}`;
} else if (url.searchParams.has("ll")) { // Get marker from ll param
// https://maps.google.com/?ll=38.882147,-76.99017
@ -163,16 +162,16 @@ function redirect(url, initiator) {
const [mlat, mlon] = url.searchParams.get("ll").split(",");
if (mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query=${mlat}%2C${mlon}`); return; }
if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${mlat}%2C${mlon}`); return; }
if (mapsFrontend == 'osm') return `${randomInstance}/search?query=${mlat}%2C${mlon}`;
if (mapsFrontend == 'facil') return `${randomInstance}/#q=${mlat}%2C${mlon}`
} else if (url.searchParams.has("viewpoint")) { // Get marker from viewpoint param.
// https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=48.857832,2.295226&heading=-45&pitch=38&fov=80
console.log("viewpoint life");
const [mlat, mlon] = url.searchParams.get("viewpoint").split(",");
if (mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query=${mlat}%2C${mlon}`); return; }
if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${mlat}%2C${mlon}`); return; }
if (mapsFrontend == 'osm') return `${randomInstance}/search?query=${mlat}%2C${mlon}`;
if (mapsFrontend == 'facil') return `${randomInstance}/#q=${mlat}%2C${mlon}`;
} else { // Use query as search if present.
console.log("normal life");
@ -183,8 +182,8 @@ function redirect(url, initiator) {
let prefsEncoded = new URLSearchParams(prefs).toString();
if (query) {
if (mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query="${query}${mapCentre}&${prefsEncoded}`); return; }
if (mapsFrontend == 'facil') { resolve(`${randomInstance}/${mapCentre}/Mpnk/${query}`); return; }
if (mapsFrontend == 'osm') return `${randomInstance}/search?query="${query}${mapCentre}&${prefsEncoded}`;
if (mapsFrontend == 'facil') return `${randomInstance}/${mapCentre}/Mpnk/${query}`;
}
}
@ -192,8 +191,8 @@ function redirect(url, initiator) {
console.log("mapCentre", mapCentre);
console.log("prefs", prefs);
console.log("prefsEncoded", prefsEncoded);
if (mapsFrontend == 'osm') { resolve(`${randomInstance}/${mapCentre}&${prefsEncoded}`); return; }
if (mapsFrontend == 'facil') { resolve(`${randomInstance}/${mapCentre}/Mpnk`); return; }
if (mapsFrontend == 'osm') return `${randomInstance}/${mapCentre}&${prefsEncoded}`;
if (mapsFrontend == 'facil') return `${randomInstance}/${mapCentre}/Mpnk`;
}
async function initDefaults() {

View File

@ -286,36 +286,50 @@ async function testLatency(element, instances) {
function copyCookie(frontend, targetUrl, urls, name) {
return new Promise(resolve => {
let query;
if (window.chrome) query = { url: protocolHost(targetUrl), name: name }
else query = { url: protocolHost(targetUrl), name: name, firstPartyDomain: null }
browser.cookies.getAll(
{ url: protocolHost(targetUrl), name: name, firstPartyDomain: null },
cookies => {
browser.privacy.websites.firstPartyIsolate.get({},
async firstPartyIsolate => {
function setCookie(url, name, value, expirationDate) {
return new Promise(resolve =>
browser.cookies.set(
{
url: url,
name: name,
value: value,
secure: true,
firstPartyDomain: firstPartyIsolate.value ? new URL(url).hostname : '',
expirationDate: firstPartyIsolate.value ? null : expirationDate,
},
() => resolve()
)
)
query,
async cookies => {
function setCookie(url, name, value, expirationDate, firstPartyIsolate) {
return new Promise(resolve => {
let query;
if (window.chrome) query = {
url: url, name: name, value: value, secure: true,
expirationDate: expirationDate,
};
else query = {
url: url, name: name, value: value, secure: true,
firstPartyDomain: firstPartyIsolate.value ? new URL(url).hostname : '',
expirationDate: firstPartyIsolate.value ? null : expirationDate,
};
browser.cookies.set(query, () => resolve())
})
}
if (window.chrome) {
for (const cookie of cookies)
if (cookie.name == name) {
console.log('cookie', cookie);
for (const url of urls) await setCookie(url, cookie.name, cookie.value, cookie.expirationDate)
browser.storage.local.set({ [`${frontend}_${name}`]: cookie }, () => resolve())
break;
}
for (const cookie of cookies)
if (cookie.name == name) {
console.log('cookie', cookie);
for (const url of urls) await setCookie(url, cookie.name, cookie.value, cookie.expirationDate)
browser.storage.local.set({ [`${frontend}_${name}`]: cookie }, () => resolve())
break;
}
resolve();
}
)
resolve();
} else {
browser.privacy.websites.firstPartyIsolate.get({},
async firstPartyIsolate => {
for (const cookie of cookies)
if (cookie.name == name) {
console.log('cookie', cookie);
for (const url of urls) await setCookie(url, cookie.name, cookie.value, cookie.expirationDate, firstPartyIsolate)
browser.storage.local.set({ [`${frontend}_${name}`]: cookie }, () => resolve())
break;
}
resolve();
}
)
}
});
})
}
@ -363,14 +377,18 @@ function copyRaw(test, copyRawElement) {
resolve(true);
if (test) return;
navigator.clipboard.writeText(newUrl);
console.log('newUrl', newUrl)
if (copyRawElement) {
console.log('working')
const textElement = copyRawElement.getElementsByTagName('h4')[0]
const oldHtml = textElement.innerHTML;
textElement.innerHTML = browser.i18n.getMessage('copied');
setTimeout(() => textElement.innerHTML = oldHtml, 1000);
}
} else resolve()
console.log('finished')
}
}
resolve()
}
)
})
@ -406,9 +424,7 @@ function unify(test) {
if (!result) result = await translateHelper.copyPasteSimplyTranslateCookies(test, url);
if (!result) result = await translateHelper.copyPasteLingvaLocalStorage(test, url);
if (result) {
resolve(true);
} else resolve()
resolve(result);
}
}
)

View File

@ -69,10 +69,7 @@ browser.runtime.onInstalled.addListener(
)
youtubeHelper.pasteInvidiousCookies();
youtubeHelper.pastePipedLocalStorage();
youtubeHelper.pastePipedMaterialLocalStorage();
translateHelper.pasteSimplyTranslateCookies();
translateHelper.pasteLingvaLocalStorage();
twitterHelper.pasteNitterCookies();
wikipediaHelper.pasteWikilessCookies();
searchHelper.pasteSearxCookies();
@ -215,7 +212,7 @@ browser.webRequest.onErrorOccurred.addListener(
)
browser.commands.onCommand.addListener(
command => {
async command => {
if (command === 'switchInstance') utils.switchInstance();
else if (command == 'copyRaw') utils.copyRaw();
else if (command == 'unify') utils.unify();

View File

@ -341,6 +341,10 @@ button svg {
color: var(--text);
}
div.checklist{
direction: ltr;
}
div.checklist div {
justify-content: space-between;
margin: 5px 15px;