index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. (function() {
  2. handleClick('js-option', showOptions);
  3. handleClick('js-temprule', showTempRuleDropdown);
  4. handleClick('js-direct', applyProfile.bind(this, 'direct'));
  5. handleClick('js-system', applyProfile.bind(this, 'system'));
  6. OmegaPopup.addTempRule = addTempRule;
  7. OmegaPopup.setDefaultProfile = setDefaultProfile;
  8. OmegaPopup.applyProfile = applyProfile;
  9. return;
  10. function handleClick(id, handler) {
  11. document.getElementById(id).addEventListener('click', handler, false);
  12. }
  13. function closePopup() {
  14. window.close();
  15. // If the popup is opened as a tab, the above won't work. Let's reload then.
  16. document.body.style.opacity = 0;
  17. setTimeout(function() { history.go(0); }, 300);
  18. }
  19. function showOptions(e) {
  20. if (typeof OmegaTargetPopup !== 'undefined') {
  21. try {
  22. OmegaTargetPopup.openOptions(null, closePopup);
  23. e.preventDefault();
  24. } catch (_) {
  25. }
  26. }
  27. }
  28. function applyProfile(profileName) {
  29. $script.ready('om-target', function() {
  30. OmegaTargetPopup.applyProfile(profileName, closePopup);
  31. });
  32. }
  33. function setDefaultProfile(profileName, defaultProfileName) {
  34. $script.ready('om-target', function() {
  35. OmegaTargetPopup.setDefaultProfile(profileName, defaultProfileName,
  36. closePopup);
  37. });
  38. }
  39. function addTempRule(domain, profileName) {
  40. $script.ready('om-target', function() {
  41. OmegaTargetPopup.addTempRule(domain, profileName, closePopup);
  42. });
  43. }
  44. function showTempRuleDropdown() {
  45. $script.ready('om-dropdowns', function() {
  46. OmegaPopup.showTempRuleDropdown();
  47. });
  48. }
  49. })();