Skip to content

Commit

Permalink
v106 - extensions updated
Browse files Browse the repository at this point in the history
  • Loading branch information
annihilation7071 committed Dec 29, 2024
1 parent 25da034 commit d0b3f34
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 40 deletions.
Binary file added extension/Extended/downloader-chrome.crx
Binary file not shown.
37 changes: 37 additions & 0 deletions extension/Extended/downloader-chrome/content-general.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
async function isServerAvailable(url) {
try {

const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({url: "test"})
})

return response.ok; // true
} catch (error) {
return false;
}
}

function wait(milliseconds) {
return new Promise(resolve => {setTimeout(resolve, milliseconds)})
}

function waitForElements(selector, interval = 500, timeout = 20000) {
return new Promise((resolve) => {
const startTime = Date.now()

const timer = setInterval(() => {
const elements = document.querySelectorAll(selector)
if (elements.length > 0) {
clearInterval(timer)
resolve(elements)
} else if (Date.now() - startTime > timeout) {
clearInterval(timer)
resolve(null)
}
}, interval)
})
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
console.log("script-start")
console.log("hitomi.la")

window.addEventListener("load", async () => {
console.log("Page loaded, check server available...")

setTimeout(async () => {
console.log("wait 0.5 sec")
const serverUrl = "http://127.0.0.1:1707/get-status"
const serverAvailable = await isServerAvailable(serverUrl)

Expand All @@ -12,28 +12,36 @@ setTimeout(async () => {
return
}

await executeScript()
}, 500)
console.log("server available")
console.log("waiting for elements")

await checkElements()

async function executeScript() {
let elements_count = -1
let count = 0
const interval = 5000
const timeout = 20000
const startTime = Date.now()

async function find_elements() {
const galleryItems = document.querySelectorAll(".gallery-content > div")
if (galleryItems.length > elements_count) {
elements_count = galleryItems.length
await wait(500)
return find_elements()
} else if (galleryItems.length === elements_count) {
return galleryItems
const intervalId = setInterval(async () => {
console.log("checking elements")
if (Date.now() - startTime >= timeout) {
clearInterval(intervalId)
}
await checkElements()
}, interval)

async function checkElements() {
const elements = await waitForElements(".gallery-content > div:not(.checked)", 500, 5000)
if (elements) {
console.log("Elements found: " + elements.length)
await executeScript(elements)
} else {
console.log("Elements not found")
}
}

const galleryItems = await find_elements()
})

console.log("Elements found: ", galleryItems.length)
async function executeScript(galleryItems) {

for (const item of galleryItems) {

Expand Down Expand Up @@ -68,6 +76,7 @@ async function executeScript() {
} else if (status === "deleted") {
addStatusElement(item, "deleted", "Prevorus deleted!")
}
item.classList.add("checked")
} catch (error) {
console.error("Error!", error)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "SF.ViewerH.Downloader.Extended",
"version": "1.0",
"version": "1.1",
"permissions": [
"activeTab",
"scripting"
Expand Down
Binary file added extension/Lite/downloader-chrome.crx
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "SF.ViewerH.Downloader",
"version": "1.0",
"name": "SF.ViewerH.Downloader.Lite",
"version": "1.1",
"permissions": [
"activeTab",
"scripting"
Expand Down
Binary file removed extension/estension_v2/downloader-chrome.crx
Binary file not shown.
20 changes: 0 additions & 20 deletions extension/estension_v2/downloader-chrome/content-general.js

This file was deleted.

Binary file removed extension/extension_v1/downloader-chrome.crx
Binary file not shown.

0 comments on commit d0b3f34

Please sign in to comment.