aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBobIsMyManager <bimmgitsignature.nly8m@simplelogin.co>2022-08-02 10:46:42 +0100
committerBobIsMyManager <bimmgitsignature.nly8m@simplelogin.co>2022-08-02 22:02:35 +0100
commit6a1ac047915a997b7b638a94436a32f00376ead6 (patch)
tree49be1057527f4a2dc17e8c8ab83b4ce1ffa62dc4
parenthttp status (diff)
downloadlibredirect-6a1ac047915a997b7b638a94436a32f00376ead6.zip
Begin work on instagram unify settings
Diffstat (limited to '')
-rw-r--r--src/assets/javascripts/instagram.js54
-rw-r--r--src/assets/javascripts/utils.js97
2 files changed, 151 insertions, 0 deletions
diff --git a/src/assets/javascripts/instagram.js b/src/assets/javascripts/instagram.js
index 45a27cb2..1690c84a 100644
--- a/src/assets/javascripts/instagram.js
+++ b/src/assets/javascripts/instagram.js
@@ -76,6 +76,58 @@ function init() {
init()
browser.storage.onChanged.addListener(init)
+function initBibliogramPreferences(test, from) {
+ return new Promise(async resolve => {
+ await init()
+ const protocolHost = utils.protocolHost(from)
+ if (
+ ![
+ ...bibliogramNormalRedirectsChecks,
+ ...bibliogramTorRedirectsChecks,
+ ...bibliogramNormalCustomRedirects,
+ ...bibliogramTorCustomRedirects,
+ ...bibliogramI2pCustomRedirects,
+ ...bibliogramLokiCustomRedirects,
+ ].includes(protocolHost)
+ ) {
+ resolve()
+ return
+ }
+
+ if (!test) {
+ let checkedInstances = []
+ if (protocol == "loki") checkedInstances = [...bibliogramLokiCustomRedirects]
+ else if (protocol == "i2p") checkedInstances = [...bibliogramI2pCustomRedirects]
+ else if (protocol == "tor") checkedInstances = [...bibliogramTorRedirectsChecks, ...bibliogramTorCustomRedirects]
+ if ((checkedInstances.length === 0 && protocolFallback) || protocol == "normal") {
+ checkedInstances = [...bibliogramNormalRedirectsChecks, ...bibliogramNormalCustomRedirects]
+ }
+ utils.getPreferencesFromToken("bibliogram", from, checkedInstances, "settings", "/settings.json")
+ utils.setPreferencesFromToken("bibliogram", checkedInstances, "settings")
+ }
+ resolve(true)
+ })
+}
+
+function setBibliogramPreferences() {
+ return new Promise(async resolve => {
+ await init()
+ if (disableInstagram || protocol === undefined) {
+ resolve()
+ return
+ }
+ let checkedInstances = []
+ if (protocol == "loki") checkedInstances = [...bibliogramLokiCustomRedirects]
+ else if (protocol == "i2p") checkedInstances = [...bibliogramI2pCustomRedirects]
+ else if (protocol == "tor") checkedInstances = [...bibliogramTorRedirectsChecks, ...bibliogramTorCustomRedirects]
+ if ((checkedInstances.length === 0 && protocolFallback) || protocol == "normal") {
+ checkedInstances = [...bibliogramNormalRedirectsChecks, ...bibliogramNormalCustomRedirects]
+ }
+ utils.setPreferencesFromToken("bibliogram", checkedInstances, "settings")
+ resolve()
+ })
+}
+
function all() {
return [
...bibliogramNormalRedirectsChecks,
@@ -201,6 +253,8 @@ function initDefaults() {
export default {
setRedirects,
+ initBibliogramPreferences,
+ setBibliogramPreferences,
reverse,
redirect,
initDefaults,
diff --git a/src/assets/javascripts/utils.js b/src/assets/javascripts/utils.js
index 929b5c17..59beeac7 100644
--- a/src/assets/javascripts/utils.js
+++ b/src/assets/javascripts/utils.js
@@ -402,6 +402,100 @@ function getCookiesFromStorage(frontend, urls, name) {
})
}
+function getPreferencesFromToken(frontend, targetUrl, urls, name, endpoint) {
+ return new Promise(resolve => {
+ browser.storage.local.get("firstPartyIsolate", r => {
+ let query
+ if (!r.firstPartyIsolate) query = { url: protocolHost(targetUrl), name: name }
+ else
+ query = {
+ url: protocolHost(targetUrl),
+ name: name,
+ firstPartyDomain: null,
+ }
+ browser.cookies.getAll(query, async cookies => {
+ for (const cookie of cookies)
+ if (cookie.name == name) {
+ const setQuery = r.firstPartyIsolate
+ ? {
+ url: targetUrl,
+ name: name,
+ value: cookie.value,
+ secure: true,
+ firstPartyDomain: new URL(targetUrl).hostname,
+ }
+ : {
+ url: targetUrl,
+ name: name,
+ value: cookie.value,
+ secure: true,
+ expirationDate: cookie.expirationDate,
+ }
+ console.log(toString(targetUrl))
+ const http = new XMLHttpRequest();
+ http.open("GET", targetUrl + endpoint)
+ http.setRequestHeader("Cookie", name + "=" + cookie.value)
+ http.send(null)
+ const preferences = http.responseText
+ //console.log(preferences)
+
+
+ browser.cookies.set(setQuery, () => browser.storage.local.set({ [`${frontend}_${name}`]: preferences }, () => resolve()))
+ break
+ }
+ resolve()
+ })
+ })
+ })
+}
+
+
+function setPreferencesFromToken(frontend, urls, name) {
+ let key = `${frontend}_${name}`
+ let formdata = ""
+ browser.storage.local.get(key, r => {
+ //console.log(r[key])
+ const preferences = JSON.parse(r[key])
+ if (preferences === undefined) return
+ for (const prefName of names(preferences)) {
+ if (formdata != "") {
+ formdata += "&"
+ }
+ formdata += prefName + "=" + preferences[prefName]
+ }
+ for (const url of urls) {
+
+ const http = new XMLHttpRequest();
+ http.open("POST", url + "/settings")
+ http.send(formdata)
+
+
+
+
+
+ /*
+ let query = r.firstPartyIsolate
+ ? {
+ url: url,
+ name: cookie.name,
+ value: cookie.value,
+ secure: true,
+ expirationDate: null,
+ firstPartyDomain: new URL(url).hostname,
+ }
+ : {
+ url: url,
+ name: cookie.name,
+ value: cookie.value,
+ secure: true,
+ expirationDate: cookie.expirationDate,
+ }
+ browser.cookies.set(query)
+ */
+ }
+ })
+}
+
function copyRaw(test, copyRawElement) {
return new Promise(resolve => {
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
@@ -471,6 +565,7 @@ function unify(test) {
if (!result) result = await wikipediaHelper.initWikilessCookies(test, url)
if (!result) result = await translateHelper.copyPasteSimplyTranslateCookies(test, url)
if (!result) result = await translateHelper.copyPasteLingvaLocalStorage(test, url)
+ if (!result) result = await instagramHelper.initBibliogramPreferences(test, url)
resolve(result)
}
@@ -545,6 +640,8 @@ export default {
latency,
copyCookie,
getCookiesFromStorage,
+ getPreferencesFromToken,
+ setPreferencesFromToken,
switchInstance,
copyRaw,
unify,