Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ExZuperi committed May 5, 2024
1 parent bcc1462 commit e820ff6
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 0 deletions.
23 changes: 23 additions & 0 deletions bing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let linksDictionary = {};

function parseAndLogLinks() {
const linkElements = document.querySelectorAll('a[class="tilk"]');
linkElements.forEach(linkElement => {
const link = linkElement.getAttribute('href');
if (!(link in linksDictionary)) {
linksDictionary[link] = true;
console.log(link);
}
});

browser.storage.local.set({ links: Object.keys(linksDictionary) }, function() {
console.log('Links saved to storage');
});
}

const observer = new MutationObserver(parseAndLogLinks);
observer.observe(document.body, { childList: true, subtree: true });

window.addEventListener('scroll', () => {
browser.runtime.sendMessage({ action: 'updateLinksCount' });
});
23 changes: 23 additions & 0 deletions duck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let linksDictionary = {};

function parseAndLogLinks() {
const linkElements = document.querySelectorAll('a[class="eVNpHGjtxRBq_gLOfGDr LQNqh2U1kzYxREs65IJu"]');
linkElements.forEach(linkElement => {
const link = linkElement.getAttribute('href');
if (!(link in linksDictionary)) {
linksDictionary[link] = true;
console.log(link);
}
});

browser.storage.local.set({ links: Object.keys(linksDictionary) }, function() {
console.log('Links saved to storage');
});
}

const observer = new MutationObserver(parseAndLogLinks);
observer.observe(document.body, { childList: true, subtree: true });

window.addEventListener('scroll', () => {
browser.runtime.sendMessage({ action: 'updateLinksCount' });
});
23 changes: 23 additions & 0 deletions google.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let linksDictionary = {};

function parseAndLogLinks() {
const linkElements = document.querySelectorAll('a[jsname="UWckNb"]');
linkElements.forEach(linkElement => {
const link = linkElement.getAttribute('href');
if (!(link in linksDictionary)) {
linksDictionary[link] = true;
console.log(link);
}
});

browser.storage.local.set({ links: Object.keys(linksDictionary) }, function() {
console.log('Links saved to storage');
});
}

const observer = new MutationObserver(parseAndLogLinks);
observer.observe(document.body, { childList: true, subtree: true });

window.addEventListener('scroll', () => {
browser.runtime.sendMessage({ action: 'updateLinksCount' });
});
Binary file added icons/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"manifest_version": 2,
"name": "Search Links Scraper",
"version": "1.0",
"permissions": ["activeTab", "tabs", "storage", "downloads"],
"browser_action": {
"default_icon": "icons/icon128.png",
"default_popup": "popup.html"
},
"icons": {
"128": "icons/icon128.png"
},
"content_scripts": [
{
"matches": ["*://www.google.com/*"],
"js": ["google.js"]
},
{
"matches": ["*://yandex.ru/*"],
"js": ["yandex.js"]
},
{
"matches": ["*://www.bing.com/*"],
"js": ["bing.js"]
},
{
"matches": ["*://duckduckgo.com/*"],
"js": ["duck.js"]
}
]
}
30 changes: 30 additions & 0 deletions popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Google Link Scraper</title>
<style>
body {
width: 300px;
padding: 10px;
font-family: Arial, sans-serif;
}
button {
width: 100%;
padding: 8px 0;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
margin-bottom: 10px;
}
</style>
</head>
<body>
<h2>Search Links Scraper</h2>
<p>Total links: <span id="totalLinks">0</span></p>
<button id="saveLinks">Save Links From Search</button>
<script src="popup.js"></script>
</body>
</html>
39 changes: 39 additions & 0 deletions popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
document.addEventListener('DOMContentLoaded', () => {
const saveLinksButton = document.getElementById('saveLinks');
const totalLinksSpan = document.getElementById('totalLinks');

// Function to update total links count
function updateTotalLinksCount() {
browser.storage.local.get('links', (data) => {
const links = data.links || [];
totalLinksSpan.textContent = links.length;
});
}

// Update total links count when popup opens
updateTotalLinksCount();

// Save links button functionality
saveLinksButton.addEventListener('click', () => {
browser.storage.local.get('links', (data) => {
const links = data.links || [];
const file = new Blob([links.join('\n')], { type: 'text/plain' });
const url = URL.createObjectURL(file);
const link = document.createElement('a');
link.href = url;
link.download = 'links.txt';
link.click();
URL.revokeObjectURL(url);
});
});

// Update total links count when scrolling the page
browser.tabs.executeScript({ code: 'window.addEventListener("scroll", () => { browser.runtime.sendMessage({ action: "updateLinksCount" }); });' });

// Listen for messages from content script to update total links count
browser.runtime.onMessage.addListener((message) => {
if (message.action === 'updateLinksCount') {
updateTotalLinksCount();
}
});
});
23 changes: 23 additions & 0 deletions yandex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let linksDictionary = {};

function parseAndLogLinks() {
const linkElements = document.querySelectorAll('a[class="Link Link_theme_normal OrganicTitle-Link organic__url link"]');
linkElements.forEach(linkElement => {
const link = linkElement.getAttribute('href');
if (!(link in linksDictionary)) {
linksDictionary[link] = true;
console.log(link);
}
});

browser.storage.local.set({ links: Object.keys(linksDictionary) }, function() {
console.log('Links saved to storage');
});
}

const observer = new MutationObserver(parseAndLogLinks);
observer.observe(document.body, { childList: true, subtree: true });

window.addEventListener('scroll', () => {
browser.runtime.sendMessage({ action: 'updateLinksCount' });
});

0 comments on commit e820ff6

Please sign in to comment.