我有一个标签旋转扩展名。只需每隔几秒切换到下一个选项卡(可配置,名为interval
/ newInterval
)。当我加载解压缩的扩展时,一切正常,但是当我测试扩展后包装时,重新加载功能没有触发。我清除间隔并重新加载扩展。当我调用onInstalled.addListener
时,runtime.reload()
触发了解压扩展名,但没有打包版本。有什么想法吗?
// rotationOptions.js(扩展选项脚本)
intervalSaveButton.onclick = function() {
clearInterval();
const newInterval = intervalInput.value;
chrome.storage.sync.set({'rotationInterval': newInterval}, function() {
chrome.runtime.reload();
});
};
// rotateTabs.js(后台脚本)
chrome.runtime.onInstalled.addListener(function() {
chrome.storage.sync.set({'rotation': true});
chrome.storage.sync.get('rotationInterval', function(data) {
if (!data || data.rotationInterval === null || data.rotationInterval === undefined) {
chrome.storage.sync.set({'rotationInterval': 5000});
setInterval(cycleNextTab, 5000);
} else {
setInterval(cycleNextTab, data.rotationInterval);
}
});
});
function cycleNextTab () {
chrome.storage.sync.get('rotation', function (data) {
if (data.rotation) {
chrome.tabs.query({active: true, currentWindow: true}, function(tab) {
const currentTabIndex = tab[0].index;
chrome.tabs.query({}, function(tabs) {
const nextIndex = (currentTabIndex + 1) === tabs.length ? 0 : currentTabIndex + 1;
const nextTabId = tabs[nextIndex].id;
chrome.tabs.update(nextTabId, { active: true });
chrome.tabs.update(nextTabId, {url: tabs[nextIndex].url});
});
});
}
});
}