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

backgroundPage.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. sites_url = "https://raw.githubusercontent.com/RSF-RWB/collateralfreedom/master/sites.json"
  2. sites = {}
  3. domain_regexp = /:\/\/(www\.)?([^\/]+)\//
  4. // Retrieve the list of mirrors
  5. function getSitesAndMirrors() {
  6. $.getJSON(sites_url).done(function(data) { chrome.storage.local.set({"sites": data}) })
  7. }
  8. // Get the URL on the current tab
  9. function getCurrentTabUrl(callback) {
  10. var queryInfo = {
  11. active: true,
  12. currentWindow: true
  13. };
  14. chrome.tabs.query(queryInfo, function(tabs) {
  15. var tab = tabs[0];
  16. var url = tab.url;
  17. console.assert(typeof url == 'string', 'tab.url should be a string');
  18. callback(url);
  19. });
  20. }
  21. // Check if the URL on the current tab is bound to a list of mirrors. If so,
  22. // indicate it to the user by turning the icon red.
  23. function updateTab() {
  24. getCurrentTabUrl(function(url) {
  25. chrome.storage.local.get("sites", function(sites){
  26. sites = sites.sites
  27. if(url.match(domain_regexp)) {
  28. // Skipping detection for about:* pages
  29. domain = url.match(domain_regexp).slice(-1)[0]
  30. if(domain in sites) {
  31. chrome.browserAction.setIcon({path: 'rsc/icon-red.png'})
  32. }
  33. else {
  34. chrome.browserAction.setIcon({path: 'rsc/icon.png'})
  35. }
  36. }
  37. })
  38. })
  39. }
  40. // Run the updateTab() function on tab switch (Ctrl+Tab), creation or target
  41. // update
  42. chrome.tabs.onActivated.addListener(updateTab)
  43. chrome.tabs.onUpdated.addListener(updateTab)
  44. // Fetch the list of mirrors on startup
  45. getSitesAndMirrors()