forked from OsaSoft/youtube-better-subscriptions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.js
65 lines (54 loc) · 1.46 KB
/
common.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
const PREFIX = "osasoft-better-subscriptions_";
const DEFAULT_SETTINGS = {
"settings.hide.watched.label": true,
"settings.hide.watched.all.label": true,
"settings.hide.watched.ui.stick.right": false,
"settings.hide.watched.default": true,
"settings.hide.watched.keep.state": true,
"settings.hide.watched.refresh.rate": 3000,
"settings.mark.watched.youtube.watched.percentage": null, //null means OFF
"settings.log.enabled": false,
"settings.hide.watched.support.channel": true,
"settings.hide.watched.support.home": true,
"settings.hide.watched.auto.store": true
};
const SETTINGS_KEY = "settings";
let brwsr;
try {
brwsr = browser;
} catch (e) {
if (e instanceof ReferenceError) {
brwsr = chrome;
}
}
function getStorage() {
return brwsr.storage.local; //TODO: use sync?
}
function loadStorage() {
return new Promise(function (resolve, reject) {
getStorage().get(null, function (items) {
resolve(items);
});
})
}
function getSyncStorage() {
return brwsr.storage.sync;
}
function setVideoInStorage(videoId) {
let obj = {};
obj[videoId] = Date.now();
getStorage().set(obj);
}
function hide(element) {
element.classList.add("hidden");
}
function show(element) {
element.classList.remove("hidden");
}
function getCurrentPage() {
let path = window.location.pathname;
if (path != null) {
return path.replace(/\/$/, "");
}
return "";
}