Skip to content

Instantly share code, notes, and snippets.

@munael
Last active February 5, 2021 13:20
Show Gist options
  • Save munael/37f48cec7ecd17f94de551c91f3e4130 to your computer and use it in GitHub Desktop.
Save munael/37f48cec7ecd17f94de551c91f3e4130 to your computer and use it in GitHub Desktop.
Update all active session URLs on Chrome
function fix_url(url) {
var bad = "";
var good = "";
return url.replace(bad, good);
}
chrome.tabs.query({}, function(tabs){
console.log(`Found ${tabs.length} tabs to update.`)
var _count = 0;
var n_changed = 0;
// tabs = tabs.slice(0, tabs.length);
for (var tb of tabs) {
var fixed_url = correct_url(tb.url);
_count += 1;
if (fixed_url != tb.url) {
n_changed += 1;
chrome.tabs.update(tb.id, {url: fixed_url});
}
if (_count % 100 == 0) {
console.log(`Finished ${_count}-th tab. Changed total: ${n_changed}.`);
}
}
console.log(`Finished ${_count}-th tab. Changed total: ${n_changed}.`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment