-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathegenie.user.js
153 lines (123 loc) · 5.43 KB
/
egenie.user.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// ==UserScript==
// @name eGenie
// @description eBay Personalization Platform
// @require http://code.jquery.com/jquery-1.8.2.js
// @require http://code.jquery.com/ui/1.9.1/jquery-ui.js
// @resource jQueryUICSS http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css
// @include http://www.ebay.com/*
// @include http://www.amazon.com/*
// @grant GM_getResourceText
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @require https://raw.github.com/vaustymenko/eGenie/master/common/js/genie.js
// @require https://raw.github.com/vaustymenko/eGenie/master/plugins/dailydeals/js/default.js
// @require https://raw.github.com/vaustymenko/eGenie/master/plugins/accessories/js/accessories.js
// @require https://raw.github.com/vaustymenko/eGenie/master/plugins/competitor-prices/js/competitor-prices.js
// @require https://raw.github.com/vaustymenko/eGenie/master/plugins/mystuff/js/default.js
// @require https://raw.github.com/vaustymenko/eGenie/master/plugins/suggestions/js/suggestions.js
// @resource dailyDealsCSS https://raw.github.com/vaustymenko/eGenie/master/plugins/dailydeals/css/default.css
// @resource genieOverlayCSS https://raw.github.com/vaustymenko/eGenie/master/common/css/genie-overlay.css
// @resource genieButtonsCSS https://raw.github.com/vaustymenko/eGenie/master/common/css/buttons.css
// ==/UserScript==
/*
Permanent Storage sample
// restore the state
var state = JSON.parse(localStorage.getItem('state')||'{}');
// use the state as you wish
state.lastTweetId = 987654321;
state.options = {reloadTime:30,playSound:true};
// save state
localStorage.setItem('state', JSON.stringify(state) );
*/
/**
* Plugin manager responsible for initializing the registered plugins and
* building the main menu as well as genie appearance
*
* @param {type} $
* @returns {undefined}
*/
(function($) {
var PluginManager = {
/**
* Returns plugins which match the current URL
*
* @param {type} $
* @returns {undefined}
*/
getMatchingPlugins: function(currentURL) {
if (!$ || !$.eGenie || !$.eGenie.plugins)
return null;
var plugins = [];
for (var i in $.eGenie.plugins) {
if ($.eGenie.plugins[i].sites)
for (var j in $.eGenie.plugins[i].sites)
if (currentURL.match($.eGenie.plugins[i].sites[j])) {
plugins.push($.eGenie.plugins[i]);
log("Matching plugin for the current page: " + $.eGenie.plugins[i].menuTitle);
break;
}
}
return plugins;
},
/**
* Builds main menu
*
* @param {type} $
* @returns {undefined}
*/
createMenu: function(plugins) {
var $ebayGenieOverlay = $("<div class='ebay-genie-overlay' />"),
$ebayGenieOverlayMainBtn = $("<button class='ebay-genie-button' />"),
$ebayGenieOverlayBox = $("<div class='ebay-genie-overlay-box'/>"),
$ebayGenieOverlayPlugins = $("<div class='ebay-genie-overlay-plugins' />"),
$ebayGenieOverlayContainer = $("<div class='ebay-genie-overlay-box-container' />");
$ebayGenieOverlayBox
.append($ebayGenieOverlayPlugins)
.append("<hr />")
.append($ebayGenieOverlayContainer);
$ebayGenieOverlay
.append($ebayGenieOverlayMainBtn)
.append($ebayGenieOverlayBox)
.appendTo(window.document.body);
for (var i in plugins) {
log("Initializing " + plugins[i].menuTitle + " plugin");
$("<button type='type' class='btn "+plugins[i].buttonColor+"' />")
.text( plugins[i].menuTitle)
.click($.proxy(plugins[i].callback, plugins[i]))
.appendTo($ebayGenieOverlayPlugins);
plugins[i].init.call(plugins[i]);
}
// <button type="button" class="btn btn-success">Daily Deals</button>
// var $genieOverlay = $("<div />",{class: "eGenie-overlay"}).appendTo(window.document.body);
},
/**
* Enatry method which triggers initialization of the entire eGenie
*
* @param {type} $
* @returns {undefined}
*/
init: function() {
log("Retrieving matching plugins");
var plugins = this.getMatchingPlugins(window.location.href);
if (!plugins || !plugins.length)
return;
log("Adding styles");
// add jQuery css to head
var jCSS = GM_getResourceText("jQueryUICSS");
GM_addStyle(jCSS);
var dailyDealsCSS = GM_getResourceText("dailyDealsCSS");
GM_addStyle(dailyDealsCSS);
var genieOverlayCSS = GM_getResourceText("genieOverlayCSS");
GM_addStyle(genieOverlayCSS);
var genieButtonsCSS = GM_getResourceText("genieButtonsCSS");
GM_addStyle(genieButtonsCSS);
this.createMenu(plugins);
}
}
$(document).ready(function(){
PluginManager.init();
$(".ebay-genie-overlay .ebay-genie-button").on("click",function(){
$(".ebay-genie-overlay").toggleClass("opened");
});
});
})(jQuery);