ilpost.it - extract MP3 URLs from podcast pages

Extracts MP3 URLs and provides options to open or download them

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         ilpost.it - extract MP3 URLs from podcast pages
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Extracts MP3 URLs and provides options to open or download them
// @author       Ovinomaster
// @match        https://www.ilpost.it/podcasts/*
// @icon         https://static-prod.cdnilpost.com/wp-content/uploads/favicon/favicon.ico
// @grant        none
// @license      CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
// ==/UserScript==

(function() {
'use strict';

// Function to extract MP3 URLs from <script> tags
function extractMP3Urls() {
const scriptTags = document.getElementsByTagName('script');
const mp3Urls = [];
const currentUrl = window.location.href.replace(/\/$/, ''); // Strip the last '/'
//const pattern = new RegExp(`"url":"${currentUrl}","episode_raw_url":"(https://www\\.ilpost\\.it/wp-content/uploads/.*\\.mp3)"`, 'g');
const pattern = new RegExp(`"url":"${currentUrl}","episode_raw_url":"(https://static-prod\\.cdnilpost\\.com/wp-content/uploads/.*\\.mp3)"`, 'g');

for (let script of scriptTags) {
const matches = script.textContent.match(pattern);
if (matches) {
for (let match of matches) {
//const url = match.match(/https:\/\/www\.ilpost\.it\/wp-content\/uploads\/.*\.mp3/)[0];
const url = match.match(/https:\/\/static-prod\.cdnilpost\.com\/wp-content\/uploads\/.*\.mp3/)[0];
mp3Urls.push(url);
}
}
}
return mp3Urls;
}

// Create a button to open the extracted MP3 URL in a new tab
const openButton = document.createElement('button');
openButton.innerText = 'Apri file MP3';
openButton.style.height = '36.7333px';
openButton.style.padding = '5px 10px';
openButton.style.marginLeft = '10px';
openButton.style.backgroundColor = '#ffe000';
openButton.style.color = 'black';
openButton.style.border = '0.975px solid #b4b5b6';
openButton.style.borderRadius = '7.5px';
openButton.style.cursor = 'pointer';
// openButton.style.boxShadow = '0 4px 6px rgba(0, 0, 0, 0.1)';
openButton.style.fontFamily = 'Red Hat Text, sans-serif';
openButton.style.fontSize = '.688rem';
openButton.style.fontWeight = '500';
openButton.addEventListener('mouseover', () => {
openButton.style.backgroundColor = '#ffd700';
});
openButton.addEventListener('mouseout', () => {
openButton.style.backgroundColor = '#ffe000';
});
openButton.addEventListener('click', () => {
const mp3Urls = extractMP3Urls();
if (mp3Urls.length > 0) {
const truncatedUrl = mp3Urls[0].split('.mp3')[0] + '.mp3';
window.open(truncatedUrl, '_blank');
} else {
alert('No MP3 URLs found.');
}
});

// Create a button to download the extracted MP3 URL
const downloadButton = document.createElement('button');
downloadButton.innerText = 'Scarica file MP3';
downloadButton.style.height = '36.7333px';
downloadButton.style.padding = '5px 10px';
downloadButton.style.marginLeft = '10px';
downloadButton.style.backgroundColor = '#ffe000';
downloadButton.style.color = 'black';
downloadButton.style.border = '0.975px solid #b4b5b6';
downloadButton.style.borderRadius = '7.5px';
downloadButton.style.cursor = 'pointer';
// downloadButton.style.boxShadow = '0 4px 6px rgba(0, 0, 0, 0.1)';
downloadButton.style.fontFamily = 'Red Hat Text, sans-serif';
downloadButton.style.fontSize = '.688rem';
downloadButton.style.fontWeight = '500';
downloadButton.addEventListener('mouseover', () => {
downloadButton.style.backgroundColor = '#ffd700';
});
downloadButton.addEventListener('mouseout', () => {
downloadButton.style.backgroundColor = '#ffe000';
});
downloadButton.addEventListener('click', () => {
const mp3Urls = extractMP3Urls();
if (mp3Urls.length > 0) {
const truncatedUrl = mp3Urls[0].split('.mp3')[0] + '.mp3';
const link = document.createElement('a');
link.href = truncatedUrl;
link.download = '';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} else {
alert('No MP3 URLs found.');
}
});

// Function to place the buttons inside the target div
function placeButtons() {
const divPattern = /episode_episode-buttons__/;
const actionDivPattern = /episode_episode-actions__/;
const divs = document.querySelectorAll('div');
for (let div of divs) {
if (divPattern.test(div.className)) {
const actionDiv = Array.from(div.children).find(child => actionDivPattern.test(child.className));
if (actionDiv) {
div.insertBefore(openButton, actionDiv);
div.insertBefore(downloadButton, actionDiv);
} else {
div.appendChild(openButton);
div.appendChild(downloadButton);
}
break;
}
}
}

// Wait for the page to load completely before placing the buttons
window.addEventListener('load', placeButtons);
})();