Ver Fonte

Add auto-reload option, fix #23

If checked, current tab will be reloaded after script is switched on or
off in popup menu.
Gerald há 10 anos atrás
pai
commit
3a6396bb71
5 ficheiros alterados com 13 adições e 2 exclusões
  1. 1 0
      src/common.js
  2. 2 0
      src/injected.js
  3. 4 0
      src/options/templates/tab-settings.html
  4. 6 1
      src/popup/app.js
  5. 0 1
      src/popup/model.js

+ 1 - 0
src/common.js

@@ -13,6 +13,7 @@ _.options = function () {
     closeAfterInstall: false,
     trackLocalFile: false,
     injectMode: 0,
+    autoReload: false,
   };
 
   function getOption(key, def) {

+ 2 - 0
src/injected.js

@@ -571,6 +571,7 @@ function handleC(e) {
     },
     RegisterMenu: function(data) {
       if (window.top === window) menus.push(data);
+      getPopup();
     },
     GetRequestId: getRequestId,
     HttpRequest: httpRequest,
@@ -641,6 +642,7 @@ function loadScript(data) {
   });
   comm.post({cmd: 'LoadScript', data: data});
   badge.ready = true;
+  getPopup();
   setBadge();
 }
 function initCommunicator() {

+ 4 - 0
src/options/templates/tab-settings.html

@@ -8,6 +8,10 @@
     <input type=checkbox data-check=ignoreGrant <%= it.ignoreGrant ? 'checked' : '' %>>
     <span data-i18n=labelIgnoreGrant></span>
   </label>
+  <label class="line">
+    <input type=checkbox data-check=autoReload <%= it.autoReload ? 'checked' : '' %>>
+    <span data-i18n=labelAutoReloadCurrentTab></span>
+  </label>
   <label class="line">
     <span data-i18n=labelInjectMode></span>
     <select id=sInjectMode>

+ 6 - 1
src/popup/app.js

@@ -36,11 +36,16 @@ BaseView.prototype.initI18n.call(window);
       },
     }).then(function () {
       model.set({data: data});
+      _.options.get('autoReload') && chrome.tabs.reload(app.currentTab.id);
     });
   }
+  function init() {
+    chrome.tabs.sendMessage(app.currentTab.id, {cmd: 'GetPopup'});
+  }
 
   var commands = {
     SetPopup: function (data, src, callback) {
+      if (app.currentTab.id !== src.tab.id) return;
       commandsMenu.reset(data.menus.map(function (menu) {
         return new MenuItem({
           name: menu[0],
@@ -72,6 +77,6 @@ BaseView.prototype.initI18n.call(window);
 
   chrome.tabs.query({currentWindow: true, active: true}, function (tabs) {
     app.currentTab = tabs[0];
-    chrome.tabs.sendMessage(tabs[0].id, {cmd: 'GetPopup'});
+    init();
   });
 }();

+ 0 - 1
src/popup/model.js

@@ -1,6 +1,5 @@
 var MenuItem = Backbone.Model.extend({});
 
-
 var Menu = Backbone.Collection.extend({
   model: MenuItem,
 });