This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpopup.js
76 lines (68 loc) · 2.32 KB
/
popup.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
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
let socialMediaKeys = {
"facebook": true,
"github": true,
"google": true,
"instagram": true,
"keybase": true,
"linkedin": true,
"stackoverflow": true,
"twitter": true
};
// Wait until the DOM is fully loaded, then we can init everything.
window.addEventListener('DOMContentLoaded', initializeStoredValues);
// Get stored values.
function initializeStoredValues() {
// Get the stored information
chrome.storage.sync.get(['mediaKeys'], function(data) {
if(Object.keys(data).length !== 0) {
let mediaKeys = data.mediaKeys;
for(let key in mediaKeys) {
if(mediaKeys.hasOwnProperty(key)) {
setKey(key, mediaKeys[key]);
}
}
}
});
// Strange Extension bug. Needs it.
setTimeout(() => {
document.querySelector('#reset-button').addEventListener('click', resetMediaValues);
document.querySelector('#apply-button').addEventListener('click', applyMediaValues);
}, 500);
}
function setKey(mediaKey, value) {
let labelID = mediaKey + "-label";
if(!value) {
document.querySelector('#' + labelID).MaterialSwitch.off();
} else {
document.querySelector('#' + labelID).MaterialSwitch.on();
}
}
// The user has pressed the apply button, let's save the values of the
// The switches to storage.
function applyMediaValues() {
// Set the values
for(let key in socialMediaKeys) {
if(socialMediaKeys.hasOwnProperty(key)) {
let labelID = key + "-label";
socialMediaKeys[key] = document.querySelector('#' + labelID).MaterialSwitch.inputElement_.checked;
}
}
chrome.storage.sync.set({['mediaKeys']: socialMediaKeys}, function() {
console.log('Successfully saved media key values.');
});
}
function resetMediaValues() {
for(let key in socialMediaKeys) {
if(socialMediaKeys.hasOwnProperty(key)) {
socialMediaKeys[key] = true;
setKey(key, true);
}
}
chrome.storage.sync.set({['mediaKeys']: socialMediaKeys}, function() {
console.log('Successfully saved media key values.');
});
}