add lisp packages

This commit is contained in:
2020-12-05 21:29:49 +01:00
parent 85e20365ae
commit a6e2395755
7272 changed files with 1363243 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
(function() {
const activeElement = document.activeElement;
activeElement.blur();
})();

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,46 @@
(function() {
function getVisibleElements(filter) {
var all = Array.from(document.documentElement.getElementsByTagName("*"));
var visibleElements = [];
for (var i = 0; i < all.length; i++) {
var e = all[i];
// include elements in a shadowRoot.
if (e.shadowRoot) {
var cc = e.shadowRoot.querySelectorAll('*');
for (var j = 0; j < cc.length; j++) {
all.push(cc[j]);
}
}
var rect = e.getBoundingClientRect();
if ( (rect.top <= window.innerHeight) && (rect.bottom >= 0)
&& (rect.left <= window.innerWidth) && (rect.right >= 0)
&& rect.height > 0
&& getComputedStyle(e).visibility !== 'hidden'
) {
filter(e, visibleElements);
}
}
return visibleElements;
}
var cssSelector = "input";
var elements = getVisibleElements(function(e, v) {
if (e.matches(cssSelector) && !e.disabled && !e.readOnly
&& (e.type === "text" || e.type === "search" || e.type === "password")) {
v.push(e);
}
});
if (elements.length === 0 && document.querySelector(cssSelector) !== null) {
document.querySelector(cssSelector).scrollIntoView();
elements = getVisibleElements(function(e, v) {
if (e.matches(cssSelector) && !e.disabled && !e.readOnly) {
v.push(e);
}
});
}
if (elements.length >= 1) {
elements[0].focus();
}
})();

View File

@@ -0,0 +1,3 @@
(function() {
return window.getComputedStyle(document.body, null).backgroundColor.toString();
})();

View File

