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

popup.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (c) 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. /**
  5. * Get the current URL.
  6. *
  7. * @param {function(string)} callback - called when the URL of the current tab
  8. * is found.
  9. */
  10. function getCurrentTabUrl(callback) {
  11. // Query filter to be passed to chrome.tabs.query - see
  12. // https://developer.chrome.com/extensions/tabs#method-query
  13. var queryInfo = {
  14. active: true,
  15. currentWindow: true
  16. };
  17. chrome.tabs.query(queryInfo, function(tabs) {
  18. // chrome.tabs.query invokes the callback with a list of tabs that match the
  19. // query. When the popup is opened, there is certainly a window and at least
  20. // one tab, so we can safely assume that |tabs| is a non-empty array.
  21. // A window can only have one active tab at a time, so the array consists of
  22. // exactly one tab.
  23. var tab = tabs[0];
  24. // A tab is a plain object that provides information about the tab.
  25. // See https://developer.chrome.com/extensions/tabs#type-Tab
  26. var url = tab.url;
  27. // tab.url is only available if the "activeTab" permission is declared.
  28. // If you want to see the URL of other tabs (e.g. after removing active:true
  29. // from |queryInfo|), then the "tabs" permission is required to see their
  30. // "url" properties.
  31. console.assert(typeof url == 'string', 'tab.url should be a string');
  32. callback(url);
  33. });
  34. // Most methods of the Chrome extension APIs are asynchronous. This means that
  35. // you CANNOT do something like this:
  36. //
  37. // var url;
  38. // chrome.tabs.query(queryInfo, function(tabs) {
  39. // url = tabs[0].url;
  40. // });
  41. // alert(url); // Shows "undefined", because chrome.tabs.query is async.
  42. }
  43. function renderStatus(statusText) {
  44. document.getElementById('status').textContent = statusText;
  45. }
  46. getCurrentTabUrl(function(url) {
  47. renderStatus(url.match(/:\/\/(.+)\//)[1])
  48. })