Ghongha007 commited on
Commit
823003b
·
verified ·
1 Parent(s): 5dba712

Copy-and-search buttons (de61f8e)

Browse files
Files changed (3) hide show
  1. app.js +15 -1
  2. index.html +3 -3
  3. style.css +1 -0
app.js CHANGED
@@ -139,7 +139,7 @@
139
  <figcaption><span class="mono">${KF.fmtTime(f.t)}</span> <span class="how">${f.how}</span></figcaption>
140
  <div class="row small"><button type="button" data-a="png" aria-label="Download the frame at ${KF.fmtTime(f.t)} as PNG">PNG</button><button type="button" data-a="copy" aria-label="Copy the frame at ${KF.fmtTime(f.t)}">Copy</button>
141
  <button type="button" data-a="seek" title="Show this moment in the video" aria-label="Show ${KF.fmtTime(f.t)} in the video">Show</button><button type="button" data-a="del" aria-label="Remove the frame at ${KF.fmtTime(f.t)}">✕</button></div>
142
- <div class="engines">Search: ${ENGINES.map(([n, u]) => `<a href="${u}" target="_blank" rel="noopener">${n}</a>`).join(" · ")}</div>`;
143
  fig.querySelector(".thumb").onclick = () => {
144
  if (bigUrl) URL.revokeObjectURL(bigUrl); bigUrl = URL.createObjectURL(f.blob);
145
  $("big").src = bigUrl; $("big").alt = `Frame at ${KF.fmtTime(f.t)}`; $("viewer").showModal(); };
@@ -148,12 +148,26 @@
148
  try { await navigator.clipboard.write([new ClipboardItem({ "image/png": f.blob })]); status(`Frame at ${KF.fmtTime(f.t)} copied. Paste it into the search engine.`, "ok"); }
149
  catch (_) { status("This browser didn't allow copying images. Use PNG to download the frame instead.", "err"); }
150
  };
 
151
  fig.querySelector("[data-a=seek]").onclick = () => { video.currentTime = f.t; video.scrollIntoView({ behavior: "smooth", block: "center" }); };
152
  fig.querySelector("[data-a=del]").onclick = () => { frames.splice(i, 1); render(); };
153
  $("frames").appendChild(fig);
154
  });
155
  }
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  function save(blob, name) {
158
  const a = document.createElement("a"); a.href = URL.createObjectURL(blob); a.download = name;
159
  document.body.appendChild(a); a.click(); a.remove(); setTimeout(() => URL.revokeObjectURL(a.href), 60000);
 
139
  <figcaption><span class="mono">${KF.fmtTime(f.t)}</span> <span class="how">${f.how}</span></figcaption>
140
  <div class="row small"><button type="button" data-a="png" aria-label="Download the frame at ${KF.fmtTime(f.t)} as PNG">PNG</button><button type="button" data-a="copy" aria-label="Copy the frame at ${KF.fmtTime(f.t)}">Copy</button>
141
  <button type="button" data-a="seek" title="Show this moment in the video" aria-label="Show ${KF.fmtTime(f.t)} in the video">Show</button><button type="button" data-a="del" aria-label="Remove the frame at ${KF.fmtTime(f.t)}">✕</button></div>
142
+ <div class="engines"><span>Copy and search:</span> ${ENGINES.map(([n], k) => `<button type="button" class="eng" data-e="${k}" aria-label="Copy the frame at ${KF.fmtTime(f.t)} and open ${n}">${n}</button>`).join(" ")}</div>`;
143
  fig.querySelector(".thumb").onclick = () => {
144
  if (bigUrl) URL.revokeObjectURL(bigUrl); bigUrl = URL.createObjectURL(f.blob);
145
  $("big").src = bigUrl; $("big").alt = `Frame at ${KF.fmtTime(f.t)}`; $("viewer").showModal(); };
 
148
  try { await navigator.clipboard.write([new ClipboardItem({ "image/png": f.blob })]); status(`Frame at ${KF.fmtTime(f.t)} copied. Paste it into the search engine.`, "ok"); }
