Adds "Copy Image As..." to context menu to rename images
// ==UserScript==
// @name Copy Image As
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Adds "Copy Image As..." to context menu to rename images
// @author You
// @match *://*/*
// @grant GM_setClipboard
// @run-at context-menu
// ==/UserScript==
(function() {
'use strict';
document.addEventListener('contextmenu', function(e) {
if (e.target.tagName === 'IMG') {
const img = e.target;
const newName = prompt('Enter new image name:', 'renamed_image');
if (newName) {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;
ctx.drawImage(img, 0, 0);
canvas.toBlob(blob => {
GM_setClipboard(blob, 'image/png');
});
}
}
}, true);
})();