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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. sites_url = "sites.json"
  2. sites = {}
  3. function getSitesAndMirrors() {
  4. $.getJSON("http://host.brendanabolivier.com/files/56bf24564ab24.json")
  5. .done(function(data) { chrome.storage.local.set({"sites": data}) })
  6. }
  7. function getCurrentTabUrl(callback) {
  8. // Query filter to be passed to chrome.tabs.query - see
  9. // https://developer.chrome.com/extensions/tabs#method-query
  10. var queryInfo = {
  11. active: true,
  12. currentWindow: true
  13. };
  14. chrome.tabs.query(queryInfo, function(tabs) {
  15. // chrome.tabs.query invokes the callback with a list of tabs that match the
  16. // query. When the popup is opened, there is certainly a window and at least
  17. // one tab, so we can safely assume that |tabs| is a non-empty array.
  18. // A window can only have one active tab at a time, so the array consists of
  19. // exactly one tab.
  20. var tab = tabs[0];
  21. // A tab is a plain object that provides information about the tab.
  22. // See https://developer.chrome.com/extensions/tabs#type-Tab
  23. var url = tab.url;
  24. // tab.url is only available if the "activeTab" permission is declared.
  25. // If you want to see the URL of other tabs (e.g. after removing active:true
  26. // from |queryInfo|), then the "tabs" permission is required to see their
  27. // "url" properties.
  28. console.assert(typeof url == 'string', 'tab.url should be a string');
  29. callback(url);
  30. });
  31. // Most methods of the Chrome extension APIs are asynchronous. This means that
  32. // you CANNOT do something like this:
  33. //
  34. // var url;
  35. // chrome.tabs.query(queryInfo, function(tabs) {
  36. // url = tabs[0].url;
  37. // });
  38. // alert(url); // Shows "undefined", because chrome.tabs.query is async.
  39. }
  40. function updateTab() {
  41. getCurrentTabUrl(function(url) {
  42. chrome.storage.local.get("sites", function(sites){
  43. sites = sites.sites
  44. if(url.match(/:\/\/(.+)\//)[1] in sites) {
  45. chrome.browserAction.setIcon({path: 'icon-red.png'})
  46. }
  47. else {
  48. chrome.browserAction.setIcon({path: 'icon.png'})
  49. }
  50. })
  51. })
  52. }
  53. chrome.runtime.onStartup.addListener(getSitesAndMirrors)
  54. chrome.runtime.onInstalled.addListener(getSitesAndMirrors)
  55. chrome.tabs.onActivated.addListener(updateTab)
  56. chrome.tabs.onUpdated.addListener(updateTab)