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

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