mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-14 11:21:18 +00:00
The bundled pages took two facts from the User-Agent header: whether the app
is in dark mode ("dark") and whether they run inside OrcaSlicer at all
("BBL-Slicer", the gate on every message they post to the host). That made
the header carry application state. #15104 switched Linux to WebKitGTK's own
header so that Cloudflare accepts third-party print-host pages, and with it
the home page came up light on a dark app and New Project, Open Project, the
Project tab, the wizard and the web dialogs stopped reaching the host.
The host now tells each page its theme through a document-start user script
(window.__orcaTheme), added when the view is created, again on a theme change
before the reload, and after PrinterWebView clears its user scripts. The page
tests for the injected window.wx bridge instead of the header, which is what
the plugin pages already do. Nothing reads the header any more, so Linux
keeps sending WebKitGTK's own on every view. Windows and macOS keep the
headers they always sent: the Windows wrapper still derives WebView2's colour
scheme from it.
Four copies of the helper file lived next to the pages that used them
(homepage/js, guide/js, dialog/js, include), differing only in the relative
path each one passed to its dark.css toggle. The toggle now switches whichever
dark.css the page already links, so the one copy in include/ serves all 17
pages and the other three are gone. That file was stored with CRLF and is
normalised to LF, which is most of its diff.
374 lines
7.8 KiB
JavaScript
374 lines
7.8 KiB
JavaScript
|
|
/*------------------ Date Function ------------------------*/
|
|
function GetFullToday( )
|
|
{
|
|
var d=new Date();
|
|
|
|
var nday=d.getDate();
|
|
var nmonth=d.getMonth()+1;
|
|
var nyear=d.getFullYear();
|
|
|
|
var strM=nmonth+'';
|
|
if( nmonth<10 )
|
|
strM='0'+nmonth;
|
|
|
|
var strD=nday+'';
|
|
if( nday<10 )
|
|
strD='0'+nday;
|
|
|
|
return nyear+'-'+strM+'-'+strD;
|
|
}
|
|
|
|
function GetFullDate()
|
|
{
|
|
var d=new Date();
|
|
|
|
var tDate={};
|
|
|
|
tDate.nyear=d.getFullYear();
|
|
tDate.nmonth=d.getMonth()+1;
|
|
tDate.nday=d.getDate();
|
|
|
|
tDate.nhour=d.getHours();
|
|
tDate.nminute=d.getMinutes();
|
|
tDate.nsecond=d.getSeconds();
|
|
|
|
tDate.nweek=d.getDay();
|
|
tDate.ndate=d.getDate();
|
|
|
|
var strM=tDate.nmonth+'';
|
|
if( tDate.nmonth<10 )
|
|
strM='0'+tDate.nmonth;
|
|
|
|
var strD=tDate.nday+'';
|
|
if( tDate.nday<10 )
|
|
strD='0'+tDate.nday;
|
|
|
|
var strH=tDate.nhour+'';
|
|
if( tDate.nhour<10 )
|
|
strH='0'+tDate.nhour;
|
|
|
|
var strMin=tDate.nminute+'';
|
|
if( tDate.nminute<10 )
|
|
strMin='0'+tDate.nminute;
|
|
|
|
var strS=tDate.nsecond+'';
|
|
if( tDate.nsecond<10 )
|
|
strS='0'+tDate.nsecond;
|
|
|
|
tDate.strdate=tDate.nyear+'-'+strM+'-'+strD;
|
|
tDate.strFulldate=tDate.strdate+' '+strH+':'+strMin+':'+strS;
|
|
|
|
return tDate;
|
|
}
|
|
|
|
|
|
function Unixtimestamp2Date( nSecond )
|
|
{
|
|
var d=new Date(nSecond*1000);
|
|
|
|
var tDate={};
|
|
|
|
tDate.nyear=d.getFullYear();
|
|
tDate.nmonth=d.getMonth()+1;
|
|
tDate.nday=d.getDate();
|
|
|
|
tDate.nhour=d.getHours();
|
|
tDate.nminute=d.getMinutes();
|
|
tDate.nsecond=d.getSeconds();
|
|
|
|
tDate.nweek=d.getDay();
|
|
tDate.ndate=d.getDate();
|
|
|
|
var strM=tDate.nmonth+'';
|
|
if( tDate.nmonth<10 )
|
|
strM='0'+tDate.nmonth;
|
|
|
|
var strD=tDate.nday+'';
|
|
if( tDate.nday<10 )
|
|
strD='0'+tDate.nday;
|
|
|
|
tDate.strdate=tDate.nyear+'-'+strM+'-'+strD;
|
|
|
|
return tDate.strdate;
|
|
}
|
|
|
|
|
|
//------------Array Function-------------
|
|
Array.prototype.in_array = function (e) {
|
|
let sArray= ',' + this.join(this.S) + ',';
|
|
let skey=','+e+',';
|
|
|
|
if(sArray.indexOf(skey)>=0)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
|
|
|
|
//------------String Function------------------
|
|
/**
|
|
* Delete Left/Right Side Blank
|
|
*/
|
|
String.prototype.trim=function()
|
|
{
|
|
return this.replace(/(^\s*)|(\s*$)/g, '');
|
|
}
|
|
/**
|
|
* Delete Left Side Blank
|
|
*/
|
|
String.prototype.ltrim=function()
|
|
{
|
|
return this.replace(/(^\s*)/g,'');
|
|
}
|
|
/**
|
|
* Delete Right Side Blank
|
|
*/
|
|
String.prototype.rtrim=function()
|
|
{
|
|
return this.replace(/(\s*$)/g,'');
|
|
}
|
|
|
|
|
|
//----------------Get Param-------------
|
|
function GetQueryString(name)
|
|
{
|
|
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
|
|
var r = window.location.search.substr(1).match(reg);
|
|
if (r!=null)
|
|
{
|
|
return unescape(r[2]);
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function GetGetStr()
|
|
{
|
|
let strGet="";
|
|
|
|
//获取当前URL
|
|
let url = document.location.href;
|
|
|
|
//获取?的位置
|
|
let index = url.indexOf("?")
|
|
if(index != -1) {
|
|
//截取出?后面的字符串
|
|
strGet = url.substr(index + 1);
|
|
}
|
|
|
|
return strGet;
|
|
}
|
|
|
|
/*--------------File Function--------------*/
|
|
function getFileName(path)
|
|
{
|
|
var pos1 = path.lastIndexOf('/');
|
|
var pos2 = path.lastIndexOf('\\');
|
|
var pos = Math.max(pos1, pos2);
|
|
if (pos < 0) {
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
return path.substring(pos + 1);
|
|
}
|
|
}
|
|
|
|
function getFileTail(path)
|
|
{
|
|
var pos = path.lastIndexOf('.');
|
|
if (pos < 0) {
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
return path.substring(pos + 1);
|
|
}
|
|
}
|
|
|
|
/*--------------String Function-----------*/
|
|
function html_encode(str)
|
|
{
|
|
var s = "";
|
|
if (str.length == 0) return "";
|
|
s = str.replace(/&/g, "&");
|
|
s = s.replace(/</g, "<");
|
|
s = s.replace(/>/g, ">");
|
|
s = s.replace(/ /g, " ");
|
|
s = s.replace(/\'/g, "'");
|
|
s = s.replace(/\"/g, """);
|
|
s = s.replace(/\n/g, "<br/>");
|
|
|
|
return s;
|
|
}
|
|
|
|
function html_decode(str)
|
|
{
|
|
var s = "";
|
|
if (str.length == 0) return "";
|
|
s = str.replace(/&/g, "&");
|
|
s = s.replace(/</g, "<");
|
|
s = s.replace(/>/g, ">");
|
|
s = s.replace(/ /g, " ");
|
|
s = s.replace(/'/g, "\'");
|
|
s = s.replace(/"/g, "\"");
|
|
s = s.replace(/<br\/>/g, "\n");
|
|
|
|
return s;
|
|
}
|
|
|
|
/*--------------------JSON Function------------*/
|
|
|
|
/*
|
|
功能:检查一个字符串是不是标准的JSON格式
|
|
参数: strJson 被检查的字符串
|
|
返回值: 如果字符串是一个标准的JSON格式,则返回JSON对象
|
|
如果字符串不是标准JSON格式,则返回null
|
|
*/
|
|
function IsJson( strJson )
|
|
{
|
|
var tJson=null;
|
|
try
|
|
{
|
|
tJson=JSON.parse(strJson);
|
|
}
|
|
catch(exception)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return tJson;
|
|
}
|
|
|
|
function DecodeJsonObject( pJson )
|
|
{
|
|
let tmpJson=JSON.stringify(pJson);
|
|
tmpJson=decodeURIComponent(tmpJson);
|
|
|
|
pJson=JSON.parse(tmpJson);
|
|
|
|
return pJson;
|
|
}
|
|
|
|
/*-----------------------Ajax Function--------------------*/
|
|
/*对JQuery的Ajax函数的封装,只支持异步
|
|
参数说明:
|
|
url 目标地址
|
|
action post/get
|
|
data 字符串格式的发送内容
|
|
asyn true---异步模式;false-----同步模式;
|
|
*/
|
|
function HttpReq( url,action, data,callbackfunc)
|
|
{
|
|
var strAction=action.toLowerCase();
|
|
|
|
if( strAction=="post")
|
|
{
|
|
$.post(url,data,callbackfunc);
|
|
}
|
|
else if( strAction=="get")
|
|
{
|
|
$.get(url,callbackfunc);
|
|
}
|
|
}
|
|
|
|
/*---------------Cookie Function-------------------*/
|
|
function setCookie(name, value, time='',path='') {
|
|
if(time && path){
|
|
var strsec = time * 1000;
|
|
var exp = new Date();
|
|
exp.setTime(exp.getTime() + strsec * 1);
|
|
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path="+path;
|
|
}else if(time){
|
|
var strsec = time * 1000;
|
|
var exp = new Date();
|
|
exp.setTime(exp.getTime() + strsec * 1);
|
|
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
|
|
}else if(path){
|
|
document.cookie = name + "=" + escape(value) + ";path="+path;
|
|
}else{
|
|
document.cookie = name + "=" + escape(value);
|
|
}
|
|
}
|
|
|
|
function getCookie(c_name)
|
|
{
|
|
if(document.cookie.length > 0) {
|
|
c_start = document.cookie.indexOf(c_name + "=");//获取字符串的起点
|
|
if(c_start != -1) {
|
|
c_start = c_start + c_name.length + 1;//获取值的起点
|
|
c_end = document.cookie.indexOf(";", c_start);//获取结尾处
|
|
if(c_end == -1) c_end = document.cookie.length;//如果是最后一个,结尾就是cookie字符串的结尾
|
|
return decodeURI(document.cookie.substring(c_start, c_end));//截取字符串返回
|
|
}
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
function checkCookie(c_name) {
|
|
username = getCookie(c_name);
|
|
console.log(username);
|
|
if (username != null && username != "")
|
|
{ return true; }
|
|
else
|
|
{ return false; }
|
|
}
|
|
|
|
function clearCookie(name) {
|
|
setCookie(name, "", -1);
|
|
}
|
|
|
|
|
|
/*--------Studio WX Message-------*/
|
|
function IsInSlicer()
|
|
{
|
|
// window.wx is the host's message handler, registered on every webview OrcaSlicer creates.
|
|
return !!(window.wx && window.wx.postMessage);
|
|
}
|
|
|
|
|
|
|
|
function SendWXMessage( strMsg )
|
|
{
|
|
if( IsInSlicer() )
|
|
window.wx.postMessage(strMsg);
|
|
}
|
|
|
|
function SendWXDebugInfo( strMsg )
|
|
{
|
|
var tSend={};
|
|
tSend['sequence_id']=Math.round(new Date() / 1000);
|
|
tSend['command']="debug_info";
|
|
tSend['msg']=strMsg;
|
|
|
|
SendWXMessage( JSON.stringify(tSend) );
|
|
}
|
|
|
|
function OpenUrlInLocalBrowser( strUrl )
|
|
{
|
|
var tSend={};
|
|
tSend['sequence_id']=Math.round(new Date() / 1000);
|
|
tSend['command']="common_openurl";
|
|
tSend['url']=strUrl;
|
|
|
|
SendWXMessage( JSON.stringify(tSend) );
|
|
}
|
|
|
|
|
|
/*------Dark Mode------*/
|
|
// The host sets window.__orcaTheme at document start (WebView::AddHostThemeScript) and reloads the
|
|
// page when the theme changes. Every legacy page links its dark.css up front; it is switched on and
|
|
// off here instead of being added and removed, so the page's own path to it does not matter.
|
|
function ExecuteDarkMode()
|
|
{
|
|
let bDarkMode = window.__orcaTheme === "dark";
|
|
document.querySelectorAll('head link[href$="dark.css"]').forEach( function(link) { link.disabled = !bDarkMode; } );
|
|
}
|
|
|
|
ExecuteDarkMode();
|