@@ -0,0 +1,156 @@
(function() {
function cssSelector(el) {
let path = [], parent;
while (parent = el.parentNode) {
path.unshift(`${el.tagName}:nth-child(${[].indexOf.call(parent.children, el)+1})`);
el = parent;
}
return `${path.join(' > ')}`.toLowerCase();
}
function getCoords(link){
let rect = link.getBoundingClientRect();
return [ rect.top, rect.left, rect.right, rect.bottom, cssSelector(link) ];
}
function isElementOnScreen(rect){
let clientHeight = document.documentElement.clientHeight;
let clientWidth = document.documentElement.clientWidth;
return (rect[0] >= 0 && rect[0] <= clientHeight &&
rect[1] >= 0 && rect[1] <= clientWidth &&
rect[2] != 0 && rect[3] != 0);
}
function isElementOnTop(element, rect){
let topElement = document.elementFromPoint((rect[1] + rect[2])/2, (rect[0] + rect[3])/2);
return topElement != undefined && (element.isSameNode(topElement) || element.contains(topElement) || topElement.contains(element));
}
function hasCopy(validRects, rect){
for(let i = 0; i < validRects.length; i++) {
let each = validRects[i];
if(each[0] === rect[0] && each[1] === rect[1]){
return true;
}
}
return false;
}
function addElementToRects(validRects, elements){
let rect;
for(let i = 0; i < elements.length; i++) {
rect = getCoords(elements[i]);
if(!hasCopy(validRects, rect) &&
isElementOnScreen(rect) &&
isElementOnTop(elements[i], rect)){
validRects.push(rect);
}
}
}
function cAdd1(keyCounter, index, maxDigit){
if(keyCounter[index] + 1 == maxDigit){
keyCounter[index] = 0;
cAdd1(keyCounter, index + 1, maxDigit);
} else {
keyCounter[index]++;
}
}
function generateKeys(markerContainer) {
let lettersString = "%1";
let letters = lettersString.split("");
let linkNum = markerContainer.children.length;
let keyLen = linkNum == 1 ? 1 : Math.ceil(Math.log(linkNum)/Math.log(letters.length));
let keyCounter = [];
for(let i = 0; i < keyLen; i++) keyCounter[i] = 0;
for(let l = 0; l < linkNum; l++) {
let keyStr = '';
for(let k = 0; k < keyLen; k++) {
let mark = document.createElement('span');
mark.setAttribute('class', 'eaf-mark');
let key = letters[keyCounter[k]];
mark.textContent = key;
markerContainer.children[l].appendChild(mark);
keyStr += key;
cAdd1(keyCounter, 0, letters.length);
}
markerContainer.children[l].id = keyStr;
}
}
let style = document.createElement('style');
document.head.appendChild(style);
style.type = 'text/css';
style.setAttribute('class', 'eaf-style');
style.appendChild(document.createTextNode('\
.eaf-mark {\
background: none;\
border: none;\
bottom: auto;\
box-shadow: none;\
color: black !important;\
cursor: auto;\
display: inline;\
float: none;\
font-size: inherit;\
font-variant: normal;\
font-weight: bold;\
height: auto;\
left: auto;\
letter-spacing: 0;\
line-height: 100%;\
margin: 0;\
max-height: none;\
max-width: none;\
min-height: 0;\
min-width: 0;\
opacity: 1;\
padding: 0;\
position: static;\
right: auto;\
text-align: left;\
text-decoration: none;\
text-indent: 0;\
text-shadow: none;\
text-transform: none;\
top: auto;\
vertical-align: baseline;\
white-space: normal;\
width: auto;\
z-index: 100000;\
}'));
style.appendChild(document.createTextNode('\
.eaf-marker {\
position: fixed;\
display: block;\
white-space: nowrap;\
overflow: hidden;\
font-size: 11.5px;\
background: linear-gradient(to bottom, #ffdd6e 0%, #deb050 100%);\
padding-left: 3px;\
padding-right: 3px;\
border: 1px solid #c38a22;\
border-radius: 3px;\
box-shadow: 0px 3px 7px 0px rgba(0, 0, 0, 0.3);\
z-index: 100000;\
}'));
let validRects = [];
addElementToRects(validRects, document.querySelectorAll('pre'));
let body = document.querySelector('body');
let markerContainer = document.createElement('div');
markerContainer.setAttribute('class', 'eaf-marker-container');
body.insertAdjacentElement('afterend', markerContainer);
for(let i = 0; i < validRects.length; i++) {
let marker = document.createElement('div');
marker.setAttribute('class', 'eaf-marker');
marker.setAttribute('style', 'left: ' + validRects[i][1] + 'px; top: ' + validRects[i][0] + 'px;');
marker.setAttribute('pointed-link', validRects[i][4]);
markerContainer.appendChild(marker);
}
generateKeys(markerContainer);
})();

View File

@@ -0,0 +1,23 @@
(function() {
const activeElement = document.activeElement;
var inputs = ["input", "select", "textarea"];
var pageUrl = window.location.href;
var tagName = activeElement.tagName.toLowerCase();
if (pageUrl === "https://mail.qq.com/" && activeElement) {
// QQ mail have some security mechanism that we can't fetch value of activeElement.
// So we just return empty string make is_focus method works well in browser.py
return "";
} else if (activeElement && inputs.indexOf(tagName) !== -1) {
return activeElement.value;
} else {
if (pageUrl.startsWith("https://web.telegram.org/") && activeElement.hasAttribute("placeholder")) {
return activeElement.textContent;
} else if ((pageUrl.startsWith("https://console.cloud.google.com/") || pageUrl.startsWith("https://ssh.cloud.google.com/")) && tagName == "iframe") {
// Make user can type text in Terminal of Google Cloud.
return "";
} else {
return undefined;
}
}
})();

View File

