分享一個在themoviedb網站抓取EP標題的腳本
本來在想要不要發布的畢竟沒有很實用 不過既然做了還是發布一下好了
圖片中有個按鈕 可以複製當前頁面的所有標題
==========分隔線==========
// ==UserScript==
// @name 抓取themoviedb網站影集EP標題
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Scrape specific elements and copy text to clipboard
// @author You
// @match https://www.themoviedb.org/tv/*/season/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 定義CSS選擇器來選擇所有具有固定父元素類名"episode_title"內的標題元素
const selector = '.episode_title a.no_click.open';
// 添加一個按鈕到頁面上
const button = document.createElement('button');
button.textContent = '複製標題';
button.style.position = 'fixed';
button.style.bottom = '10px';
button.style.right = '10px';
button.style.zIndex = 1000;
button.style.padding = '10px 20px';
button.style.backgroundColor = '#007bff';
button.style.color = '#ffffff';
button.style.border = 'none';
button.style.borderRadius = '5px';
button.style.cursor = 'pointer';
document.body.appendChild(button);
// 按鈕點擊事件
button.addEventListener('click', () => {
let textsToCopy = [];
// 使用CSS選擇器選擇所有符合條件的元素
const elements = document.querySelectorAll(selector);
elements.forEach(element => {
textsToCopy.push(element.textContent.trim());
});
if (textsToCopy.length > 0) {
let textToCopy = textsToCopy.join('\n');
navigator.clipboard.writeText(textToCopy).then(() => {
console.log('Text copied to clipboard:', textToCopy);
alert('複製成功:\n' + textToCopy);
}).catch(err => {
console.error('Could not copy text: ', err);
});
} else {
alert('未找到任何資料可複製');
}
});
})();
留言
張貼留言