added services, and stems empty input

This commit is contained in:
2016-02-07 22:48:22 +08:00
parent d6af5e0e17
commit 4623a802a5
3 changed files with 99 additions and 43 deletions
+8 -3
View File
@@ -2,12 +2,17 @@
"name": "keywordshitter2",
"version": "0.0.5",
"description": "The second generation of keyword shitter. Bigger, better, and more pungent than other products.",
"main": "public/index.html",
"main": "server.js",
"scripts": {
"test": "mocha",
"build-css": "lessc ./src/less/main.less > public/css/style.css",
"build": "npm run build-css"
"build": "npm run build-css",
"start": "node server.js"
},
"author": "",
"license": "MIT"
"license": "MIT",
"devDependencies": {
"cors": "^2.7.1",
"express": "^4.13.4"
}
}
+21 -9
View File
@@ -55,8 +55,8 @@ lying internet</textarea>
<div class="form-group">
<label for="sel1">Service:</label>
<select class="form-control" name="service" id="service" disabled>
<label for="service">Service:</label>
<select class="form-control" name="service" id="service" >
<option>google</option>
<option>twitter</option>
<option>yahoo</option>
@@ -64,19 +64,29 @@ lying internet</textarea>
<option>ebay</option>
<option>amazon</option>
<option>google images</option>
<option>youtube</option>
<option>google videos</option>
<option>google books</option>
<option>google news</option>
<option>google shopping</option>
</select>
</div>
<div class="form-group">
<label for="country">Country code (google):</label>
<input type="text" disabled title="Country code. Two letters. Only works for google for now" class="form-control" id="country" value="US" >
</div>
<div class="form-group">
<label for="lang">Lang code (google):</label>
<input type="text" disabled title="Lang code. Two letters. Only works for google for now" class="form-control" id="lang" value="en" >
</div>
<div class="form-group">
<label for="rate-limit">Prefixes</label>
<label for="prefixes">Prefixes</label>
<textarea type="text" title="These values are added before words to prompt the search suggestions" class="form-control" name="prefixes" id="prefixes" >a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,y,x,y,z,how,which,why,where,who,when,are,what</textarea>
</div>
<div class="form-group">
<label for="rate-limit">Suffixes:</label>
<textarea type="text" rows="2" title="These values are added after words to prompt the search suggestions" class="form-control" id="suffixes">like,for,without,with,verses,to,near,except,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,y,x,y,z</textarea>
<label for="suffixes">Suffixes:</label>
<textarea type="text" rows="2" title="These values are added after words to prompt the search suggestions" class="form-control" id="suffixes">like,for,without,with,versus,vs,to,near,except,has,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,y,x,y,z</textarea>
</div>
<div class="form-group">
@@ -125,11 +135,11 @@ lying internet</textarea>
<thead>
<tr>
<th>id</th>
<th>Keyword</th>
<th title="A suggested search">Keyword</th>
<th title="Keyword length">Length</th>
<th title="Searches per month">Volume</th>
<th title="Cost per click ($US)">CPC</th>
<th title="Search">Search</th>
<th title="Search that prompted the keyword suggestion">Search</th>
</tr>
</thead>
<tbody>
@@ -143,11 +153,13 @@ lying internet</textarea>
</div>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/datatables/1.10.10/js/jquery.js" crossorigin="anonymous"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/datatables/1.10.10/js/jquery.js" crossorigin="anonymous"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script type="text/javascript" src="//cdn.datatables.net/s/bs/jszip-2.5.0,dt-1.10.10,b-1.1.0,b-colvis-1.1.0,b-html5-1.1.0,b-print-1.1.0,cr-1.3.0,fh-3.1.0,kt-2.1.0,r-2.0.0,se-1.1.0/datatables.min.js" crossorigin="anonymous"></script>
<script src="//cdn.datatables.net/s/bs/jszip-2.5.0,dt-1.10.10,b-1.1.0,b-colvis-1.1.0,b-html5-1.1.0,b-print-1.1.0,cr-1.3.0,fh-3.1.0,kt-2.1.0,r-2.0.0,se-1.1.0/datatables.min.js" crossorigin="anonymous"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/4.2.0/lodash.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
+70 -31
View File
@@ -29,19 +29,46 @@ $.getJSON('https://api.ipify.org?format=json', function (data) {
// TODO Implement alternative services
// Ref: https://github.com/estivo/Instantfox/blob/master/firefox/c1hrome/content/defaultPluginList.js
// Ref: https://github.com/bnoordhuis/mozilla-central/tree/master/browser/locales/en-US/searchplugins
services={
"google":
"http://suggestqueries.google.com/complete/search?client=chrome&hl=${lang}&q=${query}&ds=${site}&gl=${country}",
"yahoo":
"https://search.yahoo.com/sugg/ff?output=fxjson&appid=ffd&command=${query}",
"bing": "http://api.bing.com/osjson.aspx?query=${query}",
"ebay":
"http://autosug.ebay.com/autosug?kwd=${query}&_jgr=1&sId=0&_ch=0&callback=nil",
"amazon":
"http://completion.amazon.co.uk/search/complete?method=completion&q=${query}&search-alias=aps&mkt=4",
"twitter":
"https://twitter.com/i/search/typeahead.json?count=${max_results}&q=${query}&result_type=topics&src=SEARCH_BOX"
/**
* Get the service url based on options set in the dom.
* @return {String} A jsonp url for search suggestions with query missing from the end.
*/
function getUrl(){
services={
"google":
"http://suggestqueries.google.com/complete/search?client=chrome&hl=${lang}&gl=${country}&callback=?&q=",
"google news":
"http://suggestqueries.google.com/complete/search?client=chrome&hl=${lang}&ds=n&gl=${country}&callback=?&q=",
"google shopping":
"http://suggestqueries.google.com/complete/search?client=chrome&hl=${lang}&ds=sh&gl=${country}&callback=?&q=",
"google books":
"http://suggestqueries.google.com/complete/search?client=chrome&hl=${lang}&ds=bo&gl=${country}&callback=?&q=",
"youtube":
"http://suggestqueries.google.com/complete/search?client=chrome&hl=${lang}&ds=yt&gl=${country}&callback=?&q=",
"google videos":
"http://suggestqueries.google.com/complete/search?client=chrome&hl=${lang}&ds=v&gl=${country}&callback=?&q=",
"google images":
"http://suggestqueries.google.com/complete/search?client=chrome&hl=${lang}&ds=i&gl=${country}&callback=?&q=",
"yahoo":
"https://search.yahoo.com/sugg/ff?output=jsonp&appid=ffd&callback=?&command=",
"bing": "http://api.bing.com/osjson.aspx?JsonType=callback&JsonCallback=?&query=",
"ebay":
"http://autosug.ebay.com/autosug?_jgr=1&sId=0&_ch=0&callback=?&kwd=",
"amazon":
"http://completion.amazon.co.uk/search/complete?method=completion&search-alias=aps&mkt=4&callback=?&q=",
"twitter":
"https://twitter.com/i/search/typeahead.json?count=30&result_type=topics&src=SEARCH_BOX&callback=?&q="
};
options={
country: $('#country').val(),
service: $('#service').val(),
lang: $('#lang').val(),
};
return _.template(services[options.service])(options);
}
function ebayParser(){}
// s = req.lstrip('/**/nil/(').rstrip(')')
// sugg_texts = json.loads(s)['res']['sug']
@@ -56,15 +83,22 @@ function twitterParser(){}
// 'meta': j,
// 'relevances': [t['rounded_score'] for t in j['topics']],
// }
/** Parse response per service **/
function parseServiceResponse(res){
var service = $('#service').val();
var parser = RESPONSE_TEMPLATES[service] || RESPONSE_TEMPLATES["default"];
return parser(res);
}
var RESPONSE_TEMPLATES = {
"google": ['query', 'sugg_texts', 'sugg_titles', '_', 'meta'],
"google_maps": ['query', 'sugg_texts', 'sugg_titles', '_', 'meta'],
"yahoo": ['query', 'sugg_texts'],
"bing": ['query', 'sugg_texts'],
"bing_search": ['query', 'sugg_texts'],
"ebay": ebayParser,
"amazon": ['query', 'sugg_texts'],
"twitter": twitterParser
"default": function(res){return res[1];},
"google": function(res){return res[1];},
"youtube": function(res){return res[1];},
"yahoo": function(res){return _.map(res.gossip.results,'key');},
"bing": function(res){return res[1];},
"ebay": function(res){return res.res.sug;},
"amazon": function(res){return res[1];},
"twitter": function(res){return Array.concat(res.users,_.map(res.topics,'topic'),res.hashtags,res.oneclick);}
};
// setup a db. Ref: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB
@@ -130,12 +164,12 @@ function StartJob() {
suffixes = $('#suffixes').val().split(',');
var ks = $('#input').val().split("\n");
var i = 0;
for (i = 0; i < ks.length; i++) {
keywordsToQuery[keywordsToQuery.length] = ks[i];
for (var i = 0; i < ks.length; i++) {
if (ks[i].trim().length)
keywordsToQuery[keywordsToQuery.length] = ks[i];
}
numOfInitialKeywords = keywordsToQuery.length;
if (!numOfInitialKeywords) permuteResultsToQueue([' ']);
FilterAndDisplay();
doWork = true;
@@ -342,17 +376,18 @@ function QueryKeyword(search) {
}
else {
// search not done, lets do the query
url = getUrl()+search;
$.ajax({
url: "http://suggestqueries.google.com/complete/search",
url: url,
jsonp: "jsonp",
dataType: "jsonp",
data: {
q: search,
client: "chrome"
},
// data: {
// q: search,
// client: "chrome"
// },
success: function (res, statusText, jqXHR) {
// var search = res[0];
var retList = res[1];
var retList = parseServiceResponse(res);
var char, currentx;
storeResults(retList, search, this.url);
@@ -477,6 +512,8 @@ function FilterAndDisplay() {
function loadSettings(){
// TODO do table settings as well, e.g. column visibilitity
if (localStorage.service) $("#service").val( localStorage.service );
if (localStorage.country) $('#country').val(localStorage.country);
if (localStorage.lang) $('#lang').val(localStorage.lang);
if (localStorage.filterNegative) $("#filter-negative").val( localStorage.filterNegative );
if (localStorage.filterPositive) $("#filter-positive").val( localStorage.filterPositive );
if (localStorage.rateLimit) $("#rate-limit").val( localStorage.rateLimit );
@@ -488,6 +525,8 @@ function loadSettings(){
/** save settings to localStorage. **/
function saveSettings(){
localStorage.service = $('#service').val();
localStorage.country = $('#country').val();
localStorage.lang = $('#lang').val();
localStorage.filterNegative = $('#filter-negative').val();
localStorage.filterPositive = $('#filter-positive').val();
localStorage.rateLimit = $('#rate-limit').val();