js

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2022 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package js generated by "lib/js/generate"

Index

Constants

This section is empty.

Variables

View Source
var AddScriptTag = &Function{
	Name:         "addScriptTag",
	Definition:   `function(i,s,r){if(!document.getElementById(i))return new Promise((e,t)=>{var n=document.createElement("script");s?(n.src=s,n.onload=e):(n.type="text/javascript",n.text=r,e()),n.id=i,n.onerror=t,document.head.appendChild(n)})}`,
	Dependencies: []*Function{},
}

AddScriptTag ...

View Source
var AddStyleTag = &Function{
	Name:         "addStyleTag",
	Definition:   `function(i,s,r){if(!document.getElementById(i))return new Promise((e,t)=>{var n;s?((n=document.createElement("link")).rel="stylesheet",n.href=s):((n=document.createElement("style")).type="text/css",n.appendChild(document.createTextNode(r)),e()),n.id=i,n.onload=e,n.onerror=t,document.head.appendChild(n)})}`,
	Dependencies: []*Function{},
}

AddStyleTag ...

View Source
var ContainsElement = &Function{
	Name:         "containsElement",
	Definition:   `function(e){for(var t=e;null!=t;){if(t===this)return!0;t=t.parentElement}return!1}`,
	Dependencies: []*Function{},
}

ContainsElement ...

View Source
var Element = &Function{
	Name:         "element",
	Definition:   `function(e){const t=functions.selectable(this);return t.querySelector(e)}`,
	Dependencies: []*Function{Selectable},
}

Element ...

View Source
var ElementOverlay = &Function{
	Name:         "elementOverlay",
	Definition:   `async function(n,e){const i=100,s=functions.tag(this);let r=s.getBoundingClientRect();await functions.overlay(n,r.left,r.top,r.width,r.height,e);const o=()=>{const e=document.getElementById(n);var t;null!==e&&(t=s.getBoundingClientRect(),r.left===t.left&&r.top===t.top&&r.width===t.width&&r.height===t.height||(e.style.left=t.left+"px",e.style.top=t.top+"px",e.style.width=t.width+"px",e.style.height=t.height+"px",r=t),setTimeout(o,i))};setTimeout(o,i)}`,
	Dependencies: []*Function{Tag, Overlay},
}

ElementOverlay ...

View Source
var ElementR = &Function{
	Name:         "elementR",
	Definition:   `function(e,t){var n=t.match(/(\/?)(.+)\1([a-z]*)/i),i=n[3]&&!/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(n[3])?new RegExp(t):new RegExp(n[2],n[3]);const s=functions.selectable(this);e=Array.from(s.querySelectorAll(e)).find(e=>i.test(functions.text.call(e)));return e||null}`,
	Dependencies: []*Function{Selectable, Text},
}

ElementR ...

View Source
var ElementX = &Function{
	Name:         "elementX",
	Definition:   `function(e){var t=functions.selectable(this);return document.evaluate(e,t,null,XPathResult.FIRST_ORDERED_NODE_TYPE).singleNodeValue}`,
	Dependencies: []*Function{Selectable},
}

ElementX ...

View Source
var Elements = &Function{
	Name:         "elements",
	Definition:   `function(e){return functions.selectable(this).querySelectorAll(e)}`,
	Dependencies: []*Function{Selectable},
}

Elements ...

View Source
var ElementsX = &Function{
	Name:         "elementsX",
	Definition:   `function(e){var t,n=functions.selectable(this);const i=document.evaluate(e,n,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE),s=[];for(;t=i.iterateNext();)s.push(t);return s}`,
	Dependencies: []*Function{Selectable},
}

ElementsX ...

View Source
var ExposeFunc = &Function{
	Name:         "exposeFunc",
	Definition:   `function(e,t){let r=0;window[e]=e=>new Promise((n,i)=>{const s=t+"_cb"+r++;window[s]=(e,t)=>{delete window[s],t?i(t):n(e)},window[t](JSON.stringify({req:e,cb:s}))})}`,
	Dependencies: []*Function{},
}

ExposeFunc ...

