Created
January 15, 2024 14:31
-
-
Save yshalsager/4b41a5e5c2f85c5abb492a8bb637889d to your computer and use it in GitHub Desktop.
albabtainlibrary extract books urls
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
// ==UserScript== | |
// @name albabtainlibrary extract books urls | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Copy books pages URL from albabtainlibrary. | |
// @author yshalsager | |
// @match *://albabtainlibrary.org/zobair_list/ | |
// @match *://albabtainlibrary.org/zobair_list/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=albabtainlibrary.org | |
// @run-at document-idle | |
// ==/UserScript== | |
function getInfo(container) { | |
return Array.from(container.querySelectorAll('a.read-more.button[href*="/archives/zobair/"')) | |
.map(item => { | |
return decodeURI(item.href); | |
}) | |
.join("\n"); | |
} | |
(async function() { | |
'use strict'; | |
const booksConainerSelector = ".mh-the-content"; | |
const booksFilesContainer = document.querySelector(booksConainerSelector); | |
let results = getInfo(booksFilesContainer); | |
let pagination = document.querySelector("a.next"); | |
while (pagination) { | |
const response = await fetch(pagination.href); | |
const html = await response.text(); | |
const parser = new DOMParser(); | |
const doc = parser.parseFromString(html, 'text/html'); | |
results += "\n" + getInfo(doc.querySelector(booksConainerSelector)); | |
pagination = doc.querySelector("a.next") | |
} | |
const htmlString = `<a href="#" style="color: white; padding: 24px;"><span style="width: 125px; padding-end: 1px;">نسخ الروابط</span></a>`; | |
const container = document.createElement('div'); | |
container.setAttribute("style", "background: #ab1e56; width: fit-content; padding: 5px;"); | |
container.innerHTML = htmlString; | |
container.addEventListener('click', () => { | |
navigator.clipboard.writeText(results) | |
.then(() => { | |
alert('نسخت الروابط إلى الحافظة'); | |
}) | |
.catch(error => { | |
alert('Error copying title to clipboard:', error); | |
}); | |
}); | |
document.querySelector(".mh-the-content").appendChild(container); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment