forked from superfeedr/subtome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
register-no-ui.html
55 lines (49 loc) · 1.73 KB
/
register-no-ui.html
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
<script type="text/javascript">
var Services = function Services() {
this.services = {};
this.error = null;
this.load();
}
Services.prototype.load = function loadServices() {
try {
var servicesString = localStorage.getItem('services');
}
catch(error) {
console.error('There was an error, so we could not load the services from the localStorage. ', error);
if(error.name === 'SecurityError' && error.code === 18) {
this.error = 'A browser setting is preventing SubToMe from saving your favorite subscription tools. Open up Settings > Privacy. Then, make sure Accept cookies from sites is checked. Also, make sure Accept third-party is checked as well.';
}
else {
this.error = 'We could not load your favorite subscriptions tools. ';
}
}
if(servicesString) {
try {
this.services = JSON.parse(servicesString);
}
catch(error) {
console.error('Could not parse ' + servicesString);
this.error = 'Warning: We could not load your favorite subscriptions tools. ';
}
}
}
Services.prototype.save = function saveServices() {
localStorage.setItem('services', JSON.stringify(this.services));
}
Services.prototype.register = function registerService(name, handler) {
if(!this.services[name]) {
this.services[name] = {
url: decodeURIComponent(handler),
addedOn: Date.now()
}
this.save();
}
}
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
new Services().register(getParameterByName('name'), getParameterByName('url'));
</script>