Created
June 4, 2023 14:26
-
-
Save yshalsager/eaa1ff4487318de52a103a97aca9f661 to your computer and use it in GitHub Desktop.
Islamweb extract audio with names
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 Islamweb extract audio with names | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Copy audio files URL and names from Islamweb. | |
// @author yshalsager | |
// @match *://audio.islamweb.net/audio/* | |
// @match *://audio.islamweb.com/audio/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=islamweb.net | |
// @run-at document-idle | |
// ==/UserScript== | |
function getAudioInfo(container) { | |
return Array.from(container.querySelectorAll(".sitems")) | |
.map(item => { | |
const audio = item.querySelector("a[title_data]"); | |
const url = audio.getAttribute("url"); | |
const fileName = audio.getAttribute("title_data").trim(); | |
const extension = url.split('.').pop(); | |
return `${url},${fileName}.${extension}`; | |
}) | |
.join("\n"); | |
} | |
(async function() { | |
'use strict'; | |
const audioConainerSelector = ".soundlist"; | |
const audioFilesContainer = document.querySelector(audioConainerSelector); | |
let results = getAudioInfo(audioFilesContainer); | |
let pagination = document.querySelector("ul.pagination"); | |
while (pagination) { | |
const lastPage = pagination.querySelector("li:nth-last-child(2)").textContent; | |
const nextPage = pagination.querySelector("li:not(.active):last-child"); | |
if (!nextPage) break; | |
const nextPageURL = nextPage.querySelector("a").href; | |
const response = await fetch(nextPageURL); | |
const html = await response.text(); | |
const parser = new DOMParser(); | |
const doc = parser.parseFromString(html, 'text/html'); | |
results += "\n" + getAudioInfo(doc.querySelector(audioConainerSelector)); | |
pagination = doc.querySelector("ul.pagination") | |
} | |
const htmlString = `<a href="#" style="color: white; padding: 24px;"><span style="width: 125px; padding-end: 1px;"><i class="fa fa-copy" style="padding-inline-end: 5px;"></i>نسخ الروابط</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(".mainitem").appendChild(container); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment