Skip to content

Commit

Permalink
Merge pull request #6 from roxaloxa/030220-clipboard
Browse files Browse the repository at this point in the history
added copy to clipboard & options
  • Loading branch information
FutureMillennium committed Feb 3, 2020
2 parents a96ff42 + eae71bb commit 6b5d306
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
4 changes: 3 additions & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"permissions": [
"https://www.youtube.com/*",
"webNavigation",
"storage"
"storage",
"clipboardWrite",
"clipboardRead"
]
}
6 changes: 6 additions & 0 deletions extension/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ <h2>Settings</h2>

<p><label><input type="checkbox" id="ScreenshotKeyCheck" /> <code>P</code> keyboard shortcut to take screenshot</label></p>

<p>Functionality
<label><input type="radio" name="ScreenshotFunctionalityCheck" value="0" id="SFCSave"> Save to file</label>
<label><input type="radio" name="ScreenshotFunctionalityCheck" value="1" id="SFCCopy"> Copy to clipboard</label>
<label><input type="radio" name="ScreenshotFunctionalityCheck" value="2" id="SFCBoth"> Both<label>
</p>

<h2>Extra features</h2>
<p><label><input type="checkbox" id="PlaybackSpeedButtonsCheck" /> Playback rate buttons</label></p>

Expand Down
30 changes: 29 additions & 1 deletion extension/options.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
19 changes: 15 additions & 4 deletions extension/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var activePBRButton;
var screenshotKey = false;
var playbackSpeedButtons = false;
var screenshotFunctionality = 0;

function CaptureScreenshot() {

Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6b5d306

Please sign in to comment.