Initial commit
This commit is contained in:
commit
289c386119
72
content.js
Normal file
72
content.js
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
if (window.location.href.includes("sahibinden.com")) {
|
||||||
|
const title = document.querySelector('div.classifiedDetailTitle>h1');
|
||||||
|
const button = document.createElement("button");
|
||||||
|
button.innerText = "Parse it"
|
||||||
|
title.appendChild(button)
|
||||||
|
const priceTag = document.querySelector('div.classifiedInfo>h3');
|
||||||
|
const locationTag = document.querySelector('div.classifiedInfo > h2 ');
|
||||||
|
const infoTag = document.querySelector('div.classifiedInfo>ul.classifiedInfoList ');
|
||||||
|
const desc = document.querySelector("div#classifiedDescription > p")
|
||||||
|
|
||||||
|
|
||||||
|
if (title) {
|
||||||
|
const dataObject = {
|
||||||
|
content: title.textContent, // Adjust this based on your needs
|
||||||
|
};
|
||||||
|
console.log(dataObject )
|
||||||
|
const priceObj = priceTag.textContent.split("\n")
|
||||||
|
|
||||||
|
const price = priceObj.find(item=>item.trim()).trim()
|
||||||
|
console.log(price)
|
||||||
|
const location = locationTag.textContent.split("\n").map(item=>item.trim()).filter(item=>item).join(' ')
|
||||||
|
console.log(location)
|
||||||
|
const description = document.querySelector('.classifiedDescription');
|
||||||
|
if (infoTag) {
|
||||||
|
const infoItems = infoTag.querySelectorAll('li');
|
||||||
|
|
||||||
|
const resultObject = {};
|
||||||
|
|
||||||
|
infoItems.forEach((li) => {
|
||||||
|
const fieldName = li.querySelector('strong').textContent.trim();
|
||||||
|
const fieldValue = li.querySelector('span').textContent.trim();
|
||||||
|
resultObject[fieldName] = fieldValue;
|
||||||
|
});
|
||||||
|
console.log(resultObject)
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(desc.innerText)
|
||||||
|
|
||||||
|
const h3Elements = description.querySelectorAll('h3');
|
||||||
|
|
||||||
|
const descriptionObject = {};
|
||||||
|
|
||||||
|
h3Elements.forEach((h3) => {
|
||||||
|
const category = h3.textContent.trim();
|
||||||
|
|
||||||
|
const ul = h3.nextElementSibling;
|
||||||
|
if (ul && ul.tagName === 'UL') {
|
||||||
|
const liElements = ul.querySelectorAll('li');
|
||||||
|
const itemsInfo = [];
|
||||||
|
|
||||||
|
liElements.forEach((li) => {
|
||||||
|
const itemText = li.textContent.trim();
|
||||||
|
|
||||||
|
const isSelected = li.classList.contains('selected');
|
||||||
|
|
||||||
|
// Add information about the item to the array
|
||||||
|
itemsInfo.push({
|
||||||
|
item: itemText,
|
||||||
|
selected: isSelected,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
descriptionObject[category] = itemsInfo;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(descriptionObject);
|
||||||
|
|
||||||
|
// Send the data to the background script
|
||||||
|
// chrome.runtime.sendMessage({ data: dataObject });
|
||||||
|
}
|
||||||
|
}
|
BIN
images/acho-bark.png
Normal file
BIN
images/acho-bark.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
BIN
images/icon16.png
Normal file
BIN
images/icon16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 813 B |
BIN
images/icon24.png
Normal file
BIN
images/icon24.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1012 B |
BIN
images/icon32.png
Normal file
BIN
images/icon32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
24
manifest.json
Normal file
24
manifest.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"manifest_version": 3,
|
||||||
|
"name": "Parser",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "Parser for sahibinden.com",
|
||||||
|
"action": {
|
||||||
|
"default_icon": {
|
||||||
|
"16": "images/icon16.png",
|
||||||
|
"24": "images/icon24.png",
|
||||||
|
"32": "images/icon32.png"
|
||||||
|
},
|
||||||
|
"default_popup": "popup.html"
|
||||||
|
},
|
||||||
|
"permissions": [
|
||||||
|
"tabs",
|
||||||
|
"storage"
|
||||||
|
],
|
||||||
|
"content_scripts": [
|
||||||
|
{
|
||||||
|
"matches": ["*://www.sahibinden.com/*"], // Update this line
|
||||||
|
"js": ["content.js"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
9
popup.css
Normal file
9
popup.css
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#acho {
|
||||||
|
display: block;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
#dialog-box {
|
||||||
|
text-align: center;
|
||||||
|
font-size: medium;
|
||||||
|
}
|
14
popup.html
Normal file
14
popup.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Acho, where are we?</title>
|
||||||
|
<link href="popup.css" rel="stylesheet" type="text/css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p id="dialog-box"></p>
|
||||||
|
<img id="acho" src="images/acho-bark.png" alt="Acho the pup">
|
||||||
|
|
||||||
|
<script src='popup.js'></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
27
popup.js
Normal file
27
popup.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
const dialogBox = document.getElementById('dialog-box');
|
||||||
|
const query = { active: true, currentWindow: true };
|
||||||
|
|
||||||
|
chrome.tabs.query(query, (tabs) => {
|
||||||
|
dialogBox.innerHTML = getBarkedTitle(tabs[0].title);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const getBarkedTitle = (tabTitle) => {
|
||||||
|
const barkTitle = `${getRandomBark()} Ahem.. I mean, we are at: ${tabTitle}`
|
||||||
|
return barkTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
const barks = [
|
||||||
|
'Barf barf!',
|
||||||
|
'Birf birf!',
|
||||||
|
'Woof woof!',
|
||||||
|
'Arf arf!',
|
||||||
|
'Yip yip!',
|
||||||
|
'Biiiirf!'
|
||||||
|
]
|
||||||
|
|
||||||
|
const getRandomBark = () => {
|
||||||
|
const bark = barks[Math.floor(Math.random() * barks.length)];
|
||||||
|
return bark;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user