-
Notifications
You must be signed in to change notification settings - Fork 0
/
Userscript.user.js
61 lines (50 loc) · 1.58 KB
/
Userscript.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
// ==UserScript==
// @name rus-to-eng-kebab-case
// @namespace http://tampermonkey.net/
// @version 1
// @author Lui22
// @require https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js
// @grant none
// @include http://*/*
// @include https://*/*
// ==/UserScript==
'use strict';
let stri
document.onkeydown = function(e) {
if(e.ctrlKey) {
switch (e.keyCode) {
case 81:
console.log('ща')
stri = null
camelize(getSelectionText())
}
}
}
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function camelize(str) {
var xhr = new XMLHttpRequest();
var params = 'q=' + encodeURIComponent(str) +
'&target=' + encodeURIComponent('en') +
'&source=' + encodeURIComponent('ru');
xhr.open("GET", 'https://api.allorigins.win/get?url=' + encodeURIComponent('https://script.google.com/macros/s/AKfycbzTpY-St_55t4l5wbt7Fg19DMMEId_yMftRIUQ4DyBQbgz6fsII/exec?') + params, true);
xhr.onload = function(){
var jsonResponse = xhr.response;
stri = JSON.parse(jsonResponse).contents
stri = _.kebabCase(stri)
console.log(stri)
navigator.clipboard.writeText(stri);
return stri;
};
xhr.send();
}