Firefox 的扩展会泄漏内存,并且随着时间的推移,会消耗越来越多的 CPU。可以通过禁用/启用它们来重置此问题。有没有办法循环启用所有活动扩展的状态,而不必为每个扩展手动执行此操作?
答案1
这是一个非常粗糙的 JavaScript 解决方案:
function clickToggleButtons() {
// Static XPath to count the number of nodes
var staticXPath = '/html/body/div/div[2]/div/addon-list/section[1]/addon-card/div/div/div/div/moz-toggle';
// Evaluate the static XPath expression to get a node list
var staticXPathResult = document.evaluate(staticXPath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
// Count the number of nodes
var numberOfNodes = staticXPathResult.snapshotLength;
// Variable XPath to loop through nodes
var baseXPath = '/html/body/div/div[2]/div/addon-list/section[1]/addon-card[%d]/div/div/div/div/moz-toggle';
// Loop through each toggle button
for (var i = 1; i <= numberOfNodes; i++) {
// Construct the XPath for the current toggle button
var currentXPath = baseXPath.replace('%d', i);
// Select the toggle button using the constructed XPath
var button = document.evaluate(currentXPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
// Click the toggle button
button.click();
// Wait for 3 seconds before clicking it again
setTimeout(function(currentButton) {
return function() {
currentButton.click();
};
}(button), 10000);
}
}
// Call the function to start the process
clickToggleButtons();
欢迎改进!
只需打开 Web 检查器,单击“控制台”,粘贴并按 Enter 键。如果您有很多扩展,可能需要一些时间才能重新激活它们。它不是超级稳定的,因此在运行它之前请记下所有活动的扩展,以防它无法重新激活其中一些,这样您就可以手动执行此操作。