commit 289c386119594ca4691e25a83b44ee2763ce49ee Author: Şahin Akkaya Date: Fri Mar 8 16:35:54 2024 +0300 Initial commit diff --git a/content.js b/content.js new file mode 100644 index 0000000..d24ec9c --- /dev/null +++ b/content.js @@ -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 }); + } +} diff --git a/images/acho-bark.png b/images/acho-bark.png new file mode 100644 index 0000000..18143e3 Binary files /dev/null and b/images/acho-bark.png differ diff --git a/images/icon16.png b/images/icon16.png new file mode 100644 index 0000000..dffac8e Binary files /dev/null and b/images/icon16.png differ diff --git a/images/icon24.png b/images/icon24.png new file mode 100644 index 0000000..66fb975 Binary files /dev/null and b/images/icon24.png differ diff --git a/images/icon32.png b/images/icon32.png new file mode 100644 index 0000000..b74c2eb Binary files /dev/null and b/images/icon32.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..7778a1c --- /dev/null +++ b/manifest.json @@ -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"] + } + ] +} diff --git a/popup.css b/popup.css new file mode 100644 index 0000000..ad45be1 --- /dev/null +++ b/popup.css @@ -0,0 +1,9 @@ +#acho { + display: block; + margin: auto; +} + +#dialog-box { + text-align: center; + font-size: medium; +} diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..5dc5165 --- /dev/null +++ b/popup.html @@ -0,0 +1,14 @@ + + + + + Acho, where are we? + + + +

+ Acho the pup + + + + diff --git a/popup.js b/popup.js new file mode 100644 index 0000000..3241233 --- /dev/null +++ b/popup.js @@ -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; +}