View Source
var Functions = &Function{
	Name:         "functions",
	Definition:   "() => ({})",
	Dependencies: nil,
}

Functions ...

View Source
var InitMouseTracer = &Function{
	Name:         "initMouseTracer",
	Definition:   `async function(e,t){if(await functions.waitLoad(),!document.getElementById(e)){const n=document.createElement("div");n.innerHTML=t;const i=n.lastChild;i.id=e,i.style="position: absolute; z-index: 2147483647; width: 17px; pointer-events: none;",i.removeAttribute("width"),i.removeAttribute("height"),document.body.parentElement.appendChild(i)}}`,
	Dependencies: []*Function{WaitLoad},
}

InitMouseTracer ...

View Source
var InputEvent = &Function{
	Name:         "inputEvent",
	Definition:   `function(){this.dispatchEvent(new Event("input",{bubbles:!0})),this.dispatchEvent(new Event("change",{bubbles:!0}))}`,
	Dependencies: []*Function{},
}

InputEvent ...

View Source
var InputTime = &Function{
	Name:         "inputTime",
	Definition:   `function(e){const t=new Date(e);var e=e=>e.toString().padStart(2,"0"),n=t.getFullYear(),i=e(t.getMonth()+1),s=e(t.getDate()),r=e(t.getHours()),o=e(t.getMinutes());switch(this.type){case"date":this.value=n+` + "`" + `-${i}-` + "`" + `+s;break;case"datetime-local":this.value=n+` + "`" + `-${i}-${s}T${r}:` + "`" + `+o;break;case"month":this.value=i;break;case"time":this.value=r+":"+o}functions.inputEvent.call(this)}`,
	Dependencies: []*Function{InputEvent},
}

InputTime ...

View Source
var Invisible = &Function{
	Name:         "invisible",
	Definition:   `function(){return!functions.visible.apply(this)}`,
	Dependencies: []*Function{Visible},
}

Invisible ...

View Source
var Overlay = &Function{
	Name: "overlay",
	Definition: `async function(e,t,n,i,s,r){await functions.waitLoad();const o=document.createElement("div");if(o.id=e,o.style=` + "`" + `position: fixed; z-index:2147483647; border: 2px dashed red;
        border-radius: 3px; box-shadow: #5f3232 0 0 3px; pointer-events: none;
        box-sizing: border-box;
        left: ${t}px;
        top: ${n}px;
        height: ${s}px;
        width: ${i}px;` + "`" + `,i*s==0&&(o.style.border="none"),r){const l=document.createElement("div");l.style=` + "`" + `position: absolute; color: #cc26d6; font-size: 12px; background: #ffffffeb;
        box-shadow: #333 0 0 3px; padding: 2px 5px; border-radius: 3px; white-space: nowrap;
        top: ${s}px;` + "`" + `,l.innerHTML=r,o.appendChild(l),document.body.parentElement.appendChild(o),window.innerHeight<l.offsetHeight+n+s&&(l.style.top=-l.offsetHeight-2+"px"),window.innerWidth<l.offsetWidth+t&&(l.style.left=window.innerWidth-l.offsetWidth-t+"px")}else document.body.parentElement.appendChild(o)}`,
	Dependencies: []*Function{WaitLoad},
}

Overlay ...

View Source
var Parents = &Function{
	Name:         "parents",
	Definition:   `function(e){let t=this.parentElement;const n=[];for(;t;)t.matches(e)&&n.push(t),t=t.parentElement;return n}`,
	Dependencies: []*Function{},
}

Parents ...

View Source
var Rect = &Function{
	Name:         "rect",
	Definition:   `function(){var e=functions.tag(this).getBoundingClientRect();return{x:e.x,y:e.y,width:e.width,height:e.height}}`,
	Dependencies: []*Function{Tag},
}

Rect ...

View Source
var RemoveOverlay = &Function{
	Name:         "removeOverlay",
	Definition:   `function(e){e=document.getElementById(e);e&&Element.prototype.remove.call(e)}`,
	Dependencies: []*Function{},
}

RemoveOverlay ...

