Dall-e-2 Copy Button Userscript

Copy 6 mini images to clipboard

当前为 2022-06-28 提交的版本,查看 最新版本

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址