-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cc93522
Showing
5 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
const baseUrl = 'https://www.keysearch.co'; | ||
|
||
|
||
function objectToFormData(obj) { | ||
const formData = new FormData(); | ||
Object.keys(obj).forEach(key => formData.append(key, obj[key])); | ||
return formData; | ||
} | ||
|
||
function makeRequest(endpoint, params) { | ||
return fetch(`${baseUrl}${endpoint}`, { | ||
method: 'POST', | ||
body: objectToFormData(params) | ||
}) | ||
.then(response => response.text()) | ||
.catch(error => console.error('Error:', error)); | ||
} | ||
|
||
function searchKeyword(keyword) { | ||
const params = { | ||
keyword: keyword, | ||
location: "all", | ||
search_type: "M", | ||
text_search: "search" | ||
}; | ||
return makeRequest('/research/search', params); | ||
} | ||
|
||
function getFilter(keyword) { | ||
const params = { | ||
keyword: keyword, | ||
location: "all", | ||
search_type: "M", | ||
volume_start: 150, | ||
volume_end: "", | ||
cpc_start: "", | ||
cpc_end: "", | ||
keyword_start: "", | ||
keyword_end: "", | ||
keyword_to_filter: "", | ||
score_start: "", | ||
score_end: 29, | ||
negative: "" | ||
}; | ||
return makeRequest('/research/get-filter', params); | ||
} | ||
|
||
function righttablemainresults(keyword) { | ||
const params = { | ||
keyword: keyword, | ||
location: "all", | ||
search_type: "M", | ||
}; | ||
return makeRequest('/research/righttablemainresults', params); | ||
} | ||
|
||
function extractKeywordsFromHTML(htmlString) { | ||
let parser = new DOMParser(); | ||
let doc = parser.parseFromString(htmlString, "text/html"); | ||
const keywordElements = doc.querySelectorAll('.btn-info'); | ||
const keywords = Array.from(keywordElements).map(el => el.textContent.trim()); | ||
return keywords; | ||
} | ||
|
||
function addKeywordsToQueue(keywords) { | ||
chrome.storage.local.get('keywordQueue', result => { | ||
const queue = result.keywordQueue || []; | ||
keywords.forEach(keyword => { | ||
if (!queue.includes(keyword)) { | ||
queue.push(keyword); | ||
} | ||
}); | ||
chrome.storage.local.set({ keywordQueue: queue }); | ||
}); | ||
} | ||
|
||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { | ||
if (request.message === 'searchKeyword') { | ||
const keyword = request.keyword; | ||
searchKeyword(keyword) | ||
.then(data => { | ||
chrome.runtime.sendMessage({message: 'downloadData', data: data, filename: `${keyword}_search.html`, type: 'text/html'}); | ||
return righttablemainresults(keyword); | ||
}) | ||
.then(data => { | ||
chrome.runtime.sendMessage({message: 'downloadData', data: data, filename: `${keyword}_maintable.html`, type: 'text/html'}); | ||
// Send raw HTML to the popup for parsing | ||
chrome.runtime.sendMessage({message: 'parseHTML', data: data}); | ||
return getFilter(keyword); | ||
}) | ||
.then(data => { | ||
chrome.runtime.sendMessage({message: 'downloadData', data: data, filename: `${keyword}_results.html`, type: 'text/html'}); | ||
}) | ||
.catch(error => console.error(error)); | ||
} | ||
}); | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"manifest_version": 3, | ||
"name": "Keysearch Explorer", | ||
"version": "1.0", | ||
"permissions": ["activeTab", "scripting", "storage", "downloads"], | ||
"action": { | ||
"default_popup": "popup.html", | ||
"default_icon": { | ||
"48": "images/icon48.png" | ||
} | ||
}, | ||
"background": { | ||
"service_worker": "background.js" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Keysearch Helper</title> | ||
</head> | ||
<body> | ||
<h1>Keysearch Helper</h1> | ||
<form id="searchForm"> | ||
<input type="text" id="keyword" placeholder="Enter keyword"> | ||
<button type="submit">Search</button> | ||
</form> | ||
<button id="clearQueue">Clear Keyword Queue</button> | ||
<h2>Keyword Queue</h2> | ||
<ul id="keywordQueue"></ul> | ||
<script src="popup.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
function downloadData(data, filename, type) { | ||
const file = new Blob([data], { type: type }); | ||
const a = document.createElement('a'); | ||
a.href = URL.createObjectURL(file); | ||
a.download = filename; | ||
a.click(); | ||
} | ||
|
||
function displayQueue() { | ||
chrome.storage.local.get('keywordQueue', result => { | ||
const queue = result.keywordQueue || []; | ||
const queueElement = document.getElementById('keywordQueue'); | ||
queueElement.innerHTML = ''; // Clear the existing queue display | ||
queue.forEach(keyword => { | ||
const li = document.createElement('li'); | ||
li.textContent = keyword; | ||
li.style.cursor = 'pointer'; // Make it look clickable | ||
li.addEventListener('click', function () { // Add click event listener | ||
chrome.runtime.sendMessage({ message: 'searchKeyword', keyword: keyword }); | ||
}); | ||
queueElement.appendChild(li); | ||
}); | ||
}); | ||
} | ||
|
||
|
||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { | ||
if (request.message === 'downloadData') { | ||
downloadData(request.data, request.filename, request.type); | ||
} | ||
}); | ||
|
||
window.addEventListener('DOMContentLoaded', (event) => { | ||
document.getElementById('searchForm').addEventListener('submit', function (e) { | ||
e.preventDefault(); | ||
const keyword = document.getElementById('keyword').value; | ||
chrome.runtime.sendMessage({ message: 'searchKeyword', keyword: keyword }); | ||
}); | ||
displayQueue(); | ||
}); | ||
|
||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { | ||
if (request.message === 'parseHTML') { | ||
const keywords = extractKeywordsFromHTML(request.data); | ||
addKeywordsToQueue(keywords); | ||
} | ||
}); | ||
|
||
function extractKeywordsFromHTML(htmlString) { | ||
let parser = new DOMParser(); | ||
let doc = parser.parseFromString(htmlString, "text/html"); | ||
const keywordElements = doc.querySelectorAll('.btn-info'); | ||
const keywords = Array.from(keywordElements).map(el => el.textContent.trim()); | ||
console.log(`Found ${keywords.length} keywords \n${keywords.join('\n')}`) | ||
return keywords; | ||
} | ||
|
||
|
||
function clearKeywordQueue() { | ||
chrome.storage.local.clear(() => { | ||
console.log("Keyword queue cleared"); | ||
}); | ||
} | ||
|
||
|
||
|
||
document.getElementById('clearQueue').addEventListener('click', clearKeywordQueue); | ||
|
||
function addKeywordsToQueue(keywords) { | ||
chrome.storage.local.get('keywordQueue', result => { | ||
const queue = result.keywordQueue || []; | ||
keywords.forEach(keyword => { | ||
if (!queue.includes(keyword)) { | ||
queue.push(keyword); | ||
} | ||
}); | ||
chrome.storage.local.set({ keywordQueue: queue }); | ||
}); | ||
} |