|
// ==UserScript== |
|
// @name Replace Clip with Save on YouTube |
|
// @namespace http://tampermonkey.net/ |
|
// @version 0.1 |
|
// @description Replaces the Clip button with the Save button on YouTube video pages |
|
// @author You |
|
// @match https://www.youtube.com/* |
|
// @grant none |
|
// @source https://gist.github.com/aleclarson/60fc2c4fd9276ceba0063066a4e55ef8 |
|
// ==/UserScript== |
|
|
|
(function () { |
|
'use strict'; |
|
|
|
let lastLocation = ''; |
|
|
|
// Function to replace the Clip button with Save |
|
function replaceClipWithSave() { |
|
// Check if location has changed |
|
if (lastLocation === window.location.href) { |
|
return; |
|
} |
|
|
|
lastLocation = window.location.href; |
|
|
|
// Check if Save button already exists |
|
const saveButton = document.querySelector('button[aria-label="Save"]'); |
|
if (saveButton) { |
|
console.log('Save button already exists, no action needed'); |
|
return; |
|
} |
|
|
|
// Look for the Clip button |
|
const clipButton = document.querySelector('button[aria-label="Clip"]'); |
|
if (!clipButton) { |
|
console.log('Clip button not found, no action needed'); |
|
return; |
|
} |
|
|
|
// Replace the text content |
|
const textElement = clipButton.querySelector('.yt-spec-button-shape-next__button-text-content'); |
|
if (textElement) { |
|
textElement.textContent = 'Save'; |
|
} |
|
|
|
// Replace the icon |
|
const iconContainer = clipButton.querySelector('.yt-spec-button-shape-next__icon'); |
|
if (iconContainer) { |
|
iconContainer.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24" focusable="false" aria-hidden="true" style="pointer-events: none; display: inherit; width: 100%; height: 100%;"><path d="M18 4v15.06l-5.42-3.87-.58-.42-.58.42L6 19.06V4h12m1-1H5v18l7-5 7 5V3z"></path></svg>' |
|
} |
|
|
|
clipButton.title = 'Save'; |
|
clipButton.setAttribute('aria-label', 'Save'); |
|
|
|
// Replace the click handler |
|
clipButton.addEventListener('click', function (e) { |
|
e.preventDefault(); |
|
e.stopImmediatePropagation(); |
|
|
|
const saveMenuItem = document.querySelector('#flexible-item-buttons [aria-label="Save to playlist"]'); |
|
|
|
if (saveMenuItem) { |
|
saveMenuItem.click(); |
|
} |
|
|
|
return false; |
|
}, true); |
|
} |
|
|
|
function callOnceElementExists(selector, callback) { |
|
return function check() { |
|
const element = document.querySelector(selector); |
|
if (element) { |
|
callback(element); |
|
} else { |
|
setTimeout(check, 100); |
|
} |
|
} |
|
} |
|
|
|
// Run the function when the page loads |
|
window.addEventListener( |
|
'load', |
|
callOnceElementExists( |
|
'ytd-watch-metadata #menu', |
|
replaceClipWithSave |
|
) |
|
); |
|
|
|
// Also run the function periodically to handle dynamic page changes |
|
setInterval(replaceClipWithSave, 2000); |
|
})(); |