-
Notifications
You must be signed in to change notification settings - Fork 4
/
index-injected.js
48 lines (41 loc) · 1.44 KB
/
index-injected.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
"use strict";
/*jshint node: true */
var PouchDB = global.PouchDB;
if (PouchDB) {
PouchDB = PouchDB.defaults({});
PouchDB.allDbs = function () {
var prefix = typeof PouchDB.prefix === "undefined" ? "_pouch_" : PouchDB.prefix;
return getIDBDatabaseNames().then(function (names) {
return names.filter(function (name) {
return name.indexOf(prefix) === 0;
}).map(function (name) {
return name.substr(prefix.length);
}).filter(function (name) {
return (
["_checkModernIdb", "pouch__all_dbs__"].indexOf(name) === -1 &&
name.indexOf("-mrview-") === -1 &&
name.indexOf("-session-") === -1
);
});
});
};
}
var req2resp = require("./req2resp.js")(PouchDB);
var PostMessageRPC = require("./postmessagerpc.js");
var rpc = new PostMessageRPC(global.postMessage, "page");
global.addEventListener("message", rpc.onMessage);
rpc.serve("req2resp", req2resp);
var getIDBDatabaseNames;
if (global.indexedDB.webkitGetDatabaseNames) {
getIDBDatabaseNames = function () {
//Promisify webkitGetDatabaseNames()
return new global.Promise(function (resolve, reject) {
var req = global.indexedDB.webkitGetDatabaseNames().onsuccess = function () {
resolve(Array.prototype.slice.call(this.result));
};
});
};
} else {
//In Firefox, ask the add-on to provide the idb db names
getIDBDatabaseNames = rpc.call.bind(rpc, "main", "getIDBDatabaseNames");
}