IndexDB, ip, search, options, bootstrap, about

This commit is contained in:
2016-02-06 23:47:44 +08:00
parent e011162861
commit 17d3181068
3 changed files with 228 additions and 89 deletions
+7 -8
View File
@@ -11,14 +11,13 @@ Ways to visualise:
# TODO:
change how it stems searches
datatables for visualisation - done
with length column - done
change how it stems searches - done
cache to indexdb- done
hide advanced options- done
remember how many done on this ip- done
datatables for visualisation
with length column
add bing etc
keywordkeg
cache to indexdb
remember how many done on this ip
+75 -17
View File
@@ -5,10 +5,11 @@
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap-theme.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/alertifyjs-alertify.js/1.0.8/css/alertify.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/s/bs/dt-1.10.10,b-1.1.0,b-html5-1.1.0,fh-3.1.0,kt-2.1.0,r-2.0.0,rr-1.1.0,se-1.1.0/datatables.min.css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap-theme.css"> -->
<link rel="stylesheet" href="theme.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
</head>
@@ -22,7 +23,7 @@
<div class="row">
<div class="col-sm-12">
<img class="responsive text-center" style="max-height: 75px" src="bl.png">
<img class="responsive" style="max-height: 75px" src="bl.png">
</div>
</div>
@@ -31,23 +32,81 @@
<div class="col-sm-6">
<div id="numofkeywords"></div>
<textarea id="input" rows="6" style="min-width: 100%"></textarea>
<div class="form-group">
<label for="input" >Starting searches:</label>
<textarea id="input" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" rows="6" title="queue" class="form-control" placeholder="I accidentally
on purpose">I accidentally
on purpose</textarea>
</div>
<a class="btn btn-info" id="startjob" onclick="StartJob();" type="button" value="Shit Keywords!">Shit Keywords!</a>
<div id="container"></div>
<!-- For debugging -->
<textarea id="queryoutput" style="display:none;"></textarea>
<button class="btn btn-default" type="button" data-toggle="collapse" data-target="#advanced" aria-expanded="false" aria-controls="advanced">
Advanced
</button>
<button class="btn btn-default" type="button" data-toggle="collapse" data-target="#about" aria-expanded="false" aria-controls="about">
About
</button>
<!-- </div> -->
<!-- <div class="col-sm-2"> -->
<div id="advanced" class="collapse">
<div class="form-group">
<label for="sel1">Service:</label>
<select class="form-control" id="select-service" disabled>
<option>google</option>
<option>twitter</option>
<option>yahoo</option>
<option>bing</option>
<option>ebay</option>
<option>amazon</option>
<option>google images</option>
<option>google books</option>
<option>google news</option>
<option>google shopping</option>
</select>
</div>
<div class="form-group">
<label for="rate-limit">Prefixes</label>
<textarea type="text" title="These values are added before words to prompt the search suggestions" class="form-control" 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>
</div>
<div class="form-group">
<label for="filter-positive" >Positive filter:</label>
<textarea disabled id="filter-positive" class="form-control" rows="3" onkeyup="FilterIfNotWorking()"
placeholder="Positive Filter"></textarea>
</div>
<div class="form-group">
<label for="filter-negative">Negative filter:</label>
<textarea disabled id="filter-negative" class="form-control" rows="3" onkeyup="FilterIfNotWorking()" placeholder="Negative Filter"></textarea>
</div>
<div class="form-group">
<label for="rate-limit">Rate limit (for experts):</label>
<input type="text" disabled title="Value between searches in milliseconds" class="form-control" id="rate-limit" value="750" title="Only change if you know what you are doing. This could get your ip banned, or place a burden on the suggest servers." >
</div>
</div>
<div id="about" class="collapse">
<p>Keyword shitter 2 is inspired by the amazing Keyword shitter 1!</p>
<p>New features include: multiple services, sorting results, configurable keywords stemming, IndexDB storage, and some options.</p>
<p>But you will be glad to know we kept the same old shit name.</p>
</div>
</div>
<div class="col-sm-2">
<textarea id="filter-positive" rows="3" onkeyup="FilterIfNotWorking()" placeholder="Positive Filter"></textarea>
<textarea id="filter-negative" rows="3" onkeyup="FilterIfNotWorking()" placeholder="Negative Filter"></textarea>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<hr>
@@ -64,6 +123,7 @@
<th title="Keyword length">Length</th>
<th title="Searches per month">Searches</th>
<th title="Cost per click ($US)">CPC</th>
<th title="Search">Search</th>
</tr>
</thead>
<tbody>
@@ -78,13 +138,11 @@
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.10/js/jquery.js"></script>
<script type="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://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"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/alertify.js/0.5.0/alertify.min.js"></script>
<script type="text/javascript" src="main.js"></script>
+146 -64
View File
@@ -5,37 +5,94 @@ var doWork = false;
var keywordsToQuery = new Array();
var keywordsToQueryIndex = 0;
var queryflag = false;
var table;
var prefixes;
var suffixes;
var objectStore;
var myIp;
$.getJSON("http://jsonip.com?callback=?", function (data) {
myIp = data.host;
});
// setup a db. Ref: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB
var db;
var dbReq = window.indexedDB.open("KeywordShitter2", 2);
dbReq.onerror = function (event) {
console.error('dbReq', event);
};
dbReq.onsuccess = function (event) {
// Do something with request.result!
console.log('dbReq', event);
db = event.target.result;
db.onerror = function (event) {
// Generic error handler for all errors targeted at this database's
// requests!
console.error("Database error: " + event.target.errorCode);
};
};
dbReq.onupgradeneeded = function (event) {
console.log("running onupgradeneeded");
db = event.target.result;
if (!db.objectStoreNames.contains("suggestions")) {
objectStore = db.createObjectStore("suggestions", {
autoIncrement: true
});
// Create an index to search suggestions by search.
objectStore.createIndex("search", "search", {
unique: false
});
objectStore.createIndex("keywords", "keywords", {
unique: true
});
} else {
objectStore = db.objectStore("customers");
}
};
window.setInterval(DoJob, 750);
function StartJob() {
if (doWork == false) {
keywordsToDisplay = new Array();
keywordsToDisplay = [];
hashMapResults = {};
keywordsToQuery = new Array();
keywordsToQuery = [];
keywordsToQueryIndex = 0;
hashMapResults[""] = 1;
hashMapResults[" "] = 1;
hashMapResults[" "] = 1;
prefixes = $('#prefixes').val().split(',');
suffixes = $('#suffixes').val().split(',');
var ks = $('#input').val().split("\n");
var i = 0;
for (i = 0; i < ks.length; i++) {
keywordsToQuery[keywordsToQuery.length] = {Keyword: ks[i]};
keywordsToDisplay[keywordsToDisplay.length]= {Keyword: ks[i]};
keywordsToQuery[keywordsToQuery.length] = {
Keyword: ks[i]
};
keywordsToDisplay[keywordsToDisplay.length] = {
Keyword: ks[i]
};
var j = 0;
for (j = 0; j < 26; j++) {
var chr = String.fromCharCode(97 + j);
var currentx = ks[i] + ' ' + chr;
keywordsToQuery[keywordsToQuery.length] = {Keyword: currentx};
keywordsToQuery[keywordsToQuery.length] = {
Keyword: currentx
};
hashMapResults[currentx] = 1;
}
}
//document.getElementById("input").value = '';
//document.getElementById("input").value += "\n";
numOfInitialKeywords = keywordsToDisplay.length;
FilterAndDisplay();
@@ -44,8 +101,8 @@ function StartJob() {
} else {
doWork = false;
alertify.alert("Stopped");
$('#startjob').val('Start Job').text('Start Job').removeClass('btn-danger');
FilterAndDisplay();
}
}
@@ -53,11 +110,12 @@ function DoJob() {
if (doWork == true && queryflag == false) {
if (keywordsToQueryIndex < keywordsToQuery.length) {
var currentKw = keywordsToQuery[keywordsToQueryIndex].Keyword;
QueryKeyword(currentKw);
// if (currentKw[currentKw.length - 1] != '✓') {
QueryKeyword(currentKw);
// }
keywordsToQueryIndex++;
} else {
if (numOfInitialKeywords != keywordsToDisplay.length) {
alertify.alert("Done");
doWork = false;
$('#startjob').val('Start Job');
} else {
@@ -81,7 +139,8 @@ function QueryKeyword(keyword) {
q: querykeyword,
client: "chrome"
},
success: function (res) {
success: function (res, statusText, jqXHR) {
var search = res[0];
var retList = res[1];
// sort so the shortest is first in the queue
@@ -94,34 +153,70 @@ function QueryKeyword(keyword) {
var currents = CleanVal(retList[i]);
if (hashMapResults[currents] != 1) {
hashMapResults[currents] = 1;
var cleanKw = CleanVal(retList[i]);
keywordsToDisplay[keywordsToDisplay.length] = {Keyword:cleanKw};
table.row.add([keywordsToDisplay.length,cleanKw,cleanKw.length]).draw( false );
var cleanKw = CleanVal(retList[i]);
keywordsToQuery[keywordsToQuery.length] = {Keyword: currents};
// add keyword to queue and display and db
keywordsToQuery[keywordsToQuery.length] = {
Keyword: currents
};
keywordsToDisplay[keywordsToDisplay.length] = {
Keyword: cleanKw
};
var 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'];
var suffixes = ['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', 'like', 'for', 'without', 'with', 'verses', 'to', 'near', 'except'];
table.row.add([keywordsToDisplay.length, cleanKw, cleanKw.length, undefined, undefined, search]).draw(false);
// add to db
var transaction = db.transaction(["suggestions"], "readwrite");
transaction.onerror = console.error;
var objectStore = transaction.objectStore("suggestions");
objectStore.add({
Keyword: cleanKw,
Length: cleanKw.length,
search: search,
ip: myIp,
url: this.url,
time: (new Date()).toUTCString()
});
// stem the result and add too
for (var k = 0; k < prefixes.length; k++) {
var chr = prefixes[k];
var currentx = chr + ' ' + currents;
keywordsToQuery[keywordsToQuery.length] = {Keyword: currentx};
keywordsToQuery[keywordsToQuery.length] = {
Keyword: currentx
};
hashMapResults[currentx] = 1;
}
for (var j = 0; j < prefixes.length; j++) {
var chr = prefixes[j];
var currentx = currents + ' ' + chr;
keywordsToQuery[keywordsToQuery.length] = {Keyword: currentx};
keywordsToQuery[keywordsToQuery.length] = {
Keyword: currentx
};
hashMapResults[currentx] = 1;
}
}
}
table.draw();
FilterAndDisplay();
// FilterAndDisplay();
var textarea = document.getElementById("input");
textarea.scrollTop = textarea.scrollHeight;
// textarea.scrollTop = textarea.scrollHeight;
queryflag = false;
// now remove from the queue
// FIXME oh wait but that mean it progress up th queue by 2 instead of one
// var found=false;
// for (var l = 0; l < keywordsToQuery.length; l++) {
// if (keywordsToQuery[l].Keyword==search){
// // keywordsToQuery.splice(l,1);
// keywordsToQuery[l].Keyword+=' ✓';
// found=true;
// break;
// }
// }
// if (!found){console.error('Did not find ', search, 'in queue');}
}
});
}
@@ -155,7 +250,7 @@ function Filter(listToFilter) {
var filterContains = document.getElementById("filter-positive").value.split("\n");
var i = 0;
for (i = 0; i < retList.length; i++) {
var currentKeyword = retList[i];
var currentKeyword = retList[i].Keyword;
var boolContainsKeyword = false;
var j = 0;
for (j = 0; j < filterContains.length; j++) {
@@ -168,7 +263,7 @@ function Filter(listToFilter) {
}
if (boolContainsKeyword) {
filteredList[filteredList.length] = currentKeyword;
filteredList[filteredList.length].Keyword = currentKeyword;
}
}
@@ -180,7 +275,7 @@ function Filter(listToFilter) {
var filterContains = document.getElementById("filter-negative").value.split("\n");
var i = 0;
for (i = 0; i < retList.length; i++) {
var currentKeyword = retList[i];
var currentKeyword = retList[i].Keyword;
var boolCleanKeyword = true;
var j = 0;
for (j = 0; j < filterContains.length; j++) {
@@ -193,7 +288,7 @@ function Filter(listToFilter) {
}
if (boolCleanKeyword) {
filteredList[filteredList.length] = currentKeyword;
filteredList[filteredList.length].Keyword = currentKeyword;
}
}
@@ -206,14 +301,15 @@ function Filter(listToFilter) {
function FilterAndDisplay() {
var i = 0;
var sb = '';
var outputKeywords = Filter(keywordsToDisplay);
var outputKeywords = Filter(keywordsToQuery);
for (i = 0; i < outputKeywords.length; i++) {
sb += outputKeywords[i].Keyword;
sb += '\n';
}
// document.getElementById("input").value = "";
document.getElementById("input").value = sb;
document.getElementById("numofkeywords").innerHTML = '' + outputKeywords.length + ' : ' + keywordsToDisplay.length;
// document.getElementById("numofkeywords").innerHTML = '' + outputKeywords.length + ' : ' + keywordsToDisplay.length;
}
function FilterIfNotWorking() {
@@ -222,49 +318,35 @@ function FilterIfNotWorking() {
}
}
function post_to_url(path, params, method) {
method = method || "post"; // Set method to post by default, if not specified.
// The rest of this code assumes you are not using a library.
// It can be made less wordy if you use one.
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for (var key in params) {
if (params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
function Download() {
var inputText = document.getElementById("input").value;
post_to_url('KSDownload.php', {
'input_text': inputText
}, 'post');
}
$(document).ready(function() {
$(document).ready(function () {
table = $('#outtable').DataTable({
// "dom": '<"top"iflp<"clear">>rt<"bottom"ipB<"clear">>',
// responsive: true,
pageLength: 25,
pageLength: 25,
// bAutoWidth: false,
// dom: 'lfrtipB',
dom: "<'row'<'col-sm-3'B><'col-sm-6'p><'col-sm-3'f>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-4'i><'col-sm-5'p><'col-sm-3'l>>",
buttons: ['copyHtml5','csvHtml5']
dom: "<'row'<'col-sm-3'B><'col-sm-6'i><'col-sm-3'f>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-4'B><'col-sm-5'p><'col-sm-3'l>>",
buttons: ['copyHtml5', 'csvHtml5'],
"columnDefs": [{
"name": "keyword",
"targets": 0
}, {
"name": "length",
"targets": 1
}, {
"name": "volume",
"targets": 2
}, {
"name": "cpc",
"targets": 3
}, {
"name": "search",
"targets": 4
}],
// aaSorting: [],
// data: keywordsToDisplay
});
} );
});