This repository was archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchEnhancer.user.js
More file actions
66 lines (58 loc) · 2.74 KB
/
SearchEnhancer.user.js
File metadata and controls
66 lines (58 loc) · 2.74 KB
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
// ==UserScript==
// @name Bueda Powered Craigslist Enhanced Search
// @namespace http://www.bueda.com
// @description Script for enhancing searches in craigslist using Bueda api
// @include http://*.craigslist.org/
// ==/UserScript==
window.addEventListener('load', function() {
var form = document.getElementById('search');
if(form) {
// Attach the handler if search form is present in the page
form.addEventListener('submit', function(e) {
// Prevent the form from being submitted by default
e.preventDefault();
// Query string for bueda web service request
var query = document.getElementById('query').value;
// API KEY for requesting bueda web service
var api_key = 'vEmEfeiUADwfTP67Cjftq1w91hIJ8hrlY6L8eQ';
// URL for bueda web service
var URL = 'http://api.bueda.com/enriched?apikey=' +
api_key + '&tags=' + query;
// Cross domain request to bueda web service
GM_xmlhttpRequest({
method:'GET',
url:URL,
// callback function for a succesful response
onload:function(response){
if(response.status==200){
var jsonResponse = JSON.parse(response.responseText);
var query = "";
// Change the following few lines to populate enhanced
// keywords once the api supports it.
var cleanTags = jsonResponse.result.cleanup;
// Construct the query parameter by separating keywords
// using pipes
for(var i in cleanTags) {
if(cleanTags.hasOwnProperty(i)) {
query += cleanTags[i]+'|';
}
}
query = query.substr(0,query.length-1);
// Set the 'query' field with new query value
document.getElementById('query').value = query;
//alert(document.getElementById('query').value)
// Submit the form with bueda expanded keywords
form.submit();
}
},
// callback function for a failure response
onerror:function(response){
// Alert used for debugging
alert('Something went wrong!');
// Submit the form with the original keywords
form.submit();
}
});
}, false);
}
}, false);