149
  catch (_) { status("This browser didn't allow copying images. Use PNG to download the frame instead.", "err"); }
150
  };
151
+ fig.querySelectorAll(".eng").forEach((b) => { b.onclick = () => searchWith(f, ENGINES[+b.dataset.e]); });
152
  fig.querySelector("[data-a=seek]").onclick = () => { video.currentTime = f.t; video.scrollIntoView({ behavior: "smooth", block: "center" }); };
153
  fig.querySelector("[data-a=del]").onclick = () => { frames.splice(i, 1); render(); };
154
  $("frames").appendChild(fig);
155
  });
156
  }
157
 
158
+ // Copy the frame, then open the engine's upload page, so the user only has to paste (Ctrl+V / Cmd+V).
159
+ // The tab is opened first, inside the click, so pop-up blockers allow it; it is pointed at the engine once the
160
+ // frame is on the clipboard. Nothing is sent anywhere by this page: the user pastes into the engine they chose.
161
+ async function searchWith(f, [name, url]) {
162
+ const w = window.open("", "_blank");
163
+ let copied = false;
164
+ try { await navigator.clipboard.write([new ClipboardItem({ "image/png": f.blob })]); copied = true; } catch (_) { /* fall through */ }
165
+ if (w) { try { w.opener = null; } catch (_) {} w.location.href = url; } else window.open(url, "_blank", "noopener");
166
+ const key = /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent) ? "Cmd+V" : "Ctrl+V";
167
+ status(copied ? `Frame at ${KF.fmtTime(f.t)} copied. On the ${name} page, press ${key} to paste it, or use its upload button with the PNG.`
168
+ : `${name} is open, but this browser didn't allow copying the image. Use PNG to download the frame, then upload it there.`, copied ? "ok" : "err");
169
+ }
170
+
171
  function save(blob, name) {
172
  const a = document.createElement("a"); a.href = URL.createObjectURL(blob); a.download = name;
173
  document.body.appendChild(a); a.click(); a.remove(); setTimeout(() => URL.revokeObjectURL(a.href), 60000);
index.html CHANGED
@@ -59,9 +59,9 @@
59
  <button type="button" id="clear">Clear</button>
60
  </div>
61
  </div>
62
- <p class="note">Click a frame to view it at full size. <b>Copy</b> puts the full-resolution frame on your clipboard,
63
- to paste into a search engine; the search links open the engine's own upload page, and uploading there sends the
64
- frame to that company.</p>
65
  <div id="frames" class="frames"></div>
66
  </section>
67
 
 
59
  <button type="button" id="clear">Clear</button>
60
  </div>
61
  </div>
62
+ <p class="note">Click a frame to view it at full size. Each search button copies the full-resolution frame and opens
63
+ that engine's upload page: press <b>Ctrl+V</b> (<b>Cmd+V</b> on a Mac) there to paste it in. If an engine doesn't
64
+ take a pasted image, download the PNG and use its upload button. Searching sends the frame to that company.</p>
65
  <div id="frames" class="frames"></div>
66
  </section>
67
 
style.css CHANGED
@@ -72,3 +72,4 @@ dialog { max-width: 96vw; max-height: 94vh; padding: 8px; border: 1px solid var(
72
  dialog img { display: block; max-width: 92vw; max-height: 82vh; } dialog form { text-align: right; margin-top: 6px; }
73
  dialog::backdrop { background: rgba(0,0,0,.7); }
74
  .about h2 { font-size: 1.05rem; margin: 0 0 8px; } .about ul { padding-left: 18px; font-size: .92rem; } .about li { margin: 0 0 6px; }
 
 
72
  dialog img { display: block; max-width: 92vw; max-height: 82vh; } dialog form { text-align: right; margin-top: 6px; }
73
  dialog::backdrop { background: rgba(0,0,0,.7); }
74
  .about h2 { font-size: 1.05rem; margin: 0 0 8px; } .about ul { padding-left: 18px; font-size: .92rem; } .about li { margin: 0 0 6px; }
75
+ .engines span { margin-right: 2px; } .eng { font-size: .78rem; padding: 2px 7px; margin: 2px 1px; }