-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsteamContextMenu.js
80 lines (72 loc) · 2.1 KB
/
steamContextMenu.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
var options = {
b_steam: true,
b_steamdb: true,
b_steamdb_instant: false,
b_isthereanydeal: true,
b_options: true
};
chrome.storage.sync.get(options, update_menus);
chrome.storage.onChanged.addListener(options_changed);
function options_changed(changes, areaName) {
for(var opt in changes) {
options[opt] = changes[opt].newValue;
}
update_menus(options);
}
function update_menus(results) {
options = results;
remove_all_menus(function() {
if (options.b_steam) {
create_steam_menu();
}
if (options.b_steamdb) {
create_steamdb_menu();
}
if (options.b_isthereanydeal) {
create_isthereanydeal_menu();
}
if (options.b_options) {
create_options_menu();
}
});
}
function create_steam_menu() {
chrome.contextMenus.create({
"title": "Search Steam for '%s'",
"contexts": ["selection"],
"onclick": function (info) {
chrome.tabs.create({url: 'http://store.steampowered.com/search/?term=' + encodeURIComponent(info.selectionText)});
}
});
}
function create_steamdb_menu() {
var steamdb_url = options.b_steamdb_instant ? 'https://steamdb.info/instantsearch/?idx=steamdb&q=' : 'https://steamdb.info/search/?q=';
chrome.contextMenus.create({
"title": "Search SteamDB for '%s'",
"contexts": ["selection"],
"onclick": function (info) {
chrome.tabs.create({url: steamdb_url + encodeURIComponent(info.selectionText)});
}
});
}
function create_isthereanydeal_menu() {
chrome.contextMenus.create({
"title": "Search IsThereAnyDeal for '%s'",
"contexts": ["selection"],
"onclick": function (info) {
chrome.tabs.create({url: 'https://isthereanydeal.com/#/filter:&search/' + encodeURIComponent(info.selectionText) + ';/scroll:%23gamelist'});
}
});
}
function create_options_menu() {
chrome.contextMenus.create({
"title": "Change Visible Menus...",
"contexts": ["selection"],
"onclick": function (info) {
chrome.runtime.openOptionsPage();
}
});
}
function remove_all_menus(callback) {
chrome.contextMenus.removeAll(callback);
}