-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.user.js
146 lines (126 loc) · 5.51 KB
/
index.user.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// ==UserScript==
// @name Selenoid Clipboard Control
// @version 4.1.6
// @author Viktar Silakou
// @namespace SCC
// @homepage https://github.com/viktor-silakov/selenoid-clipboard-control
// @description Selenoid Clipboard Control User Script
// @match *
// @connect *
// @run-at document-body
// @grant GM.xmlHttpRequest
// @grant GM.setValue
// @grant GM.getValue
// @grant GM.setClipboard
// ==/UserScript==
(function () {
'use strict';
// change the value if you use custom selenoid hub port
const BASE_URL = '';
const SELENOID_HUB_PORT = '';
function waitForElm(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
resolve(document.querySelector(selector));
observer.disconnect();
}
}
);
observer.observe(document.body, {
childList: true,
subtree: true
});
}
);
}
const request = (url, method = 'GET', data) => {
return new Promise((resolve, reject) => {
GM.xmlHttpRequest({
method: method,
url,
data,
onload: function (response) {
return resolve(response.responseText);
}
});
}
)
}
const addButton = (action, text, title = '') => {
const toolbar = document.getElementsByClassName('vnc-card__controls')[0];
const buttonInside = document.createElement('div');
buttonInside.title = title;
buttonInside.innerText = text;
const button = document.createElement('a');
button.classList.add('control');
button.classList.add('clp-buttons');
button.onclick = action;
button.appendChild(buttonInside)
// button.style.backgroundColor = '#ff4d4d';
// button.style.color = '#white';
toolbar.appendChild(button);
}
window.addEventListener('load', () => {
setTimeout(() => {
if (!document.querySelector(".vnc-card__controls")) return;
console.log('Selenoid Clipboard Control user script starting...')
const sessionId = document.URL.toString().replace(/(^.+?)sessions[\/]/, '');
const baseUrl = BASE_URL || `${location.protocol}//${document.domain}`
const selenoidHubPort = SELENOID_HUB_PORT || '4444'
const url = `${baseUrl}:${selenoidHubPort}/clipboard/${sessionId}`
console.log({ url })
const getClipBoard = () => {
return request(url);
}
const setClipBoard = (data) => {
return request(url, 'POST', data);
}
const style = document.createElement('style');
style.innerText = `
.clp-buttons {
background-color: #ff4d4d !important;
color: #ff4d4d !important;
cursor: pointer;
}
.clp-buttons:hover {
background-color: #ff4d4d !important;
color: #ffffff !important;
cursor: pointer;
}`;
document.body.appendChild(style);
document.addEventListener('paste', async function (event) {
const clipText = event.clipboardData.getData('Text');
console.log({ clipText })
const resp = await setClipBoard(sessionId, clipText);
console.log({
resp
})
});
waitForElm('[title=Fullscreen]').then(async () => {
addButton(async () => {
const resp = await getClipBoard();
console.log({
'remote clipboard': resp,
})
GM.setClipboard(resp);
}
, 'G', 'get remote clipboard data');
addButton(async () => {
const text = prompt('please insert text')
const resp = await setClipBoard(text);
console.log({
resp
})
}
, 'S', 'set remote clipboard data')
}, 100)
}
)
}
)
}
)();