@@ -0,0 +1,166 @@
(function() {
function cssSelector(el) {
let path = [], parent;
while (parent = el.parentNode) {
path.unshift(`${el.tagName}:nth-child(${[].indexOf.call(parent.children, el)+1})`);
el = parent;
}
return `${path.join(' > ')}`.toLowerCase();
}
function getCoords(link){
let rect = link.getBoundingClientRect();
return [ rect.top, rect.left, rect.right, rect.bottom, cssSelector(link) ];
}
function isElementOnScreen(rect){
let clientHeight = document.documentElement.clientHeight;
let clientWidth = document.documentElement.clientWidth;
return (rect[0] >= 0 && rect[0] <= clientHeight &&
rect[1] >= 0 && rect[1] <= clientWidth &&
rect[2] != 0 && rect[3] != 0);
}
function isElementOnTop(element, rect){
let topElement = document.elementFromPoint((rect[1] + rect[2])/2, (rect[0] + rect[3])/2);
return topElement != undefined && (element.isSameNode(topElement) || element.contains(topElement) || topElement.contains(element));
}
function hasCopy(validRects, rect){
for(let i = 0; i < validRects.length; i++) {
let each = validRects[i];
if(each[0] === rect[0] && each[1] === rect[1]){
return true;
}
}
return false;
}
function addElementToRects(validRects, elements){
let rect;
for(let i = 0; i < elements.length; i++) {
rect = getCoords(elements[i]);
if(!hasCopy(validRects, rect) &&
isElementOnScreen(rect) &&
isElementOnTop(elements[i], rect)){
validRects.push(rect);
}
}
}
function cAdd1(keyCounter, index, maxDigit){
if(keyCounter[index] + 1 == maxDigit){
keyCounter[index] = 0;
cAdd1(keyCounter, index + 1, maxDigit);
} else {
keyCounter[index]++;
}
}
function generateKeys(markerContainer) {
let lettersString = "%1";
let letters = lettersString.split("");
let linkNum = markerContainer.children.length;
let keyLen = linkNum == 1 ? 1 : Math.ceil(Math.log(linkNum)/Math.log(letters.length));
let keyCounter = [];
for(let i = 0; i < keyLen; i++) keyCounter[i] = 0;
for(let l = 0; l < linkNum; l++) {
let keyStr = '';
for(let k = 0; k < keyLen; k++) {
let mark = document.createElement('span');
mark.setAttribute('class', 'eaf-mark');
let key = letters[keyCounter[k]];
mark.textContent = key;
markerContainer.children[l].appendChild(mark);
keyStr += key;
cAdd1(keyCounter, 0, letters.length);
}
markerContainer.children[l].id = keyStr;
}
}
let style = document.createElement('style');
document.head.appendChild(style);
style.type = 'text/css';
style.setAttribute('class', 'eaf-style');
style.appendChild(document.createTextNode('\
.eaf-mark {\
background: none;\
border: none;\
bottom: auto;\
box-shadow: none;\
color: black !important;\
cursor: auto;\
display: inline;\
float: none;\
font-size: inherit;\
font-variant: normal;\
font-weight: bold;\
height: auto;\
left: auto;\
letter-spacing: 0;\
line-height: 100%;\
margin: 0;\
max-height: none;\
max-width: none;\
min-height: 0;\
min-width: 0;\
opacity: 1;\
padding: 0;\
position: static;\
right: auto;\
text-align: left;\
text-decoration: none;\
text-indent: 0;\
text-shadow: none;\
text-transform: none;\
top: auto;\
vertical-align: baseline;\
white-space: normal;\
width: auto;\
z-index: 100000;\
}'));
style.appendChild(document.createTextNode('\
.eaf-marker {\
position: fixed;\
display: block;\
white-space: nowrap;\
overflow: hidden;\
font-size: 11.5px;\
background: linear-gradient(to bottom, #ffdd6e 0%, #deb050 100%);\
padding-left: 3px;\
padding-right: 3px;\
border: 1px solid #c38a22;\
border-radius: 3px;\
box-shadow: 0px 3px 7px 0px rgba(0, 0, 0, 0.3);\
z-index: 100000;\
}'));
let validRects = [];
addElementToRects(validRects, document.links); // collect links
addElementToRects(validRects, document.querySelectorAll('a')); // collect <a> without href
addElementToRects(validRects, document.querySelectorAll('input')); // collect <input>
addElementToRects(validRects, document.querySelectorAll('button')); // collect <button>
addElementToRects(validRects, document.querySelectorAll('[class*="btn"]')); // collect class=btn buttons
addElementToRects(validRects, document.querySelectorAll('[aria-haspopup]')); // collect menu buttons
addElementToRects(validRects, document.querySelectorAll('[role="button"]')); // collect role="button"
addElementToRects(validRects, document.querySelectorAll('textarea')); // collect <textarea>
addElementToRects(validRects, document.querySelectorAll('select')); // collect <select>
addElementToRects(validRects, document.querySelectorAll('summary')); // collect <summary>
addElementToRects(validRects, document.querySelectorAll('[class="gap"]')); // collect class="gap"
let body = document.querySelector('body');
let markerContainer = document.createElement('div');
markerContainer.setAttribute('class', 'eaf-marker-container');
body.insertAdjacentElement('afterend', markerContainer);
for(let i = 0; i < validRects.length; i++) {
let marker = document.createElement('div');
marker.setAttribute('class', 'eaf-marker');
marker.setAttribute('style', 'left: ' + validRects[i][1] + 'px; top: ' + validRects[i][0] + 'px;');
marker.setAttribute('pointed-link', validRects[i][4]);
markerContainer.appendChild(marker);
}
generateKeys(markerContainer);
})();

