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

index.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. function takeMeTo(url) {
  20. updateProperties = {
  21. url: "https://" + url
  22. }
  23. chrome.tabs.update(updateProperties=updateProperties)
  24. }
  25. // Wait for the DOM to load before doing anything
  26. jQuery(document).ready(function() {
  27. // Check if there's a mirror for the current URL. If so, display the message
  28. // about it and the button to redirect to a random mirror (if there's more than
  29. // one).
  30. getCurrentTabUrl(function(url) {
  31. chrome.storage.local.get("sites", function(sites){
  32. sites = sites.sites
  33. // Grab the domain part of the URL
  34. domain = url.match(/:\/\/(www\.)?([^\/]+)\//).slice(-1)[0]
  35. if(domain in sites) {
  36. proxies = sites[domain]
  37. // Offer the user to redirect them to a mirror
  38. $("#mirror").css("display", "block")
  39. $("#nomirror").css("display", "none")
  40. $("#mirror button").on("click", function() {
  41. takeMeTo(proxies[Math.floor(Math.random()*proxies.length)])
  42. })
  43. }
  44. else {
  45. // Tell the user there's no mirror available
  46. $("#mirror").css("display", "none")
  47. $("#nomirror").css("display", "block")
  48. }
  49. })
  50. })
  51. })