diff --git a/admin_menu.js b/admin_menu.js
index de0bb90..4be395d 100644
--- a/admin_menu.js
+++ b/admin_menu.js
@@ -53,48 +53,6 @@ Drupal.behaviors.adminMenu = {
 };
 
 /**
- * Collapse fieldsets on Modules page.
- */
-Drupal.behaviors.adminMenuCollapseModules = {
-  attach: function (context, settings) {
-    if (settings.admin_menu.tweak_modules) {
-      $('#system-modules fieldset:not(.collapsed)', context).addClass('collapsed');
-    }
-  }
-};
-
-/**
- * Collapse modules on Permissions page.
- */
-Drupal.behaviors.adminMenuCollapsePermissions = {
-  attach: function (context, settings) {
-    if (settings.admin_menu.tweak_permissions) {
-      // Freeze width of first column to prevent jumping.
-      $('#permissions th:first', context).css({ width: $('#permissions th:first', context).width() });
-      // Attach click handler.
-      $modules = $('#permissions tr:has(td.module)', context).once('admin-menu-tweak-permissions', function () {
-        var $module = $(this);
-        $module.bind('click.admin-menu', function () {
-          // @todo Replace with .nextUntil() in jQuery 1.4.
-          $module.nextAll().each(function () {
-            var $row = $(this);
-            if ($row.is(':has(td.module)')) {
-              return false;
-            }
-            $row.toggleClass('element-hidden');
-          });
-        });
-      });
-      // Collapse all but the targeted permission rows set.
-      if (window.location.hash.length) {
-        $modules = $modules.not(':has(' + window.location.hash + ')');
-      }
-      $modules.trigger('click.admin-menu');
-    }
-  }
-};
-
-/**
  * Apply margin to page.
  *
  * Note that directly applying marginTop does not work in IE. To prevent
diff --git a/admin_menu.module b/admin_menu.module
index 8a8dee1..d70655c 100644
--- a/admin_menu.module
+++ b/admin_menu.module
@@ -233,12 +233,6 @@ function admin_menu_page_build(&$page) {
   if ($setting = variable_get('admin_menu_tweak_tabs', 0)) {
     $settings['tweak_tabs'] = $setting;
   }
-  if ($_GET['q'] == 'admin/modules' || strpos($_GET['q'], 'admin/modules/list') === 0) {
-    $settings['tweak_modules'] = variable_get('admin_menu_tweak_modules', 0);
-  }
-  if ($_GET['q'] == 'admin/people/permissions' || $_GET['q'] == 'admin/people/permissions/list') {
-    $settings['tweak_permissions'] = variable_get('admin_menu_tweak_permissions', 0);
-  }
 
   $attached['js'][] = array(
     'data' => array('admin_menu' => $settings),
@@ -848,6 +842,28 @@ function admin_menu_form_alter_flush_cache_submit($form, &$form_state) {
 }
 
 /**
+ * Implements hook_form_FORM_ID_alter() for system_modules().
+ */
+function admin_menu_form_system_modules_alter(&$form, &$form_state) {
+  $form['#attached']['js'][] = drupal_get_path('module', 'admin_menu') . '/admin_menu.tweaks.js';
+  $form['#attached']['js'][] = array(
+    'data' => array('admin_menu' => array('tweak_modules' => variable_get('admin_menu_tweak_modules', 0))),
+    'type' => 'setting',
+  );
+}
+
+/**
+ * Implements hook_form_FORM_ID_alter() for user_admin_permissions().
+ */
+function admin_menu_form_user_admin_permissions_alter(&$form, &$form_state) {
+  $form['#attached']['js'][] = drupal_get_path('module', 'admin_menu') . '/admin_menu.tweaks.js';
+  $form['#attached']['js'][] = array(
+    'data' => array('admin_menu' => array('tweak_permissions' => variable_get('admin_menu_tweak_permissions', 0))),
+    'type' => 'setting',
+  );
+}
+
+/**
  * Implements hook_form_FORM_ID_alter().
  *
  * Extends Devel module with Administration menu developer settings.
diff --git a/admin_menu.tweaks.js b/admin_menu.tweaks.js
new file mode 100644
index 0000000..05d1283
--- /dev/null
+++ b/admin_menu.tweaks.js
@@ -0,0 +1,50 @@
+/**
+ * @file
+ * Javascript to collapse elements on 'Modules' and 'Permissions' pages.
+ */
+
+(function ($) {
+
+/**
+ * Collapse fieldsets on Modules page.
+ */
+Drupal.behaviors.adminMenuCollapseModules = {
+  attach: function (context, settings) {
+    if (settings.admin_menu.tweak_modules) {
+      $('#system-modules fieldset:not(.collapsed)', context).addClass('collapsed');
+    }
+  }
+};
+
+/**
+ * Collapse modules on Permissions page.
+ */
+Drupal.behaviors.adminMenuCollapsePermissions = {
+  attach: function (context, settings) {
+    if (settings.admin_menu.tweak_permissions) {
+      // Freeze width of first column to prevent jumping.
+      $('#permissions th:first', context).css({ width: $('#permissions th:first', context).width() });
+      // Attach click handler.
+      $modules = $('#permissions tr:has(td.module)', context).once('admin-menu-tweak-permissions', function () {
+        var $module = $(this);
+        $module.bind('click.admin-menu', function () {
+          // @todo Replace with .nextUntil() in jQuery 1.4.
+          $module.nextAll().each(function () {
+            var $row = $(this);
+            if ($row.is(':has(td.module)')) {
+              return false;
+            }
+            $row.toggleClass('element-hidden');
+          });
+        });
+      });
+      // Collapse all but the targeted permission rows set.
+      if (window.location.hash.length) {
+        $modules = $modules.not(':has(' + window.location.hash + ')');
+      }
+      $modules.trigger('click.admin-menu');
+    }
+  }
+};
+
+})(jQuery);
