-
Notifications
You must be signed in to change notification settings - Fork 5
/
common.js
101 lines (88 loc) · 2.33 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) 2014 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.
var DEFAULT_SCHEME = 3;
var MAX_SCHEME = 7;
function $(id) {
return document.getElementById(id);
}
function getEnabled() {
var result = localStorage['enabled'];
if (result === 'true' || result === 'false') {
return (result === 'true');
}
localStorage['enabled'] = 'true';
return true;
}
function setEnabled(enabled) {
localStorage['enabled'] = enabled;
}
function getKeyAction() {
var keyAction = localStorage['keyaction'];
if (keyAction == 'global' || keyAction == 'site') {
return keyAction;
}
keyAction = 'global';
localStorage['keyaction'] = keyAction;
return keyAction;
}
function setKeyAction(keyAction) {
if (keyAction != 'global' && keyAction != 'site') {
keyAction = 'global';
}
localStorage['keyaction'] = keyAction;
}
function getDefaultScheme() {
var scheme = localStorage['scheme'];
if (scheme >= 0 && scheme <= MAX_SCHEME) {
return scheme;
}
scheme = DEFAULT_SCHEME;
localStorage['scheme'] = scheme;
return scheme;
}
function setDefaultScheme(scheme) {
if (!(scheme >= 0 && scheme <= MAX_SCHEME)) {
scheme = DEFAULT_SCHEME;
}
localStorage['scheme'] = scheme;
}
function getSiteScheme(site) {
var scheme = getDefaultScheme();
try {
var siteSchemes = JSON.parse(localStorage['siteschemes']);
scheme = siteSchemes[site];
if (!(scheme >= 0 && scheme <= MAX_SCHEME)) {
scheme = getDefaultScheme();
}
} catch (e) {
scheme = getDefaultScheme();
}
return scheme;
}
function setSiteScheme(site, scheme) {
if (!(scheme >= 0 && scheme <= MAX_SCHEME)) {
scheme = getDefaultScheme();
}
var siteSchemes = {};
try {
siteSchemes = JSON.parse(localStorage['siteschemes']);
siteSchemes['www.example.com'] = getDefaultScheme();
} catch (e) {
siteSchemes = {};
}
siteSchemes[site] = scheme;
localStorage['siteschemes'] = JSON.stringify(siteSchemes);
}
function resetSiteSchemes() {
var siteSchemes = {};
localStorage['siteschemes'] = JSON.stringify(siteSchemes);
}
function siteFromUrl(url) {
var a = document.createElement('a');
a.href = url;
return a.hostname;
}
function isDisallowedUrl(url) {
return url.indexOf('chrome') == 0 || url.indexOf('about') == 0;
}