diff options
author | HKalbasi <45197576+HKalbasi@users.noreply.github.com> | 2021-12-27 00:28:31 +0330 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-27 00:28:31 +0330 |
commit | 4af57f376398ff38d7d3fb7697159d93406142c4 (patch) | |
tree | e0b27655d3019a82308f952bc8937c0193289567 /src | |
parent | png libredirect (diff) | |
parent | set pools in update (diff) | |
download | libredirect-4af57f376398ff38d7d3fb7697159d93406142c4.zip |
Merge pull request #8 from libredirect/dynamic-instance
Fetch instances dynamically
Diffstat (limited to 'src')
-rw-r--r-- | src/pages/popup/popup.html | 3 | ||||
-rw-r--r-- | src/pages/popup/popup.js | 18 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/pages/popup/popup.html b/src/pages/popup/popup.html index 9eb6e229..68cd7632 100644 --- a/src/pages/popup/popup.html +++ b/src/pages/popup/popup.html @@ -235,6 +235,9 @@ <section class="settings-block"></section> <footer> + <a class="button" id="update-instances"> + <span data-localise="__MSG_updateInstances__">Update Instances </span> + </a> <a class="button" id="more-options"> <span data-localise="__MSG_moreOptions__">More Options </span> <svg diff --git a/src/pages/popup/popup.js b/src/pages/popup/popup.js index 13d04f6b..d2b33b6a 100644 --- a/src/pages/popup/popup.js +++ b/src/pages/popup/popup.js @@ -78,6 +78,24 @@ disableScribe.addEventListener("change", (event) => { browser.storage.sync.set({ disableScribe: !event.target.checked }); }); +const apiEndpoint = 'https://raw.githubusercontent.com/libredirect/instances/main/data.json'; + +document.querySelector("#update-instances").addEventListener("click", () => { + let request = new XMLHttpRequest(); + request.open('GET', apiEndpoint, false); + request.send(null); + + if (request.status === 200) { + document.querySelector("#update-instances").innerHTML = 'gav'; + const instances = JSON.parse(request.responseText); + const nitterRandomPool = instances.twitter.join(','); + const invidiousRandomPool = instances.youtube.join(','); + const bibliogramRandomPool = instances.instagram.join(','); + browser.storage.sync.set({ nitterRandomPool, invidiousRandomPool, bibliogramRandomPool }); + document.querySelector("#update-instances").innerHTML = 'Done!'; + } +}); + document.querySelector("#more-options").addEventListener("click", () => { browser.runtime.openOptionsPage(); }); |