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

backgroundPage.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. sites_url = "https://raw.githubusercontent.com/RSF-RWB/collateralfreedom/master/sites.json"
  2. sites = {}
  3. domain_regexp = /:\/\/(www\.)?([^\/]+)\//
  4. function getSitesAndMirrors() {
  5. $.getJSON(sites_url).done(function(data) { chrome.storage.local.set({"sites": data}) })
  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 updateTab() {
  20. getCurrentTabUrl(function(url) {
  21. chrome.storage.local.get("sites", function(sites){
  22. sites = sites.sites
  23. if(url.match(domain_regexp)) {
  24. // Skipping detection for about:* pages
  25. domain = url.match(domain_regexp).slice(-1)[0]
  26. if(domain in sites) {
  27. chrome.browserAction.setIcon({path: 'rsc/icon-red.png'})
  28. }
  29. else {
  30. chrome.browserAction.setIcon({path: 'rsc/icon.png'})
  31. }
  32. }
  33. })
  34. })
  35. }
  36. chrome.tabs.onActivated.addListener(updateTab)
  37. chrome.tabs.onUpdated.addListener(updateTab)
  38. getSitesAndMirrors()