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

eventPage.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. sites_url = "sites.json"
  2. sites = {}
  3. function getSitesAndMirrors() {
  4. $.getJSON("http://host.brendanabolivier.com/files/56bf24564ab24.json")
  5. .done(function(data) { 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. if(url.match(/:\/\/(.+)\//)[1] in sites) {
  43. chrome.browserAction.setIcon({path: 'icon-red.png'})
  44. }
  45. else {
  46. chrome.browserAction.setIcon({path: 'icon.png'})
  47. }
  48. })
  49. }
  50. chrome.runtime.onStartup.addListener(getSitesAndMirrors)
  51. chrome.tabs.onActivated.addListener(updateTab)
  52. chrome.tabs.onUpdated.addListener(updateTab)