Greasy Fork is available in English.

Dall-e-2 Copy Button Userscript

Copy the images to clipboard,

  1. // ==UserScript==
  2. // @name Dall-e-2 Copy Button Userscript
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Copy the images to clipboard,
  6. // @author Jonathan, shoutout to will
  7. // @match https://labs.openai.com/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // @license CC
  11. // ==/UserScript==
  12. (function() {
  13. 'use strict';
  14. const getImCount = () => document.querySelectorAll(".task-page-generations .generated-image-overlay").length;
  15. const addBtn = function() {
  16. const node = document.getElementsByClassName('task-page-generations')[0];
  17. const makeImage = function() {
  18. const imCount = getImCount();
  19. console.log('copy button clicked');
  20. const canvas = document.createElement('canvas');
  21. canvas.id = "copy-canvas";
  22. const imSize = 400;
  23. const margin = 8;
  24. const imAcross = imCount == 6 ? 3 : 2;
  25. canvas.width = imAcross*imSize + (4*margin);
  26. canvas.height= 2*imSize + (2*margin) + 50;
  27. const body = document.getElementsByTagName("body")[0];
  28. body.appendChild(canvas);
  29. const ctx = canvas.getContext('2d');
  30. ctx.fillStyle = "white";
  31. ctx.fillRect(0, 0, canvas.width, canvas.height);
  32. const images = document.getElementsByClassName('generated-image');
  33. const sig = document.getElementsByClassName('image-signature')[0];
  34. for(var i = 0; i < imCount; i++) {
  35. const img = images.item(i).firstChild;
  36. const x = (imSize * i + (i%imAcross*margin)) % (imAcross*imSize) + margin;
  37. const y = margin+ (i<imAcross?0:imSize + margin);
  38. ctx.drawImage(img, x, y, imSize, imSize);
  39. ctx.translate(x+imSize-80, y+imSize-16);
  40. for(var p=0;p<sig.children.length;p++) {
  41. const pp = sig.children[p]
  42. const path = new Path2D(pp.getAttribute('d'));
  43. ctx.fillStyle = pp.getAttribute('fill');
  44. ctx.fill(path);
  45. }
  46. ctx.setTransform(1,0,0,1,0,0);
  47. }
  48. ctx.fillStyle = "black";
  49.  
  50.  
  51. const text = "DALL·E - " + document.getElementsByClassName('image-prompt-input')[0].value;
  52. let fntSize = 32;
  53. ctx.font = `${fntSize}pt Charter, Georgia`;
  54. while(ctx.measureText(text).width > canvas.width - 32) {
  55. fntSize -= 0.25;
  56. ctx.font = `${fntSize}pt Charter, Georgia`;
  57. }
  58. ctx.fillText(text, 16, canvas.height-42+12, canvas.width - 32);
  59. canvas.toBlob(function(blob) {
  60. const item = new ClipboardItem({'image/png': blob });
  61. navigator.clipboard.write([item]);
  62. })
  63. document.getElementById("copy-canvas").outerHTML = "";
  64. };
  65. const saveAll = function() {
  66. const imCount = getImCount();
  67. for(let i = 0; i < imCount; i++) {
  68. document.getElementsByClassName("task-page-quick-actions-button")[i].click();
  69. document.getElementsByClassName("menu-item menu-item-selectable")[3].click();
  70. }
  71. };
  72. const rowDiv = document.createElement('div');
  73. rowDiv.style.cssText = 'align-items: horizontal; align-self: center; flex: auto; align-items: center; padding-bottom: 10px; display: flex; flex-direction: row;max-height: 56px;'
  74. if (!node) return;
  75. node.prepend(rowDiv);
  76. const mkBtn = function(txt, id) {
  77. const btn = document.createElement('div');
  78. btn.innerHTML = `<button id="${id}" class="btn btn-medium btn-filled btn-secondary" type="button" aria-haspopup="true" aria-expanded="false"><span class="btn-label-wrap"><span class="btn-label-inner">${txt}</span></span></button>`;
  79. rowDiv.prepend(btn);
  80. return btn;
  81. }
  82. const btnCopy = mkBtn('Copy', 'btn-copy')
  83. const btnSave = mkBtn('Save', 'btn-save')
  84. btnSave.style['padding-right'] = '10px';
  85. btnSave.addEventListener('click', saveAll);
  86. btnCopy.addEventListener('click', makeImage);
  87. }
  88. setInterval(function() {
  89. // if task-page-generations-grid is on the page, and the buttons are not, add them
  90. const imCount = getImCount();
  91. if(document.getElementsByClassName("task-page-quick-actions-button").length == imCount) {
  92. if(!document.getElementById('btn-copy')) {
  93. addBtn();
  94. }
  95. }
  96. },500);
  97. })();