指定されたFIVBのページで表示される「Subscribe」ポップアップを除去するために、TampermonkeyやGreasemonkeyなどのユーザースクリプトマネージャーを使用してカスタムスクリプトを作成できます。以下は、その目的を達成するためのUserScriptの例です。
// ==UserScript==
// @name Remove FIVB Subscribe Popup
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Removes the 'Subscribe' popup on FIVB Volleyball Nations League schedule page.
// @author Your Name
// @match https://en.volleyballworld.com/volleyball/competitions/volleyball-nations-league/schedule/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Function to remove the subscribe popup
function removeSubscribePopup() {
// Common class or ID for the popup (adjust based on actual structure)
const popupSelectors = [
'.popup-subscribe', // Hypothetical class for the popup
'.subscribe-modal', // Another possible class
'#subscribe-popup', // Hypothetical ID for the popup
'.modal-dialog' // Generic modal dialog class
];
popupSelectors.forEach(selector => {
const popup = document.querySelector(selector);
if (popup) {
console.log(`Removing popup with selector: ${selector}`);
popup.remove(); // Completely remove the element from the DOM
}
});
// Optionally, remove overlay background if present
const overlay = document.querySelector('.modal-backdrop, .overlay');
if (overlay) {
console.log('Removing overlay background');
overlay.remove();
}
}
// Run the removal function on page load
removeSubscribePopup();
// Observe DOM changes in case the popup is dynamically added later
const observer = new MutationObserver(() => {
removeSubscribePopup();
});
// Start observing the entire document for changes
observer.observe(document.body, { childList: true, subtree: true });
})();
スクリプトの説明
-
メタデータブロック:
@name: スクリプトの名前。
@namespace: スクリプトの識別用の名前空間。
@match: このスクリプトが適用されるURLパターン。
@grant: 特殊な権限が必要ない場合、noneを指定。
-
ポップアップの削除:
removeSubscribePopup関数では、ポップアップ要素を特定するためにいくつかのセレクタを試します。
- 実際のHTML構造に基づいてセレクタを調整してください(開発者ツールで確認可能)。
-
動的に追加されるポップアップに対応:
- ポップアップがページ読み込み後に動的に追加される可能性があるため、
MutationObserverを使用してDOMの変更を監視し、必要に応じて再度削除します。
-
オーバーレイ背景の削除:
- ポップアップと一緒に表示される半透明の背景(モーダルの裏側)も削除します。
使用方法
-
TampermonkeyやGreasemonkeyをインストール:
-
スクリプトを作成:
- Tampermonkeyダッシュボードを開き、「新しいスクリプトを作成」を選択します。
- 上記のコードを貼り付け、保存します。
-
ページをリロード:
- 指定されたFIVBのページを開くと、ポップアップが自動的に削除されます。
注意点
- 実際のHTML構造が異なる場合、セレクタを調整する必要があります。開発者ツール(F12キー)を使用して、ポップアップ要素のクラス名やIDを確認してください。
- ページのデザインや構造が更新されると、スクリプトが動作しなくなる可能性があります。その場合は、セレクタを再確認して修正してください。
このスクリプトを使用することで、指定されたページでの「Subscribe」ポップアップを効果的に除去できます。