Find access to blocked websites https://rsf.org/collateral-freedom

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Get the current URL.
  3. *
  4. * @param {function(string)} callback - called when the URL of the current tab
  5. * is found.
  6. */
  7. function getCurrentTabUrl(callback) {
  8. var queryInfo = {
  9. active: true,
  10. currentWindow: true
  11. };
  12. chrome.tabs.query(queryInfo, function(tabs) {
  13. var tab = tabs[0];
  14. var url = tab.url;
  15. console.assert(typeof url == 'string', 'tab.url should be a string');
  16. callback(url);
  17. });
  18. }
  19. // Redirect to mirror url
  20. function takeMeTo(url) {
  21. let updateProperties = {
  22. url: "https://" + url
  23. }
  24. chrome.tabs.update(updateProperties=updateProperties)
  25. }
  26. // Wait for the DOM to load before doing anything
  27. jQuery(document).ready(function() {
  28. // Check if there's a mirror for the current URL. If so, display the message
  29. // about it and the button to redirect to a random mirror (if there's more than
  30. // one).
  31. getCurrentTabUrl(function(url) {
  32. chrome.storage.local.get("sites", function(localSites){
  33. sites = localSites.sites
  34. // Grab the domain part of the URL
  35. let domain = url.match(/:\/\/(www\.)?([^\/]+)\//).slice(-1)[0]
  36. console.log(domain);
  37. console.log(sites);
  38. if(domain in sites) {
  39. let proxies = sites[domain]
  40. // Offer the user to redirect them to a mirror
  41. $("#mirror").css("display", "block")
  42. $("#nomirror").css("display", "none")
  43. $("#mirror button").on("click", function() {
  44. takeMeTo(proxies[Math.floor(Math.random()*proxies.length)])
  45. })
  46. }
  47. else {
  48. // Tell the user there's no mirror available
  49. $("#mirror").css("display", "none")
  50. $("#nomirror").css("display", "block")
  51. }
  52. })
  53. })
  54. })