-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.html
72 lines (66 loc) · 1.92 KB
/
background.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<html>
<head>
<script>
Bob = {
currentUser: '',
getUserInfo: function() {
var text = localStorage['user_info'];
if(!localStorage['user_info']) {
text = '{\n name: "shinamon(sample)",\n rk: "21e7b1941"\n},\n{\n name: "konamon(sample)",\n rk: "ac3252af2"\n}';
localStorage['user_info'] = text;
}
text = '[' + text + ']';
return (new Function('return ' + text))()
},
saveUserInfo: function(text) {
if (this.checkUserInfoData(text)) {
localStorage['user_info'] = text;
this.notification('Save!', 'done.');
}
},
changeCookie: function(cookie, rk) {
//リファレンスに載ってない属性があるとsetできないのでurl属性を足したり余分なのを消したり。
//http://code.google.com/chrome/extensions/cookies.html
cookie.value = rk;
cookie.url = 'http://www.hatena.ne.jp/';
delete cookie.hostOnly;
delete cookie.session;
chrome.cookies.set(cookie);
},
checkUserInfoData: function(text) {
text = '[' + text + ']';
try {
var data = (new Function('return ' + text))();
} catch (e) {
this.notification('Error!', 'Syntax error.');
console.log(e);
return false;
}
var jadge = data.every(function(e) {
var count = 0;
for (var prop in e) {
count++;
if(!/^name$|^rk$/.test(prop))
return false;
}
return (count === 2);
});
if (jadge) {
return true;
} else {
this.notification('Error!', 'Jadge - Against the rules!');
return false;
}
},
notification: function(title, msg) {
var notification = webkitNotifications.createNotification('icon48.png', title, msg);
notification.show();
setTimeout(function(){notification.cancel();}, 3000);
},
reload: function() {
chrome.tabs.executeScript(null, { code: "if (/\.hatena\.ne\.jp/.test(location.host)) location.reload()"});
}
};
</script>
</head>
</html>