-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpopup.js
More file actions
106 lines (79 loc) · 3.12 KB
/
popup.js
File metadata and controls
106 lines (79 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
'use strict';
// Function to create a file name for the screenshot
function getFilename(url) {
// Creates a url object to parse the url more easily
url = new URL(url);
// Get the hostname and pathname of the url
const hostname = url.hostname.split(".").length > 2 ? url.hostname.split(".")[1] : url.hostname.split(".")[0];
var pathname = url.pathname.replace(/\//g, '-');
// Get current date and time
const today = new Date();
const date = today.getFullYear() + '-'
+ ('0' + (today.getMonth() + 1)).slice(-2) + '-'
+ ('0' + today.getDate()).slice(-2)
const time = today.getHours() + "_" + today.getMinutes() + "_" + today.getSeconds();
const dateTime = date + '-' + time;
if (pathname !== "-") pathname += "-"
return 'snapper-' + hostname + pathname + dateTime + '.png';
}
//
// Custom area button stuff
//
// EventListener for "Custom Area" button
document.getElementById("customArea").addEventListener("click", clickCustomArea);
// Function to call when "Custom Area" button is clicked.
function clickCustomArea() {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
const currentTab = tabs[0];
let filename = getFilename(currentTab.url);
initiateCustomAreaScreenshot(currentTab, filename);
});
}
//
// Visible content button stuff
//
// EventListener for "Visible Content" button
document.getElementById("visibleContent").addEventListener("click", clickVisibleContent);
// Function to call when "Visible Content" button is clicked.
function clickVisibleContent() {
// Get current active tab inforamtion
chrome.tabs.query({ currentWindow: true, active: true }, (tabs) => {
const currentTab = tabs[0];
let filename = getFilename(currentTab.url)
// Start capturing the visible content of the currently active tab
chrome.tabs.captureVisibleTab(null, { format: 'png' }, (dataURL) => {
if (dataURL) {
var data = {
image: dataURL,
width: window.innerWidth,
height: window.innerHeight,
devicePixelRatio: window.devicePixelRatio
}
// Send the image including additional information to new tab
sendImageToNewTab(data, currentTab.id, currentTab.index, filename)
}
})
});
}
//
// Full page button stuff
//
// EventListener for "Full Page" button
document.getElementById("fullPage").addEventListener("click", clickFullPage);
// Function to call when "Full Page" button is clicked.
function clickFullPage() {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
const currentTab = tabs[0];
var filename = getFilename(currentTab.url);
initiateFullPageScreenshot(currentTab, filename);
});
}
//
// Dark/Light mode switch stuff
//
// EventListener for the on/off switch
document.querySelector(".onoffswitch-checkbox").addEventListener("click", onoff);
// Function for the on/off switch for dark/light mode
function onoff() {
document.body.classList.toggle("dark-theme")
}