Skip to content

Commit

Permalink
Merge pull request #3 from luke-jr/migrate
Browse files Browse the repository at this point in the history
Support migration from TGS with other extension ids
  • Loading branch information
aciidic committed Feb 6, 2021
2 parents 28db43b + 9beda96 commit d67e5f6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
"html_history_recent_sessions": { "message": "Recent sessions" },
"html_history_saved_sessions": { "message": "Saved sessions" },
"html_history_import_session": { "message": "Import session" },
"html_history_migrate_tabs": { "message": "Migrate tabs" },
"html_history_migrate_old_id": { "message": "Old TGS Extension id" },
"html_notice_title": { "message": "Notice" },
"html_notice_important_notice": { "message": "Important notice from The Great Suspender" },
"html_options_title": { "message": "Settings" },
Expand Down Expand Up @@ -228,6 +230,15 @@
"js_history_confirm_delete": { "message": "Are you sure you want to delete this session?" },
"js_history_confirm_session_overwrite": { "message": "There is already a saved session with this name. Overwrite existing session?" },
"js_history_import_fail": { "message": "Failed to load file. Ensure file is plain text and contains a single url per line." },
"js_history_migrate_fail": { "message": "Need 32-character extension id to migrate from" },
"js_history_migrate_success": {
"message": "Successfully migrated $TABCOUNT$ tabs",
"placeholders": {
"tabcount": {
"content": "$1"
}
}
},
"js_suspended_remove_from_whitelist": { "message": "Remove site from whitelist" },
"js_suspended_hotkey_to_reload": { "message": "Set keyboard shortcuts" },
"js_suspended_low_memory": { "message": "Tab suspended due to low system memory" },
Expand Down
8 changes: 8 additions & 0 deletions src/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ <h2 data-i18n="__MSG_html_history_saved_sessions__:"></h2>

<a href="#" id="importSession" class="btn" data-i18n="__MSG_html_history_import_session__"></a>
<input type="file" id="importSessionAction" hidden />

<br><br>

<div class="formRow">
<label for="migrateFromId" class="cbLabel" data-i18n="__MSG_html_history_migrate_old_id__"></label>
<input size="33" id="migrateFromId" class='option' value="klbibkeccnjlkjkiokjodocebajanakg" /><br>
<a href="#" id="migrateTabs" class="btn" data-i18n="__MSG_html_history_migrate_tabs__"></a>
</div>
</div>

</div>
Expand Down
6 changes: 6 additions & 0 deletions src/js/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@
importSessionActionEl.click();
};

var migrateTabsEl = document.getElementById('migrateTabs');
migrateTabsEl.onclick = function() {
var migrateTabsFromIdEl = document.getElementById('migrateFromId');
historyUtils.migrateTabs(migrateTabsFromIdEl.value);
};

//hide incompatible sidebar items if in incognito mode
if (chrome.extension.inIncognitoContext) {
Array.prototype.forEach.call(
Expand Down
22 changes: 22 additions & 0 deletions src/js/historyUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,33 @@ var historyUtils = (function(global) {
});
}

function migrateTabs(from_id) {
if (from_id.length == 32) {
chrome.tabs.query({}, function(tabs){
var count = 0;
var prefix_before = 'chrome-extension://' + from_id;
var prefix_after = 'chrome-extension://' + chrome.i18n.getMessage('@@extension_id');
for (var tab of tabs) {
if (!tab.url.startsWith(prefix_before)) {
continue;
}
count += 1;
var migrated_url = prefix_after + tab.url.substr(prefix_before.length);
chrome.tabs.update(tab.id, {url: migrated_url});
}
alert(chrome.i18n.getMessage('js_history_migrate_success', '' + count));
});
} else {
alert(chrome.i18n.getMessage('js_history_migrate_fail'));
}
}

return {
importSession,
exportSession,
exportSessionWithId,
validateNewSessionName,
saveSession,
migrateTabs
};
})(this);

0 comments on commit d67e5f6

Please sign in to comment.