chemicaljs
Advanced tools
Comparing version 1.7.2 to 1.7.3
@@ -7,12 +7,19 @@ class ChemicalInput extends HTMLInputElement { | ||
this.addEventListener("keydown", async function (e) { | ||
if (e.key == "Enter" && window.chemicalLoaded && e.target.value) { | ||
let encodedURL = await window.chemicalEncode(e.target.value) | ||
let action = this.getAttribute("action") | ||
let target = this.getAttribute("target") | ||
let frame = this.getAttribute("frame") | ||
if (e.key == "Enter" && window.chemical.loaded && e.target.value) { | ||
let service = this.dataset.service || "uv"; | ||
let autoHttps = this.dataset.autoHttps !== undefined ? true : false; | ||
let searchEngine = this.dataset.searchEngine; | ||
let action = this.dataset.action | ||
let target = this.dataset.target | ||
let frame = this.dataset.frame | ||
let encodedURL = await chemical.encode(e.target.value, { | ||
service, | ||
autoHttps, | ||
searchEngine | ||
}) | ||
if (frame) { | ||
let forFrame = document.getElementById(this.getAttribute("frame")) | ||
forFrame.src = encodedURL | ||
forFrame.setAttribute("open", "true") | ||
let forFrame = document.getElementById(frame) | ||
forFrame.src = encodedURL; | ||
forFrame.setAttribute("data-open", "true") | ||
} | ||
@@ -42,3 +49,3 @@ | ||
this.addEventListener("click", function (e) { | ||
let forInput = document.getElementById(this.getAttribute("for")) | ||
let forInput = document.getElementById(this.dataset.for) | ||
@@ -55,3 +62,3 @@ if (forInput) { | ||
class ChemicalIFrame extends HTMLIFrameElement { | ||
static observedAttributes = ["open"]; | ||
static observedAttributes = ["data-open"]; | ||
constructor() { | ||
@@ -61,14 +68,14 @@ super(); | ||
connectedCallback() { | ||
let open = this.getAttribute("open") | ||
let open = this.dataset.open | ||
this.style.display = open == "true" ? "" : "none" | ||
} | ||
attributeChangedCallback(name, oldValue, newValue) { | ||
if (name == "open") { | ||
let open = this.getAttribute("open") | ||
if (name == "data-open") { | ||
let open = this.dataset.open | ||
this.style.display = open == "true" ? "" : "none" | ||
let controls = document.getElementById(this.getAttribute("controls")) | ||
let controls = document.getElementById(this.dataset.controls) | ||
if (controls) { | ||
controls.setAttribute("open", open) | ||
controls.dataset.open = open | ||
} | ||
@@ -80,3 +87,3 @@ } | ||
class ChemicalControls extends HTMLElement { | ||
static observedAttributes = ["open"]; | ||
static observedAttributes = ["data-open"]; | ||
constructor() { | ||
@@ -86,8 +93,8 @@ super(); | ||
connectedCallback() { | ||
let open = this.getAttribute("open") | ||
let open = this.dataset.open | ||
this.style.display = open == "true" ? "" : "none" | ||
} | ||
attributeChangedCallback(name, oldValue, newValue) { | ||
if (name == "open") { | ||
let open = this.getAttribute("open") | ||
if (name == "data-open") { | ||
let open = this.dataset.open | ||
this.style.display = open == "true" ? "" : "none" | ||
@@ -103,12 +110,22 @@ } | ||
async connectedCallback() { | ||
let href = this.getAttribute("href"); | ||
this.removeAttribute("href"); | ||
let href = this.dataset.href; | ||
let service = this.dataset.service || "uv"; | ||
let autoHttps = this.dataset.autoHttps !== undefined ? true : false; | ||
let searchEngine = this.dataset.searchEngine; | ||
this.dataset.chemicalLoading = "true"; | ||
if (window.chemicalLoaded) { | ||
this.setAttribute("href", await chemicalEncode(href)) | ||
if (window.chemical.loaded) { | ||
this.setAttribute("href", await chemical.encode(href, { | ||
service, | ||
autoHttps, | ||
searchEngine | ||
})) | ||
this.dataset.chemicalLoading = "false"; | ||
} else { | ||
window.addEventListener("chemicalLoaded", async () => { | ||
this.setAttribute("href", await chemicalEncode(href)) | ||
this.setAttribute("href", await chemical.encode(href, { | ||
service, | ||
autoHttps, | ||
searchEngine | ||
})) | ||
this.dataset.chemicalLoading = "false"; | ||
@@ -141,3 +158,3 @@ }) | ||
case "close": | ||
frame.setAttribute("open", "false") | ||
frame.dataset.open = "false" | ||
frame.src = "" | ||
@@ -144,0 +161,0 @@ } |
@@ -231,2 +231,10 @@ window.chemical = { | ||
if (config.service == undefined) { | ||
config.service = defaultService; | ||
} | ||
if (config.autoHttps == undefined) { | ||
config.autoHttps = false; | ||
} | ||
if (url.match(/^https?:\/\//)) { | ||
@@ -233,0 +241,0 @@ return await encodeService(url, config.service); |
@@ -22,5 +22,5 @@ { | ||
"dependencies": { | ||
"chemicaljs": "^1.7.1", | ||
"chemicaljs": "^1.7.2", | ||
"express": "^4.19.2" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { ChemicalServer } from "chemicaljs"; | ||
import { ChemicalServer } from "../../index.js"; | ||
import express from "express"; | ||
@@ -3,0 +3,0 @@ |
@@ -21,5 +21,5 @@ { | ||
"dependencies": { | ||
"chemicaljs": "^1.7.1", | ||
"chemicaljs": "^1.7.2", | ||
"express": "^4.19.2" | ||
} | ||
} |
@@ -21,5 +21,5 @@ { | ||
"dependencies": { | ||
"chemicaljs": "^1.7.1", | ||
"chemicaljs": "^1.7.2", | ||
"express": "^4.19.2" | ||
} | ||
} |
@@ -11,3 +11,3 @@ { | ||
"dependencies": { | ||
"chemicaljs": "^1.7.1", | ||
"chemicaljs": "^1.7.2", | ||
"express": "^4.19.2", | ||
@@ -14,0 +14,0 @@ "preact": "^10.23.2" |
@@ -21,5 +21,5 @@ { | ||
"dependencies": { | ||
"chemicaljs": "^1.7.1", | ||
"chemicaljs": "^1.7.2", | ||
"express": "^4.19.2" | ||
} | ||
} |
{ | ||
"name": "chemicaljs", | ||
"version": "1.7.2", | ||
"version": "1.7.3", | ||
"description": "Easily create your own web proxy with no experience required.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -52,3 +52,3 @@ # Chemical | ||
```js | ||
chemical.get("/", function(req, res){ | ||
app.get("/", function(req, res){ | ||
res.send("Hello World"); | ||
@@ -298,5 +298,7 @@ }); | ||
```html | ||
<a href="https://example.com" is="chemical-link">Link</a> | ||
<a data-href="https://example.com" is="chemical-link">Link</a> | ||
``` | ||
You can also add `data-service="uv"`, `data-autoHttps`, and `data-search-engine="https://www.google.com/search?q=%s"` | ||
You can style the link as chemical is loading. | ||
@@ -315,15 +317,17 @@ | ||
```html | ||
<input target="_self" placeholder="Enter URL" is="chemical-input"> | ||
<input data-target="_self" placeholder="Enter URL" is="chemical-input"> | ||
``` | ||
You can also add `data-service="uv"`, `data-autoHttps`, and `data-search-engine="https://www.google.com/search?q=%s"` | ||
Opens in current tab when the enter key is pressed. | ||
```html | ||
<input target="_blank" placeholder="Enter URL" is="chemical-input"> | ||
<input data-target="_blank" placeholder="Enter URL" is="chemical-input"> | ||
``` | ||
Custom action when the enter key is pressed. Change `action` to your function name. The first parameter of the action will be the encoded URL. | ||
Custom action when the enter key is pressed. Change `data-action` to your function name. The first parameter of the action will be the encoded URL. | ||
```html | ||
<input action="logURL" placeholder="Enter URL" is="chemical-input"> | ||
<input data-action="logURL" placeholder="Enter URL" is="chemical-input"> | ||
<script> | ||
@@ -341,4 +345,4 @@ function logURL(url) { | ||
```html | ||
<input id="my-input" target="_blank" placeholder="Enter URL" is="chemical-input"> | ||
<button for="my-input" is="chemical-button">Go!</button> | ||
<input id="my-input" data-target="_blank" placeholder="Enter URL" is="chemical-input"> | ||
<button data-for="my-input" is="chemical-button">Go!</button> | ||
``` | ||
@@ -351,3 +355,3 @@ | ||
```html | ||
<input frame="my-iframe" placeholder="Enter URL" is="chemical-input"> | ||
<input data-frame="my-iframe" placeholder="Enter URL" is="chemical-input"> | ||
<iframe id="my-iframe" is="chemical-iframe"></iframe> | ||
@@ -364,3 +368,3 @@ ``` | ||
```html | ||
<input frame="my-iframe-2" placeholder="Enter URL" is="chemical-input"> | ||
<input data-frame="my-iframe-2" placeholder="Enter URL" is="chemical-input"> | ||
<section id="my-controls-2" is="chemical-controls"> | ||
@@ -372,3 +376,3 @@ <button onclick="chemicalAction('back', 'my-iframe-2')">←</button> | ||
</section> | ||
<iframe controls="my-controls-2" id="my-iframe-2" is="chemical-iframe"></iframe> | ||
<iframe data-controls="my-controls-2" id="my-iframe-2" is="chemical-iframe"></iframe> | ||
``` | ||
@@ -375,0 +379,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
375
621247
15236