-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated to work with new page layout, added locales
- Loading branch information
Showing
8 changed files
with
154 additions
and
107 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,20 @@ | ||
{ | ||
"popupTitle": { | ||
"message": "Find documents on Docer" | ||
}, | ||
"instructionsTitle": { | ||
"message": "Instructions" | ||
}, | ||
"instructionsText": { | ||
"message": "Simply open the Docer site and navigate to the document you wish to download. Once there, perform captcha verification to start the download." | ||
}, | ||
"authorText": { | ||
"message": "Author: seszele" | ||
}, | ||
"projectLinkText": { | ||
"message": "Project link, leave ⭐" | ||
}, | ||
"latestReleaseText": { | ||
"message": "Latest release" | ||
} | ||
} |
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,21 @@ | ||
{ | ||
"popupTitle": { | ||
"message": "Znajdź i pobierz dokumenty z Docer.pl" | ||
}, | ||
"instructionsTitle": { | ||
"message": "Instrukcje" | ||
}, | ||
"instructionsText": { | ||
"message": "Po prostu otwórz stronę Docer i przejdź do dokumentu, który chcesz pobrać. Na niej, wykonaj weryfikację captcha, aby rozpocząć pobieranie." | ||
}, | ||
"authorText": { | ||
"message": "Autor: seszele" | ||
}, | ||
"projectLinkText": { | ||
"message": "zostaw ⭐ na GitHubie" | ||
}, | ||
"latestReleaseText": { | ||
"message": "Najnowsza wersja" | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -1,44 +1,10 @@ | ||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { | ||
if (message.action === "download" && message.itemId) { | ||
// Random number between 1 and 9 | ||
const rc = Math.floor(Math.random() * 9) + 1; | ||
const bodyData = new URLSearchParams({ | ||
item_id: message.itemId, | ||
rc: rc | ||
}).toString(); | ||
|
||
fetch("https://docer.pl/start/download", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", | ||
"Accept": "*/*", | ||
"Cache-Control": "no-cache", | ||
"Pragma": "no-cache", | ||
"X-Requested-With": "XMLHttpRequest", | ||
"Referer": message.referer, | ||
"Origin": "https://docer.pl", | ||
}, | ||
body: bodyData, | ||
credentials: "include" | ||
}) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => { | ||
if (data && data.success && data.response && data.response.url) { | ||
chrome.tabs.create({ url: data.response.url }); // Open in a new tab | ||
} else { | ||
throw new Error('Request succeeded but no URL was provided in the response.'); | ||
} | ||
}) | ||
.catch(error => { | ||
console.error('Error during fetch:', error); | ||
sendResponse({ error: error.message }); | ||
// background.js | ||
|
||
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { | ||
if (message.action === "openTab" && message.url) { | ||
// Open the PDF URL in a new tab | ||
chrome.tabs.create({ url: message.url }, function(tab) { | ||
console.log('New tab opened with PDF:', message.url); | ||
}); | ||
} | ||
return true; // Required to use sendResponse asynchronously | ||
}); | ||
|
||
} | ||
}); |
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 |
---|---|---|
@@ -1,17 +1,44 @@ | ||
// This could be triggered by some event on the page, e.g., button click | ||
document.addEventListener('click', function(event) { | ||
if (event.target.matches('#dwn_btn')) { | ||
const item_id = event.target.getAttribute('data-id'); | ||
const referer = window.location.href; | ||
|
||
// Send the item_id to the background script | ||
chrome.runtime.sendMessage({action: "download", itemId: item_id, referer: referer}, function(response) { | ||
if(response && response.error) { | ||
console.error('Error in background script:', response.error); | ||
} else { | ||
// Handle successful response or further actions here | ||
} | ||
}); | ||
// contentScript.js | ||
|
||
} | ||
}); | ||
// Function to set up the observer | ||
function setUpObserver() { | ||
const pdfHolder = document.getElementById('pdf-holder'); | ||
if (pdfHolder) { | ||
// Create an observer instance linked to the checkForPDFUrl callback function | ||
const observer = new MutationObserver(checkForPDFUrl); | ||
|
||
// Start observing the target node for configured mutations | ||
observer.observe(pdfHolder, { childList: true, subtree: true }); | ||
|
||
console.log('Observer has been set up.'); | ||
} else { | ||
console.log('The PDF holder element does not exist on this page.'); | ||
} | ||
} | ||
|
||
function checkForPDFUrl(mutationList, observer) { | ||
for (const mutation of mutationList) { | ||
if (mutation.type === 'childList') { | ||
const pdfHolder = document.getElementById('pdf-holder'); | ||
const pdfUrlElement = pdfHolder.querySelector('[data-pdf-url]'); | ||
if (pdfUrlElement) { | ||
const pdfUrl = pdfUrlElement.getAttribute('data-pdf-url'); | ||
if (pdfUrl) { | ||
// Send the PDF URL to the background script | ||
chrome.runtime.sendMessage({action: "openTab", url: pdfUrl}); | ||
observer.disconnect(); // Disconnect the observer if not needed further | ||
console.log('PDF URL found and sent to background script:', pdfUrl); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Wait for the DOM to be fully loaded before attempting to set up the observer | ||
if (document.readyState === "complete" || document.readyState === "interactive") { | ||
// DOM is already ready to be manipulated | ||
setUpObserver(); | ||
} else { | ||
// Set up observer once DOM is fully loaded | ||
window.addEventListener('DOMContentLoaded', setUpObserver); | ||
} |
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,10 @@ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
var elements = document.querySelectorAll('[data-i18n]'); | ||
for (var i = 0; i < elements.length; i++) { | ||
var element = elements[i]; | ||
var message = chrome.i18n.getMessage(element.getAttribute('data-i18n')); | ||
if (message) { | ||
element.innerHTML = message; | ||
} | ||
} | ||
}); |
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
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