Open xgqfrms opened 6 years ago
https://json5.org/ https://github.com/json5/json5
https://github.com/json5/json5#json5stringify
<!DOCTYPE html>
<html lang="zh-Hans">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="author" content="xgqfrms">
<meta name="generator" content="VS code">
<title>JSON5</title>
</head>
<body>
<section>
<h1>
<a href="https://feiqa.xgqfrms.xyz/index.html"></a>
</h1>
</section>
<!-- libs -->
<!-- <script src="https://unpkg.com/json5@^2.0.0/dist/index.min.js"></script> -->
<script src="./libs/json5.min.js"></script>
<script type="module">
// const JSON5 = require('json5');
import * as JSON5 from "./libs/json5.min.js";
// JSON5.stringify(value[, replacer[, space]]);
// JSON5.stringify(value[, options]);
</script>
</body>
</html>
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON
JSON5
https://developer.mozilla.org/en-US/docs/Web/Events/change
https://www.w3schools.com/tags/ev_onchange.asp
Set custom HTML5 required field validation message
https://github.com/xyz-data/RAIO/issues/176
https://html5demos.com/contenteditable/
https://www.w3schools.com/Tags/att_global_contenteditable.asp
http://html5doctor.com/the-contenteditable-attribute/
http://www.developerdrive.com/2012/06/allowing-users-to-edit-text-content-with-html5/
https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Editable_content
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/contenteditable
Ace
editor edit?editor.setReadOnly(true);
https://stackoverflow.com/questions/24757506/how-to-disable-in-ace-editor-the-selection
https://github.com/ajaxorg/ace/issues/406#issuecomment-425603533
https://cdn.xgqfrms.xyz/web-ide/ace.js
relative path & reference bug
importScripts('https://cdn.xgqfrms.xyz/web-ide/worker-javascript.js');
new instance & open Modal
API
https://ace.c9.io/#api=editor&nav=api
https://ace.c9.io/api/editor.html
editor.setValue(initial_value);
& editor.getValue();
& editor.setReadOnly(true);
let editor = ace.edit("editor");
// editor.setReadOnly(true);
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/javascript");
const ace_content = document.querySelector(`.ace_content`);
const ace_box = document.querySelector(`#editor`);
let initial_html = ``;
let initial_text = ``;
let initial_value = ``;
const showText = () => {
let text = ace_content.innerText;
console.log(`text =\n`, text);
};
let edit_btn = document.querySelector(`[data-btn="edit"]`),
save_btn = document.querySelector(`[data-btn="save"]`),
cancel_btn = document.querySelector(`[data-btn="cancel"]`);
edit_btn.addEventListener(`click`, () => {
editor.setReadOnly(false);
initial_html = ace_box.innerHTML;
// initial_html = ace_content.innerHTML;
initial_text = ace_content.innerText;
initial_value = editor.getValue();
// console.log(`initial_html =\n`, initial_html);
console.log(`initial_text =\n`, initial_text);
console.log(`initial_value =\n`, initial_value);
});
save_btn.addEventListener(`click`, () => {
// update data
initial_html = ace_box.innerHTML;
// initial_html = ace_content.innerHTML;
initial_text = ace_content.innerText;
initial_value = editor.getValue();
showText();
editor.setReadOnly(true);
});
cancel_btn.addEventListener(`click`, () => {
// ace_box.innerHTML = initial_html;
// ace_content.innerHTML = initial_html;
// ace_box.innerText = initial_text;
editor.setValue(initial_value);
// editor.setValue(initial_text);
// editor.undo();
editor.setReadOnly(true);
// editor.destroy();
});
<meta name="renderer" content="webkit">
<!DOCTYPE html>
<html lang="zh-Hans">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=3.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="renderer" content="webkit">
<meta name="author" content="xgqfrms">
<meta name="generator" content="VS code">
<title>ACE in Action</title>
<style type="text/css" media="screen">
#editor {
/* position: absolute; */
top: 0;
right: 0;
bottom: 0;
left: 0;
}
#editor {
width: 500px;
height: 300px;
}
</style>
</head>
<body>
<section>
<h1>
<a href="https://feiqa.xgqfrms.xyz/index.html"></a>
</h1>
</section>
</body>
</html>
https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent http://www.octodecillion.com/javascript-focus-event-has-wrong-target/
使用 Chrome Headless 模式将 HTML 转 PDF
https://stackoverflow.com/questions/43344819/reading-response-headers-with-fetch-api
https://www.yukei.net/2016/01/getting-response-headers-data-from-an-ajax-request-with-jquery/ https://stackoverflow.com/questions/1557602/jquery-and-ajax-response-header
xhr.getResponseHeader('Header')
https://www.cnblogs.com/xgqfrms/p/9724866.html
let url = `http://localhost:9000/api/render`,
obj = {
url: "https://developer.mozilla.org/en-US/docs/Web/CSS/calc",
output: "pdf",
// scrollPage: true,
// pdf: {
// landscape: true,
// },
// output: "screenshot",
ignoreHttpsErrors: true,
};
fetch(url,
{
method: "POST",
mode: "cors",
headers: {
"Content-Type": "application/json; charset=utf-8",
},
body: JSON.stringify(obj),
})
.then(res => {
let headers = res.headers;
headers.forEach(
(value, key) => {
console.log(`response header =`, `${key} = ${value}`);
// console.log(`response header =`, key, value);
}
);
// console.log(`response headers =`, headers);
return res.blob();
})
.then(blob => {
// base64
let objectURL = URL.createObjectURL(blob);
let a = document.createElement(`a`);
a.href = objectURL;
console.log(`a =`, a);
// let title = document.querySelector(`title`).innerText;
let title = `test`;
// png
// a.setAttribute(`download`, `${title}.png`);
// pdf
a.setAttribute(`download`, `${title}.pdf`);
a.click();
})
.catch((err) => {
console.log(`There has been a problem with your fetch operation: `, err);
});
https://github.com/alvarcarto/url-to-pdf-api#2-local-development
no header & no footer
https://stackoverflow.com/questions/46077392/additional-options-in-chrome-headless-print-to-pdf
@page {
margin: 0;
}
@page {
margin-top: 0;
}
@page {
margin-bottom: 0;
}
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir=D:\chrome
url = `http://localhost:9000/api/render`,
obj = {
url: "http://10.1.5.202/stock/f9/fastview/index.html",
output: "pdf",
scrollPage: true,
pdf: {
landscape: true,
},
emulateScreenMedia: true,
// output: "screenshot",
ignoreHttpsErrors: true,
};
fetch(url,
{
method: "POST",
mode: "cors",
headers: {
"Content-Type": "application/json; charset=utf-8",
},
body: JSON.stringify(obj),
})
.then(res => res.blob())
.then(blob => {
// base64
let objectURL = URL.createObjectURL(blob);
let a = document.createElement(`a`);
a.href = objectURL;
let title = `test`;
// png
// a.setAttribute(`download`, `${title}.png`);
// pdf
a.setAttribute(`download`, `${title}.pdf`);
a.click();
})
.catch((err) => {
console.log(`There has been a problem with your fetch operation: `, err);
});
https://github.com/GoogleChrome/puppeteer https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md
https://zhaoqize.github.io/puppeteer-api-zh_CN/#/
https://www.sitepen.com/blog/2017/10/04/browser-automation-with-puppeteer/
https://www.santoshsrinivas.com/puppeteer-api-to-control-headless-chrome/ https://puppet.com/docs/puppet/5.3/http_api/http_api_index.html
only out internet can be access & print pdf
https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md https://github.com/GoogleChrome/puppeteer/issues/1908
https://zhaoqize.github.io/puppeteer-api-zh_CN/#/ https://zhaoqize.github.io/puppeteer-api-zh_CN/#/class-Page
https://mydev.app/ https://github.com/umaar/puppeteer-sitepen-contact-example/blob/master/index.js
https://stackoverflow.com/questions/11503217/css-disable-header-footer-from-print-preview-chrome
https://stackoverflow.com/questions/44575628/alter-the-default-header-footer-when-printing-to-pdf
https://bugs.chromium.org/p/chromium/issues/detail?id=603559
highstock 十字准星线
tooltip: {
crosshairs:[
{
enabled:true,//是否显示X轴标线
width:3,//标线宽度
color:'red' //标线颜色值
},
{
enabled:true,//是否显示Y轴标线
width:3,//标线宽度
color:'green' //标线颜色值
}
],
style:{
display:'none' //通过样式表控制不显示tooltip数据提示框
}
},
window.parent.location.href;
window.parent.location.pathname;
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw
throw 'Error2'; // generates an exception with a string value
throw 42; // generates an exception with the value 42
throw true; // generates an exception with the value true
throw new Error('Required'); // generates an error object with the message of Required
http://www.javascriptkit.com/javatutors/trycatch2.shtml https://humanwhocodes.com/blog/2009/03/10/the-art-of-throwing-javascript-errors-part-2/
js json string to object
https://stackoverflow.com/questions/9036429/convert-object-string-to-json
https://stackoverflow.com/questions/45015/safely-turning-a-json-string-into-an-object