-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
71 lines (67 loc) · 2.38 KB
/
popup.js
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
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
this.popupName = "dashboardPopup"
let urlCollectorCanvas = document.getElementById('urlCollector');
// When you click the extension app icon to loading the popup.html,
// then display resources.
function init() {
var bgPage = chrome.extension.getBackgroundPage();
bgPage.sendMessageToView();
setPopupSizeAndPosition();
}
init();
window.setInterval(function () {
setPopupSizeAndPosition();
}, 100);
var lastPopupWidth = 0;
var lastPopupHeight = 0;
function setPopupSizeAndPosition() {
chrome.windows.getCurrent(function (window) {
let width = window.width || 640;
let height = window.height || 480;
width = width / 2 - 40;
height = height - 40;
if (Math.abs(lastPopupWidth - width) > 1 || Math.abs(lastPopupHeight - height) > 1) {
document.body.style.width = width + "px";
document.body.style.height = height + "px";
lastPopupWidth = width;
lastPopupHeight = height;
}
});
}
function showUrlCollectorValue(windowRoot, tab) {
let elm = document.getElementById("urlCollector");
let hasContent = false;
if (windowRoot) {
let summary = "";
let message = "";
let filterExtension = tab.getFilterExtension();
let dashboard = tab.getDashboard();
if (filterExtension.getMessage()) {
message = "<b><i style='color:red'>" + filterExtension.getMessage() + "</i></b><hr/>";
}
dashboard.handleResContent(function (resContent) {
summary = summary + resContent + "<hr />";
});
hasContent = true;
summary = dashboard.getSummary() + message + summary;
if (elm) elm.innerHTML = summary;
if (!hasContent) elm.innerHTML = "";
}
}
document.addEventListener("click", function (event) {
logMsg("document clicked: " + JSON.stringify(event));
});
urlCollectorCanvas.addEventListener("click", function (event) {
let tar = event.target;
let url = "";
if (tar && (url = tar.getAttribute("url"))) {
tar.value = "Copied";
copyTextToClipboard(document, url);
logMsg("resource copied, " + url);
}
logMsg("div clicked: " + JSON.stringify(event));
event.stopPropagation();
});