-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBookmarkManager.js
78 lines (78 loc) · 2.98 KB
/
BookmarkManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/// <reference path=".\typings\chrome.d.ts" />
define(["require", "exports"], function (require, exports) {
"use strict";
var BookmarkManager = (function () {
function BookmarkManager() {
this._createTempUrlBookmark();
this._addShortcut();
}
BookmarkManager.getInstance = function () {
if (!BookmarkManager._instance) {
BookmarkManager._instance = new BookmarkManager();
}
return BookmarkManager._instance;
};
Object.defineProperty(BookmarkManager, "folderTitle", {
get: function () {
return "Temporary URLs";
},
enumerable: true,
configurable: true
});
BookmarkManager.prototype._createTempUrlBookmark = function () {
var _this = this;
chrome.bookmarks.search(BookmarkManager.folderTitle, function (results) {
if (results.length === 0) {
chrome.bookmarks.create({
'title': BookmarkManager.folderTitle
}, function (temporaryFolder) {
_this._tempUrlFolder = temporaryFolder;
});
}
});
};
BookmarkManager.prototype._addShortcut = function () {
var _this = this;
chrome.commands.onCommand.addListener(function (command) {
if (command === "save-temp-urls") {
_this._saveTabs();
}
else if (command === "recover-temp-urls") {
_this._reloadTabs();
}
});
};
BookmarkManager.prototype._saveTabs = function () {
var _this = this;
var info = {
populate: true
};
chrome.windows.getCurrent(info, function (window) {
window.tabs.forEach(function (tab) {
chrome.bookmarks.create({
'parentId': _this._tempUrlFolder.id,
'title': tab.url,
'url': tab.url
});
});
});
};
BookmarkManager.prototype._reloadTabs = function () {
chrome.bookmarks.search(BookmarkManager.folderTitle, function (bookmarks) {
for (var i = 0; i < bookmarks.length; i++) {
chrome.bookmarks.getChildren(bookmarks[i].id, function (recoverURLs) {
for (var j = 0; j < recoverURLs.length; j++) {
chrome.tabs.create({
"url": recoverURLs[j].url
});
chrome.bookmarks.remove(recoverURLs[j].id);
}
});
}
});
};
BookmarkManager._instance = undefined;
return BookmarkManager;
}());
exports.BookmarkManager = BookmarkManager;
});