View Source
var Resource = &Function{
	Name:         "resource",
	Definition:   `function(){return new Promise((e,t)=>{if(this.complete)return e(this.currentSrc);this.addEventListener("load",()=>e(this.currentSrc)),this.addEventListener("error",e=>t(e))})}`,
	Dependencies: []*Function{},
}

Resource ...

View Source
var Select = &Function{
	Name:         "select",
	Definition:   `function(e,n,t){let i;switch(t){case"regex":i=e.map(e=>{const t=new RegExp(e);return e=>t.test(e.innerText)});break;case"css-selector":i=e.map(t=>e=>e.matches(t));break;default:i=e.map(t=>e=>e.innerText.includes(t))}const s=Array.from(this.options);let r=!1;return i.forEach(e=>{const t=s.find(e);t&&(t.selected=n,r=!0)}),this.dispatchEvent(new Event("input",{bubbles:!0})),this.dispatchEvent(new Event("change",{bubbles:!0})),r}`,
	Dependencies: []*Function{},
}

Select ...

View Source
var SelectAllText = &Function{
	Name:         "selectAllText",
	Definition:   `function(){this.select()}`,
	Dependencies: []*Function{},
}

SelectAllText ...

View Source
var SelectText = &Function{
	Name:         "selectText",
	Definition:   `function(e){e=this.value.match(new RegExp(e));e&&this.setSelectionRange(e.index,e.index+e[0].length)}`,
	Dependencies: []*Function{},
}

SelectText ...

View Source
var Selectable = &Function{
	Name:         "selectable",
	Definition:   `function(e){return e.querySelector?e:document}`,
	Dependencies: []*Function{},
}

Selectable ...

View Source
var Tag = &Function{
	Name:         "tag",
	Definition:   `function(e){return e.tagName?e:e.parentElement}`,
	Dependencies: []*Function{},
}

Tag ...

View Source
var Text = &Function{
	Name:         "text",
	Definition:   `function(){switch(this.tagName){case"INPUT":case"TEXTAREA":return this.value||this.placeholder;case"SELECT":return Array.from(this.selectedOptions).map(e=>e.innerText).join();case void 0:return this.textContent;default:return this.innerText}}`,
	Dependencies: []*Function{},
}

Text ...

View Source
var UpdateMouseTracer = &Function{
	Name:         "updateMouseTracer",
	Definition:   `function(e,t,n){const i=document.getElementById(e);return!!i&&(i.style.left=t-2+"px",i.style.top=n-3+"px",!0)}`,
	Dependencies: []*Function{},
}

UpdateMouseTracer ...

View Source
var Visible = &Function{
	Name:         "visible",
	Definition:   `function(){const e=functions.tag(this);var t=e.getBoundingClientRect(),n=window.getComputedStyle(e);return"none"!==n.display&&"hidden"!==n.visibility&&!!(t.top||t.bottom||t.width||t.height)}`,
	Dependencies: []*Function{Tag},
}

Visible ...

View Source
var WaitIdle = &Function{
	Name:         "waitIdle",
	Definition:   `function(t){return new Promise(e=>{window.requestIdleCallback(e,{timeout:t})})}`,
	Dependencies: []*Function{},
}

WaitIdle ...

View Source
var WaitLoad = &Function{
	Name:         "waitLoad",
	Definition:   `function(){const n=this===window;return new Promise((e,t)=>{if(n){if("complete"===document.readyState)return e();window.addEventListener("load",e)}else void 0===this.complete||this.complete?e():(this.addEventListener("load",e),this.addEventListener("error",t))})}`,
	Dependencies: []*Function{},
}

WaitLoad ...

Functions

This section is empty.

Types

type Function

type Function struct {
	// Name must be unique and not conflict with the function names in "helper.js"
	Name string

	// Definition holds the code of a js function from "helper.js",
	// the js code is compressed by uglify-js.
	Definition string

	// Dependencies will be preloaded and assigned to the global js object "functions"
	Dependencies []*Function
}

Function definition

Directories

Path Synopsis
Package main ...
Package main ...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL