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

eventPage.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var sites_url = "https://raw.githubusercontent.com/RSF-RWB/collateralfreedom/master/sites.json"
  2. var sites = {}
  3. var 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. let domain = url.match(domain_regexp).slice(-1)[0]
  24. if(domain in sites) {
  25. chrome.browserAction.setIcon({path: 'rsc/icon-red.png'})
  26. }
  27. else {
  28. chrome.browserAction.setIcon({path: 'rsc/icon.png'})
  29. }
  30. })
  31. })
  32. }
  33. chrome.runtime.onStartup.addListener(getSitesAndMirrors)
  34. chrome.runtime.onInstalled.addListener(getSitesAndMirrors)
  35. chrome.tabs.onActivated.addListener(updateTab)
  36. chrome.tabs.onUpdated.addListener(updateTab)