-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
78 lines (62 loc) · 1.57 KB
/
background.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
// Copyright (c) 2012 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 oauth = ChromeExOAuth.initBackgroundPage({
'request_url' : 'https://api.twitter.com/oauth/request_token',
'authorize_url' : 'https://api.twitter.com/oauth/authorize',
'access_url' : 'https://api.twitter.com/oauth/access_token',
'consumer_key' : '',
'consumer_secret' : '',
'app_name' : 'Google Tweets'
});
var authorized = false;
var on = false;
function setIcon() {
if (on) {
chrome.browserAction.setIcon({ 'path' : 'img/icon-19-on.png'});
} else {
chrome.browserAction.setIcon({ 'path' : 'img/icon-19-off.png'});
}
};
function getTwitterAuth() {
if(!authorized) {
oauth.authorize(function(token, secret) {
authorized = true;
on = true;
setIcon();
});
} else {
on = !on;
}
setIcon();
};
function logout() {
oauth.clearTokens();
authorized = false;
on = false;
setIcon();
};
chrome.contextMenus.removeAll();
chrome.contextMenus.create({
title: "logout",
contexts: ["browser_action"],
onclick: logout
});
chrome.browserAction.onClicked.addListener(getTwitterAuth);
chrome.webRequest.onBeforeRequest.addListener(
function(info) {
var url = new URL(info.url);
var search = url.searchParams.get("q");
if(search && authorized && on) {
Twitter.update(search);
console.log("search string: " + search);
}
},
// filters
{
urls: [
"*://*.google.com/search*"
]
},
// extraInfoSpec
["blocking"]);