View File

@@ -0,0 +1,3 @@
(function() {
return window.getSelection().toString().substr(0, 20);
})();

View File

@@ -0,0 +1,31 @@
(function() {
function moveCursorToEnd(el) {
if (typeof el.selectionStart == "number") {
el.selectionStart = el.selectionEnd = el.value.length;
} else if (typeof el.createTextRange != "undefined") {
el.focus();
var range = el.createTextRange();
range.collapse(false);
range.select();
}
}
let key = "%1";
let markers = document.querySelectorAll('.eaf-marker');
let match;
for(let i = 0; i < markers.length; i++) {
if(markers[i].id === key.toUpperCase()) {
match = markers[i];
break;
}
}
if(match != undefined){
let selector = match.getAttribute('pointed-link');
let link = document.querySelector(selector);
return link.textContent;
}
return "";
})();

View File

@@ -0,0 +1,55 @@
(function() {
function moveCursorToEnd(el) {
if (typeof el.selectionStart == "number") {
el.selectionStart = el.selectionEnd = el.value.length;
} else if (typeof el.createTextRange != "undefined") {
el.focus();
var range = el.createTextRange();
range.collapse(false);
range.select();
}
}
let key = "%1";
let markers = document.querySelectorAll('.eaf-marker');
let match;
for(let i = 0; i < markers.length; i++) {
if(markers[i].id === key.toUpperCase()) {
match = markers[i];
break;
}
}
if(match != undefined){
let selector = match.getAttribute('pointed-link');
let link = document.querySelector(selector);
if(link.nodeName.toLowerCase() === 'select'){
link.focus();
}else if(link.nodeName.toLowerCase() === 'input' ||
link.nodeName.toLowerCase() === 'textarea') {
if((link.getAttribute('type') === 'submit') ||
(link.getAttribute('type') === 'checkbox')){
link.click();
} else {
link.focus(); // focus
link.click(); // show blink cursor
moveCursorToEnd(link); // move cursor to the end of line after focus.
}
} else if((link.nodeName.toLowerCase() === 'button') || // normal button
(link.nodeName.toLowerCase() === 'summary') || // summary button
(link.hasAttribute('aria-haspopup')) || // menu button
(link.getAttribute('role') === 'button') || // role="button" buttons
(link.classList.contains('btn')) || // class="btn" buttons
(link.classList.contains('gap')) || // class="gap" links
(link.getAttribute('href') === '') || // special href button
(link.getAttribute('href') === '#')){ // special href # button
link.click();
} else if(link.href != undefined && link.href != '' && link.getAttribute('href') != ''){
return link.href;
} else if(link.nodeName.toLowerCase() === 'a') {
link.click(); // most general a tag without href
}
}
return "";
})();

View File

@@ -0,0 +1,5 @@
(function() {
const activeElement = document.activeElement;
activeElement.focus();
activeElement.select();
})();

View File

@@ -0,0 +1,16 @@
(function() {
let newText = "%1";
const activeElement = document.activeElement;
if (window.location.href.startsWith("https://web.telegram.org/")) {
activeElement.textContent = decodeURIComponent(escape(window.atob(newText)));
} else {
activeElement.value = decodeURIComponent(escape(window.atob(newText)));
}
// Note: simulate input event on active element after set focus text.
// Some website need input event before submit form.
var event = document.createEvent('Event');
event.initEvent('input', true, true);
activeElement.dispatchEvent(event);
})();