-
Notifications
You must be signed in to change notification settings - Fork 0
/
search-promotion-master-script.js
208 lines (155 loc) · 5.19 KB
/
search-promotion-master-script.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
* SEARCH PROMOTION
*
* Function(s): step(1), step(2), step(3)
*
* Author: Joey Prettyman
* Year: 2018
* Company: Company
* Email: Joey.Prettyman@company.com
*
*/
//------------------------------
// Declare site language.
//------------------------------/
var language = "english";
//------------------------------
// Declare cookie variables.
//------------------------------/
var cookieName = "searchPromotion";
var cookieValue = "valid";
/********************************************************
* COOKIE FUNCTIONS
********************************************************/
/**************************************
* COOKIE LIFE CYCLE
**************************************
*
* 1) On web page load... = [undefined]
* 2) Does cookie exist? (call) = [null]
* 3) Cookie created. (method) = [setValue]
* 4) Cookie deleted. (method) = [undefined]
*
**************************************/
//================================
// Declare getCookie function.
//================================
function getCookie() {
return localStorage.getItem( cookieName );
};
//================================
// Declare setCookie function.
//================================
function setCookie() {
localStorage.setItem( cookieName, cookieValue );
};
//================================
// Declare removeCookie function.
//================================
function removeCookie() {
localStorage.removeItem( cookieName );
}
/********************************************************
* URL FUNCTIONS
********************************************************/
//------------------------------
// Declare current url variables.
//------------------------------/
var thisPage = window.location;
var port = thisPage.port;
var https = thisPage.protocol;
var domain = thisPage.host;
var directories = thisPage.pathname;
var href = thisPage.href;
//------------------------------
// Declare page variables for comparison.
//------------------------------/
var currentPage = https + "//" + domain + directories;
// Does cookie exist?
if( !getCookie() ) {
// Are we on the login page?
// [NO]
var loginPage = "https://site.admin.com/sitecore/login";
// If we are NOT on the login page... Go there.
if( currentPage !== loginPage ) {
window.location.href = loginPage;
}
// We are already on the login page...
else {
cred = []; login = []; input = [];
// Declare login credentials...
cred.user = "sitecore\\username";
cred.pass = "password";
// Declare login form variable.
login.form = document.getElementById( "login" ).getElementsByTagName( "input" );
// Declare inputs for form.
input.username = login.form[0];
input.password = login.form[1];
login.button = login.form[2];
// Begin filling out login form with credentials.
input.username.value = cred.user;
input.password.value = cred.pass;
// Before we login, let's set that cookie now.
setCookie();
// Click the login button.
login.button.click();
}
}
// Cookie(s) DO(ES) exist!
else {
// Declare objects.
find = [];
language = [];
// Are we on searchblox page?
// [NO]
var searchPage = "https://site.admin.com/sitecore/admin/searchbloxtuning.aspx";
// If we are NOT on the search page... Go there.
if( currentPage !== searchPage ) {
window.location.href = searchPage;
}
// [YES]
else {
// Was search already performed?
// If yes.
if( find.results !== undefined && find.results !== null ) {
console.log( "search was already performed" );
/*Search for best bets.
if( bestBets === true ) {
}
* Log best bet in array.
}
else {
* Perform another search.
}*/
}
// This is a fresh page.
else {
if( language === "english" ) {
// Declare radio buttons.
find.english = document.querySelector( "input[type='radio'][value='Company-Sitecore-English']" );
find.chinese = document.querySelector( "input[type='radio'][value='Company-Sitecore-Chinese']" );
find.english.click();
// Declare find filters.
find.results = document.getElementsByClassName( "results" )[0];
find.noresults = document.querySelector( "ng-if='searchData.Results.length == 0'" );
find.input = document.querySelector( "input[ng-model='search.phrase']" );
find.button = document.querySelector( "button[ng-click='search()']" );
find.input.value = "Cybersecurity";
angular.element( find.input ).triggerHandler('change');
find.button.click();
//var searchVal = "Cybersecurity"; // 2 Best Bets
//var searchVal = "Test"; // 0 Best Bets
//var searchVal = "Supreme Court Decides Wilkins v Gaddy"; // 1 Results 1 Best Bet
// Change input value.
//$( "input[ng-model='search.phrase']" ).val( searchVal );
// On input value change...
//angular.element($( "input[ng-model='search.phrase']" )).triggerHandler('change');
// Click search button.
//$( "button[ng-click='search()']" ).triggerHandler("click");
}
else {
find.chinese.click();
}
}
}
}