From eae71bb65e3f8e615c00c164fde51b790a8e0f34 Mon Sep 17 00:00:00 2001 From: roxaloxa Date: Mon, 3 Feb 2020 10:40:56 +1100 Subject: [PATCH] added copy to clipboard & options --- extension/manifest.json | 4 +++- extension/options.html | 6 ++++++ extension/options.js | 30 +++++++++++++++++++++++++++++- extension/page.js | 19 +++++++++++++++---- 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/extension/manifest.json b/extension/manifest.json index 8e0010d..5af92f3 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -28,6 +28,8 @@ "permissions": [ "https://www.youtube.com/*", "webNavigation", - "storage" + "storage", + "clipboardWrite", + "clipboardRead" ] } diff --git a/extension/options.html b/extension/options.html index e788d32..485834d 100644 --- a/extension/options.html +++ b/extension/options.html @@ -45,6 +45,12 @@

Settings

+

Functionality + + +

+

Extra features

diff --git a/extension/options.js b/extension/options.js index 7ef6b68..a0ec06d 100644 --- a/extension/options.js +++ b/extension/options.js @@ -1,15 +1,43 @@ 'use strict'; -chrome.storage.sync.get(['screenshotKey', 'playbackSpeedButtons'], function(result) { +var ScreenshotFunctionalityCheck = [false, false, false]; + +chrome.storage.sync.get(['screenshotKey', 'playbackSpeedButtons', 'screenshotFunctionality'], function(result) { ScreenshotKeyCheck.checked = result.screenshotKey; PlaybackSpeedButtonsCheck.checked = result.playbackSpeedButtons; PlaybackSpeedButtonsChange(); + + if (result.screenshotFunctionality == undefined) { + chrome.storage.sync.set({ screenshotFunctionality: 0 }); + result.screenshotFunctionality = 0; + } + var radios = document.getElementsByName("ScreenshotFunctionalityCheck"); + for (var i = 0, length = radios.length; i < length; i++) { + if (i == result.screenshotFunctionality) { + radios[i].checked = true; + break; + } + } }); ScreenshotKeyCheck.oninput = function() { chrome.storage.sync.set({'screenshotKey': this.checked}); }; +var ScreenshotFunctionalitySet = function(value) { + chrome.storage.sync.set({ screenshotFunctionality: value }); +}; + +SFCSave.oninput = function() { + ScreenshotFunctionalitySet(this.value); +}; +SFCCopy.oninput = function() { + ScreenshotFunctionalitySet(this.value); +}; +SFCBoth.oninput = function() { + ScreenshotFunctionalitySet(this.value); +}; + PlaybackSpeedButtonsCheck.oninput = function() { chrome.storage.sync.set({'playbackSpeedButtons': this.checked}); PlaybackSpeedButtonsChange(); diff --git a/extension/page.js b/extension/page.js index 28d91b1..5cfd3d2 100644 --- a/extension/page.js +++ b/extension/page.js @@ -3,6 +3,7 @@ var activePBRButton; var screenshotKey = false; var playbackSpeedButtons = false; +var screenshotFunctionality = 0; function CaptureScreenshot() { @@ -56,9 +57,18 @@ function CaptureScreenshot() { var downloadLink = document.createElement("a"); downloadLink.download = title; - canvas.toBlob(function (blob) { - downloadLink.href = URL.createObjectURL(blob); - downloadLink.click(); + canvas.toBlob(async function (blob) { + if (screenshotFunctionality == 0 || screenshotFunctionality == 2) { + // download + downloadLink.href = URL.createObjectURL(blob); + downloadLink.click(); + } + + if (screenshotFunctionality == 1 || screenshotFunctionality == 2) { + // clipboard + const clipboardItemInput = new ClipboardItem({ "image/png": blob }); + await navigator.clipboard.write([clipboardItemInput]); + } }, 'image/png'); } @@ -158,9 +168,10 @@ speed3xButton.onclick = function() { activePBRButton = speed1xButton; -chrome.storage.sync.get(['screenshotKey', 'playbackSpeedButtons'], function(result) { +chrome.storage.sync.get(['screenshotKey', 'playbackSpeedButtons', 'screenshotFunctionality'], function(result) { screenshotKey = result.screenshotKey; playbackSpeedButtons = result.playbackSpeedButtons; + screenshotFunctionality = result.screenshotFunctionality; }); document.addEventListener('keydown', function(e) {