Compare commits

...
Author SHA1 Message Date
Hanif Koh 229460595f Give the Legacy Web Pages Their Theme and Host Bridge Without the User-Agent
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.
2026-10-14 15:51:00 +08:00
21 changed files with 426 additions and 1468 deletions

No files matched your search

@@ -11,7 +11,7 @@
<script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script> <script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../js/json2.js"></script> <script type="text/javascript" src="../js/json2.js"></script>
<script type="text/javascript" src="../../include/i18n.js"></script> <script type="text/javascript" src="../../include/i18n.js"></script>
<script type="text/javascript" src="../js/globalapi.js"></script> <script type="text/javascript" src="../../include/globalapi.js"></script>
<script type="text/javascript" src="../js/common.js"></script> <script type="text/javascript" src="../js/common.js"></script>
<script src="./index.js"></script> <script src="./index.js"></script>
</head> </head>
@@ -13,7 +13,7 @@
<script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script> <script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../js/json2.js"></script> <script type="text/javascript" src="../js/json2.js"></script>
<script type="text/javascript" src="../../include/i18n.js"></script> <script type="text/javascript" src="../../include/i18n.js"></script>
<script type="text/javascript" src="../js/globalapi.js"></script> <script type="text/javascript" src="../../include/globalapi.js"></script>
<script type="text/javascript" src="../js/common.js"></script> <script type="text/javascript" src="../js/common.js"></script>
<script src="../js/plugin-config-ui.js"></script> <script src="../js/plugin-config-ui.js"></script>
<script src="./index.js"></script> <script src="./index.js"></script>
@@ -12,7 +12,7 @@
<script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script> <script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../js/json2.js"></script> <script type="text/javascript" src="../js/json2.js"></script>
<script type="text/javascript" src="../../include/i18n.js"></script> <script type="text/javascript" src="../../include/i18n.js"></script>
<script type="text/javascript" src="../js/globalapi.js"></script> <script type="text/javascript" src="../../include/globalapi.js"></script>
<script type="text/javascript" src="../js/common.js"></script> <script type="text/javascript" src="../js/common.js"></script>
<!-- <script type="text/javascript" src="./23.js"></script> --> <!-- <script type="text/javascript" src="./23.js"></script> -->
<script src="./index.js"></script> <script src="./index.js"></script>
@@ -12,7 +12,7 @@
<script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script> <script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../js/json2.js"></script> <script type="text/javascript" src="../js/json2.js"></script>
<script type="text/javascript" src="../../include/i18n.js"></script> <script type="text/javascript" src="../../include/i18n.js"></script>
<script type="text/javascript" src="../js/globalapi.js"></script> <script type="text/javascript" src="../../include/globalapi.js"></script>
<script type="text/javascript" src="../../include/xterm/xterm.js"></script> <script type="text/javascript" src="../../include/xterm/xterm.js"></script>
<script type="text/javascript" src="../../include/xterm/xterm-addon-fit.js"></script> <script type="text/javascript" src="../../include/xterm/xterm-addon-fit.js"></script>
<script src="./index.js"></script> <script src="./index.js"></script>
-339
View File
@@ -1,339 +0,0 @@
/*------------------ 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;
}
/*--------------------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;
}
/*-----------------------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()
{
let bMatch=navigator.userAgent.match( RegExp('BBL-Slicer','i') );
return bMatch;
}
function SendWXMessage( strMsg )
{
let bCheck=IsInSlicer();
if(bCheck!=null)
{
window.wx.postMessage(strMsg);
}
}
/*------CSS Link Control----*/
function RemoveCssLink( LinkPath )
{
let pNow=$("head link[href='"+LinkPath+"']");
let nTotal=pNow.length;
for( let n=0;n<nTotal;n++ )
{
pNow[n].remove();
}
}
function AddCssLink( LinkPath )
{
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.href = LinkPath;
link.rel = 'stylesheet';
link.type = 'text/css';
head.appendChild(link);
}
function CheckCssLinkExist( LinkPath )
{
let pNow=$("head link[href='"+LinkPath+"']");
let nTotal=pNow.length;
return nTotal;
}
/*------Dark Mode------*/
function SwitchDarkMode( DarkCssPath )
{
ExecuteDarkMode( DarkCssPath );
setInterval("ExecuteDarkMode('"+DarkCssPath+"')",1000);
}
function ExecuteDarkMode( DarkCssPath )
{
let nMode=0;
let bDarkMode=navigator.userAgent.match( RegExp('dark','i') );
if( bDarkMode!=null )
nMode=1;
let nNow=CheckCssLinkExist(DarkCssPath);
if( nMode==0 )
{
if(nNow>0)
RemoveCssLink(DarkCssPath);
}
else
{
if(nNow==0)
AddCssLink(DarkCssPath);
}
}
// Dialog pages are themed by the injected --orca-* contract + theme.css; the legacy dark.css poll is fully retired.
+1 -1
View File
@@ -10,7 +10,7 @@
<script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script> <script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../js/json2.js"></script> <script type="text/javascript" src="../js/json2.js"></script>
<script type="text/javascript" src="../../include/i18n.js"></script> <script type="text/javascript" src="../../include/i18n.js"></script>
<script type="text/javascript" src="../js/globalapi.js"></script> <script type="text/javascript" src="../../include/globalapi.js"></script>
<script type="text/javascript" src="../js/common.js"></script> <script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="load.js"></script> <script type="text/javascript" src="load.js"></script>
</head> </head>
+1 -1
View File
@@ -10,7 +10,7 @@
<link rel="stylesheet" type="text/css" href="1.css" /> <link rel="stylesheet" type="text/css" href="1.css" />
<script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script> <script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../../include/i18n.js"></script> <script type="text/javascript" src="../../include/i18n.js"></script>
<script type="text/javascript" src="../js/globalapi.js"></script> <script type="text/javascript" src="../../include/globalapi.js"></script>
<script type="text/javascript" src="../js/common.js"></script> <script type="text/javascript" src="../js/common.js"></script>
</head> </head>
<body onLoad="TranslatePage()"> <body onLoad="TranslatePage()">
+1 -1
View File
@@ -11,7 +11,7 @@
<script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script> <script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../js/json2.js"></script> <script type="text/javascript" src="../js/json2.js"></script>
<script type="text/javascript" src="../../include/i18n.js"></script> <script type="text/javascript" src="../../include/i18n.js"></script>
<script type="text/javascript" src="../js/globalapi.js"></script> <script type="text/javascript" src="../../include/globalapi.js"></script>
<script type="text/javascript" src="../js/common.js"></script> <script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="11.js"></script> <script type="text/javascript" src="11.js"></script>
</head> </head>
+1 -1
View File
@@ -13,7 +13,7 @@
<script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script> <script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../js/json2.js"></script> <script type="text/javascript" src="../js/json2.js"></script>
<script type="text/javascript" src="../../include/i18n.js"></script> <script type="text/javascript" src="../../include/i18n.js"></script>
<script type="text/javascript" src="../js/globalapi.js"></script> <script type="text/javascript" src="../../include/globalapi.js"></script>
<script type="text/javascript" src="../js/common.js"></script> <script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../21/common.js"></script> <!-- ORCA use common sources for setup guide and standalone dialog --> <script type="text/javascript" src="../21/common.js"></script> <!-- ORCA use common sources for setup guide and standalone dialog -->
<script type="text/javascript" src="21.js"></script> <script type="text/javascript" src="21.js"></script>
+1 -1
View File
@@ -13,7 +13,7 @@
<script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script> <script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../js/json2.js"></script> <script type="text/javascript" src="../js/json2.js"></script>
<script type="text/javascript" src="../../include/i18n.js"></script> <script type="text/javascript" src="../../include/i18n.js"></script>
<script type="text/javascript" src="../js/globalapi.js"></script> <script type="text/javascript" src="../../include/globalapi.js"></script>
<script type="text/javascript" src="../js/common.js"></script> <script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../22/common.js"></script> <!-- ORCA use common sources for setup guide and standalone dialog --> <script type="text/javascript" src="../22/common.js"></script> <!-- ORCA use common sources for setup guide and standalone dialog -->
<script type="text/javascript" src="./22.js"></script> <script type="text/javascript" src="./22.js"></script>
+1 -1
View File
@@ -12,7 +12,7 @@
<script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script> <script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../js/json2.js"></script> <script type="text/javascript" src="../js/json2.js"></script>
<script type="text/javascript" src="../../include/i18n.js"></script> <script type="text/javascript" src="../../include/i18n.js"></script>
<script type="text/javascript" src="../js/globalapi.js"></script> <script type="text/javascript" src="../../include/globalapi.js"></script>
<script type="text/javascript" src="../js/common.js"></script> <script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../22/common.js"></script> <!-- ORCA use common sources for setup guide and standalone dialog --> <script type="text/javascript" src="../22/common.js"></script> <!-- ORCA use common sources for setup guide and standalone dialog -->
<script type="text/javascript" src="./23.js"></script> <script type="text/javascript" src="./23.js"></script>
+1 -1
View File
@@ -13,7 +13,7 @@
<script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script> <script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../js/json2.js"></script> <script type="text/javascript" src="../js/json2.js"></script>
<script type="text/javascript" src="../../include/i18n.js"></script> <script type="text/javascript" src="../../include/i18n.js"></script>
<script type="text/javascript" src="../js/globalapi.js"></script> <script type="text/javascript" src="../../include/globalapi.js"></script>
<script type="text/javascript" src="../js/common.js"></script> <script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../21/common.js"></script> <!-- ORCA use common sources for setup guide and standalone dialog --> <script type="text/javascript" src="../21/common.js"></script> <!-- ORCA use common sources for setup guide and standalone dialog -->
<script type="text/javascript" src="24.js"></script> <script type="text/javascript" src="24.js"></script>
+1 -1
View File
@@ -11,7 +11,7 @@
<script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script> <script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../js/json2.js"></script> <script type="text/javascript" src="../js/json2.js"></script>
<script type="text/javascript" src="../../include/i18n.js"></script> <script type="text/javascript" src="../../include/i18n.js"></script>
<script type="text/javascript" src="../js/globalapi.js"></script> <script type="text/javascript" src="../../include/globalapi.js"></script>
<script type="text/javascript" src="../js/common.js"></script> <script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="4orca.js"></script> <script type="text/javascript" src="4orca.js"></script>
</head> </head>
+1 -1
View File
@@ -11,7 +11,7 @@
<script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script> <script type="text/javascript" src="../../include/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../js/json2.js"></script> <script type="text/javascript" src="../js/json2.js"></script>
<script type="text/javascript" src="../../include/i18n.js"></script> <script type="text/javascript" src="../../include/i18n.js"></script>
<script type="text/javascript" src="../js/globalapi.js"></script> <script type="text/javascript" src="../../include/globalapi.js"></script>
<script type="text/javascript" src="../js/common.js"></script> <script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="5.js"></script> <script type="text/javascript" src="5.js"></script>
</head> </head>
-339
View File
@@ -1,339 +0,0 @@
/*------------------ 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;
}
/*--------------------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;
}
/*-----------------------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()
{
let bMatch=navigator.userAgent.match( RegExp('BBL-Slicer','i') );
return bMatch;
}
function SendWXMessage( strMsg )
{
let bCheck=IsInSlicer();
if(bCheck!=null)
{
window.wx.postMessage(strMsg);
}
}
/*------CSS Link Control----*/
function RemoveCssLink( LinkPath )
{
let pNow=$("head link[href='"+LinkPath+"']");
let nTotal=pNow.length;
for( let n=0;n<nTotal;n++ )
{
pNow[n].remove();
}
}
function AddCssLink( LinkPath )
{
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.href = LinkPath;
link.rel = 'stylesheet';
link.type = 'text/css';
head.appendChild(link);
}
function CheckCssLinkExist( LinkPath )
{
let pNow=$("head link[href='"+LinkPath+"']");
let nTotal=pNow.length;
return nTotal;
}
/*------Dark Mode------*/
function SwitchDarkMode( DarkCssPath )
{
ExecuteDarkMode( DarkCssPath );
setInterval("ExecuteDarkMode('"+DarkCssPath+"')",1000);
}
function ExecuteDarkMode( DarkCssPath )
{
let nMode=0;
let bDarkMode=navigator.userAgent.match( RegExp('dark','i') );
if( bDarkMode!=null )
nMode=1;
let nNow=CheckCssLinkExist(DarkCssPath);
if( nMode==0 )
{
if(nNow>0)
RemoveCssLink(DarkCssPath);
}
else
{
if(nNow==0)
AddCssLink(DarkCssPath);
}
}
SwitchDarkMode( "../css/dark.css" );
-340
View File
@@ -1,340 +0,0 @@
/*------------------ 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;
}
/*--------------------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;
}
/*-----------------------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()
{
let bMatch=navigator.userAgent.match( RegExp('BBL-Slicer','i') );
return bMatch;
}
function SendWXMessage( strMsg )
{
let bCheck=IsInSlicer();
if(bCheck!=null)
{
window.wx.postMessage(strMsg);
}
}
/*------CSS Link Control----*/
function RemoveCssLink( LinkPath )
{
let pNow=$("head link[href='"+LinkPath+"']");
let nTotal=pNow.length;
for( let n=0;n<nTotal;n++ )
{
pNow[n].remove();
}
}
function AddCssLink( LinkPath )
{
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.href = LinkPath;
link.rel = 'stylesheet';
link.type = 'text/css';
head.appendChild(link);
}
function CheckCssLinkExist( LinkPath )
{
let pNow=$("head link[href='"+LinkPath+"']");
let nTotal=pNow.length;
return nTotal;
}
/*------Dark Mode------*/
function SwitchDarkMode( DarkCssPath )
{
ExecuteDarkMode( DarkCssPath );
setInterval("ExecuteDarkMode('"+DarkCssPath+"')",1000);
}
function ExecuteDarkMode( DarkCssPath )
{
let nMode=0;
let bDarkMode=navigator.userAgent.match( RegExp('dark','i') );
if( bDarkMode!=null )
nMode=1;
let nNow=CheckCssLinkExist(DarkCssPath);
if( nMode==0 )
{
if(nNow>0)
RemoveCssLink(DarkCssPath);
}
else
{
if(nNow==0)
AddCssLink(DarkCssPath);
}
}
SwitchDarkMode("css/dark.css");
+373 -427
View File
@@ -1,427 +1,373 @@
/*------------------ Date Function ------------------------*/ /*------------------ Date Function ------------------------*/
function GetFullToday( ) function GetFullToday( )
{ {
var d=new Date(); var d=new Date();
var nday=d.getDate(); var nday=d.getDate();
var nmonth=d.getMonth()+1; var nmonth=d.getMonth()+1;
var nyear=d.getFullYear(); var nyear=d.getFullYear();
var strM=nmonth+''; var strM=nmonth+'';
if( nmonth<10 ) if( nmonth<10 )
strM='0'+nmonth; strM='0'+nmonth;
var strD=nday+''; var strD=nday+'';
if( nday<10 ) if( nday<10 )
strD='0'+nday; strD='0'+nday;
return nyear+'-'+strM+'-'+strD; return nyear+'-'+strM+'-'+strD;
} }
function GetFullDate() function GetFullDate()
{ {
var d=new Date(); var d=new Date();
var tDate={}; var tDate={};
tDate.nyear=d.getFullYear(); tDate.nyear=d.getFullYear();
tDate.nmonth=d.getMonth()+1; tDate.nmonth=d.getMonth()+1;
tDate.nday=d.getDate(); tDate.nday=d.getDate();
tDate.nhour=d.getHours(); tDate.nhour=d.getHours();
tDate.nminute=d.getMinutes(); tDate.nminute=d.getMinutes();
tDate.nsecond=d.getSeconds(); tDate.nsecond=d.getSeconds();
tDate.nweek=d.getDay(); tDate.nweek=d.getDay();
tDate.ndate=d.getDate(); tDate.ndate=d.getDate();
var strM=tDate.nmonth+''; var strM=tDate.nmonth+'';
if( tDate.nmonth<10 ) if( tDate.nmonth<10 )
strM='0'+tDate.nmonth; strM='0'+tDate.nmonth;
var strD=tDate.nday+''; var strD=tDate.nday+'';
if( tDate.nday<10 ) if( tDate.nday<10 )
strD='0'+tDate.nday; strD='0'+tDate.nday;
var strH=tDate.nhour+''; var strH=tDate.nhour+'';
if( tDate.nhour<10 ) if( tDate.nhour<10 )
strH='0'+tDate.nhour; strH='0'+tDate.nhour;
var strMin=tDate.nminute+''; var strMin=tDate.nminute+'';
if( tDate.nminute<10 ) if( tDate.nminute<10 )
strMin='0'+tDate.nminute; strMin='0'+tDate.nminute;
var strS=tDate.nsecond+''; var strS=tDate.nsecond+'';
if( tDate.nsecond<10 ) if( tDate.nsecond<10 )
strS='0'+tDate.nsecond; strS='0'+tDate.nsecond;
tDate.strdate=tDate.nyear+'-'+strM+'-'+strD; tDate.strdate=tDate.nyear+'-'+strM+'-'+strD;
tDate.strFulldate=tDate.strdate+' '+strH+':'+strMin+':'+strS; tDate.strFulldate=tDate.strdate+' '+strH+':'+strMin+':'+strS;
return tDate; return tDate;
} }
function Unixtimestamp2Date( nSecond ) function Unixtimestamp2Date( nSecond )
{ {
var d=new Date(nSecond*1000); var d=new Date(nSecond*1000);
var tDate={}; var tDate={};
tDate.nyear=d.getFullYear(); tDate.nyear=d.getFullYear();
tDate.nmonth=d.getMonth()+1; tDate.nmonth=d.getMonth()+1;
tDate.nday=d.getDate(); tDate.nday=d.getDate();
tDate.nhour=d.getHours(); tDate.nhour=d.getHours();
tDate.nminute=d.getMinutes(); tDate.nminute=d.getMinutes();
tDate.nsecond=d.getSeconds(); tDate.nsecond=d.getSeconds();
tDate.nweek=d.getDay(); tDate.nweek=d.getDay();
tDate.ndate=d.getDate(); tDate.ndate=d.getDate();
var strM=tDate.nmonth+''; var strM=tDate.nmonth+'';
if( tDate.nmonth<10 ) if( tDate.nmonth<10 )
strM='0'+tDate.nmonth; strM='0'+tDate.nmonth;
var strD=tDate.nday+''; var strD=tDate.nday+'';
if( tDate.nday<10 ) if( tDate.nday<10 )
strD='0'+tDate.nday; strD='0'+tDate.nday;
tDate.strdate=tDate.nyear+'-'+strM+'-'+strD; tDate.strdate=tDate.nyear+'-'+strM+'-'+strD;
return tDate.strdate; return tDate.strdate;
} }
//------------Array Function------------- //------------Array Function-------------
Array.prototype.in_array = function (e) { Array.prototype.in_array = function (e) {
let sArray= ',' + this.join(this.S) + ','; let sArray= ',' + this.join(this.S) + ',';
let skey=','+e+','; let skey=','+e+',';
if(sArray.indexOf(skey)>=0) if(sArray.indexOf(skey)>=0)
return true; return true;
else else
return false; return false;
} }
//------------String Function------------------ //------------String Function------------------
/** /**
* Delete Left/Right Side Blank * Delete Left/Right Side Blank
*/ */
String.prototype.trim=function() String.prototype.trim=function()
{ {
return this.replace(/(^\s*)|(\s*$)/g, ''); return this.replace(/(^\s*)|(\s*$)/g, '');
} }
/** /**
* Delete Left Side Blank * Delete Left Side Blank
*/ */
String.prototype.ltrim=function() String.prototype.ltrim=function()
{ {
return this.replace(/(^\s*)/g,''); return this.replace(/(^\s*)/g,'');
} }
/** /**
* Delete Right Side Blank * Delete Right Side Blank
*/ */
String.prototype.rtrim=function() String.prototype.rtrim=function()
{ {
return this.replace(/(\s*$)/g,''); return this.replace(/(\s*$)/g,'');
} }
//----------------Get Param------------- //----------------Get Param-------------
function GetQueryString(name) function GetQueryString(name)
{ {
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg); var r = window.location.search.substr(1).match(reg);
if (r!=null) if (r!=null)
{ {
return unescape(r[2]); return unescape(r[2]);
} }
else else
{ {
return null; return null;
} }
} }
function GetGetStr() function GetGetStr()
{ {
let strGet=""; let strGet="";
//获取当前URL //获取当前URL
let url = document.location.href; let url = document.location.href;
//获取?的位置 //获取?的位置
let index = url.indexOf("?") let index = url.indexOf("?")
if(index != -1) { if(index != -1) {
//截取出?后面的字符串 //截取出?后面的字符串
strGet = url.substr(index + 1); strGet = url.substr(index + 1);
} }
return strGet; return strGet;
} }
/*--------------File Function--------------*/ /*--------------File Function--------------*/
function getFileName(path) function getFileName(path)
{ {
var pos1 = path.lastIndexOf('/'); var pos1 = path.lastIndexOf('/');
var pos2 = path.lastIndexOf('\\'); var pos2 = path.lastIndexOf('\\');
var pos = Math.max(pos1, pos2); var pos = Math.max(pos1, pos2);
if (pos < 0) { if (pos < 0) {
return null; return null;
} }
else else
{ {
return path.substring(pos + 1); return path.substring(pos + 1);
} }
} }
function getFileTail(path) function getFileTail(path)
{ {
var pos = path.lastIndexOf('.'); var pos = path.lastIndexOf('.');
if (pos < 0) { if (pos < 0) {
return null; return null;
} }
else else
{ {
return path.substring(pos + 1); return path.substring(pos + 1);
} }
} }
/*--------------String Function-----------*/ /*--------------String Function-----------*/
function html_encode(str) function html_encode(str)
{ {
var s = ""; var s = "";
if (str.length == 0) return ""; if (str.length == 0) return "";
s = str.replace(/&/g, "&amp;"); s = str.replace(/&/g, "&amp;");
s = s.replace(/</g, "&lt;"); s = s.replace(/</g, "&lt;");
s = s.replace(/>/g, "&gt;"); s = s.replace(/>/g, "&gt;");
s = s.replace(/ /g, "&nbsp;"); s = s.replace(/ /g, "&nbsp;");
s = s.replace(/\'/g, "&#39;"); s = s.replace(/\'/g, "&#39;");
s = s.replace(/\"/g, "&quot;"); s = s.replace(/\"/g, "&quot;");
s = s.replace(/\n/g, "<br/>"); s = s.replace(/\n/g, "<br/>");
return s; return s;
} }
function html_decode(str) function html_decode(str)
{ {
var s = ""; var s = "";
if (str.length == 0) return ""; if (str.length == 0) return "";
s = str.replace(/&amp;/g, "&"); s = str.replace(/&amp;/g, "&");
s = s.replace(/&lt;/g, "<"); s = s.replace(/&lt;/g, "<");
s = s.replace(/&gt;/g, ">"); s = s.replace(/&gt;/g, ">");
s = s.replace(/&nbsp;/g, " "); s = s.replace(/&nbsp;/g, " ");
s = s.replace(/&#39;/g, "\'"); s = s.replace(/&#39;/g, "\'");
s = s.replace(/&quot;/g, "\""); s = s.replace(/&quot;/g, "\"");
s = s.replace(/<br\/>/g, "\n"); s = s.replace(/<br\/>/g, "\n");
return s; return s;
} }
/*--------------------JSON Function------------*/ /*--------------------JSON Function------------*/
/* /*
功能:检查一个字符串是不是标准的JSON格式 功能:检查一个字符串是不是标准的JSON格式
参数: strJson 被检查的字符串 参数: strJson 被检查的字符串
返回值: 如果字符串是一个标准的JSON格式,则返回JSON对象 返回值: 如果字符串是一个标准的JSON格式,则返回JSON对象
如果字符串不是标准JSON格式,则返回null 如果字符串不是标准JSON格式,则返回null
*/ */
function IsJson( strJson ) function IsJson( strJson )
{ {
var tJson=null; var tJson=null;
try try
{ {
tJson=JSON.parse(strJson); tJson=JSON.parse(strJson);
} }
catch(exception) catch(exception)
{ {
return null; return null;
} }
return tJson; return tJson;
} }
function DecodeJsonObject( pJson ) function DecodeJsonObject( pJson )
{ {
let tmpJson=JSON.stringify(pJson); let tmpJson=JSON.stringify(pJson);
tmpJson=decodeURIComponent(tmpJson); tmpJson=decodeURIComponent(tmpJson);
pJson=JSON.parse(tmpJson); pJson=JSON.parse(tmpJson);
return pJson; return pJson;
} }
/*-----------------------Ajax Function--------------------*/ /*-----------------------Ajax Function--------------------*/
/*对JQuery的Ajax函数的封装,只支持异步 /*对JQuery的Ajax函数的封装,只支持异步
参数说明: 参数说明:
url 目标地址 url 目标地址
action post/get action post/get
data 字符串格式的发送内容 data 字符串格式的发送内容
asyn true---异步模式;false-----同步模式; asyn true---异步模式;false-----同步模式;
*/ */
function HttpReq( url,action, data,callbackfunc) function HttpReq( url,action, data,callbackfunc)
{ {
var strAction=action.toLowerCase(); var strAction=action.toLowerCase();
if( strAction=="post") if( strAction=="post")
{ {
$.post(url,data,callbackfunc); $.post(url,data,callbackfunc);
} }
else if( strAction=="get") else if( strAction=="get")
{ {
$.get(url,callbackfunc); $.get(url,callbackfunc);
} }
} }
/*---------------Cookie Function-------------------*/ /*---------------Cookie Function-------------------*/
function setCookie(name, value, time='',path='') { function setCookie(name, value, time='',path='') {
if(time && path){ if(time && path){
var strsec = time * 1000; var strsec = time * 1000;
var exp = new Date(); var exp = new Date();
exp.setTime(exp.getTime() + strsec * 1); exp.setTime(exp.getTime() + strsec * 1);
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path="+path; document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path="+path;
}else if(time){ }else if(time){
var strsec = time * 1000; var strsec = time * 1000;
var exp = new Date(); var exp = new Date();
exp.setTime(exp.getTime() + strsec * 1); exp.setTime(exp.getTime() + strsec * 1);
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString(); document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}else if(path){ }else if(path){
document.cookie = name + "=" + escape(value) + ";path="+path; document.cookie = name + "=" + escape(value) + ";path="+path;
}else{ }else{
document.cookie = name + "=" + escape(value); document.cookie = name + "=" + escape(value);
} }
} }
function getCookie(c_name) function getCookie(c_name)
{ {
if(document.cookie.length > 0) { if(document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=");//获取字符串的起点 c_start = document.cookie.indexOf(c_name + "=");//获取字符串的起点
if(c_start != -1) { if(c_start != -1) {
c_start = c_start + c_name.length + 1;//获取值的起点 c_start = c_start + c_name.length + 1;//获取值的起点
c_end = document.cookie.indexOf(";", c_start);//获取结尾处 c_end = document.cookie.indexOf(";", c_start);//获取结尾处
if(c_end == -1) c_end = document.cookie.length;//如果是最后一个,结尾就是cookie字符串的结尾 if(c_end == -1) c_end = document.cookie.length;//如果是最后一个,结尾就是cookie字符串的结尾
return decodeURI(document.cookie.substring(c_start, c_end));//截取字符串返回 return decodeURI(document.cookie.substring(c_start, c_end));//截取字符串返回
} }
} }
return ""; return "";
} }
function checkCookie(c_name) { function checkCookie(c_name) {
username = getCookie(c_name); username = getCookie(c_name);
console.log(username); console.log(username);
if (username != null && username != "") if (username != null && username != "")
{ return true; } { return true; }
else else
{ return false; } { return false; }
} }
function clearCookie(name) { function clearCookie(name) {
setCookie(name, "", -1); setCookie(name, "", -1);
} }
/*--------Studio WX Message-------*/ /*--------Studio WX Message-------*/
function IsInSlicer() function IsInSlicer()
{ {
let bMatch=navigator.userAgent.match( RegExp('BBL-Slicer','i') ); // window.wx is the host's message handler, registered on every webview OrcaSlicer creates.
return !!(window.wx && window.wx.postMessage);
return bMatch; }
}
function SendWXMessage( strMsg )
function SendWXMessage( strMsg ) {
{ if( IsInSlicer() )
let bCheck=IsInSlicer(); window.wx.postMessage(strMsg);
}
if(bCheck!=null)
{ function SendWXDebugInfo( strMsg )
window.wx.postMessage(strMsg); {
} var tSend={};
} tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="debug_info";
function SendWXDebugInfo( strMsg ) tSend['msg']=strMsg;
{
var tSend={}; SendWXMessage( JSON.stringify(tSend) );
tSend['sequence_id']=Math.round(new Date() / 1000); }
tSend['command']="debug_info";
tSend['msg']=strMsg; function OpenUrlInLocalBrowser( strUrl )
{
SendWXMessage( JSON.stringify(tSend) ); var tSend={};
} tSend['sequence_id']=Math.round(new Date() / 1000);
tSend['command']="common_openurl";
function OpenUrlInLocalBrowser( strUrl ) tSend['url']=strUrl;
{
var tSend={}; SendWXMessage( JSON.stringify(tSend) );
tSend['sequence_id']=Math.round(new Date() / 1000); }
tSend['command']="common_openurl";
tSend['url']=strUrl;
/*------Dark Mode------*/
SendWXMessage( JSON.stringify(tSend) ); // 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()
/*------CSS Link Control----*/ {
function RemoveCssLink( LinkPath ) let bDarkMode = window.__orcaTheme === "dark";
{ document.querySelectorAll('head link[href$="dark.css"]').forEach( function(link) { link.disabled = !bDarkMode; } );
let pNow=$("head link[href='"+LinkPath+"']"); }
let nTotal=pNow.length; ExecuteDarkMode();
for( let n=0;n<nTotal;n++ )
{
pNow[n].remove();
}
}
function AddCssLink( LinkPath )
{
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.href = LinkPath;
link.rel = 'stylesheet';
link.type = 'text/css';
head.appendChild(link);
}
function CheckCssLinkExist( LinkPath )
{
let pNow=$("head link[href='"+LinkPath+"']");
let nTotal=pNow.length;
return nTotal;
}
/*------Dark Mode------*/
function SwitchDarkMode( DarkCssPath )
{
ExecuteDarkMode( DarkCssPath );
setInterval("ExecuteDarkMode('"+DarkCssPath+"')",1000);
}
function ExecuteDarkMode( DarkCssPath )
{
let nMode=0;
let bDarkMode=navigator.userAgent.match( RegExp('dark','i') );
if( bDarkMode!=null )
nMode=1;
let nNow=CheckCssLinkExist(DarkCssPath);
if( nMode==0 )
{
if(nNow>0)
RemoveCssLink(DarkCssPath);
}
else
{
if(nNow==0)
AddCssLink(DarkCssPath);
}
}
SwitchDarkMode( "./css/dark.css" );
+1 -1
View File
@@ -9,7 +9,7 @@
<script type="text/javascript" src="../include/i18n.js"></script> <script type="text/javascript" src="../include/i18n.js"></script>
<script type="text/javascript" src="../include/jquery-3.6.0.min.js"></script> <script type="text/javascript" src="../include/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../homepage/js/json2.js"></script> <script type="text/javascript" src="../homepage/js/json2.js"></script>
<script type="text/javascript" src="../homepage/js/globalapi.js"></script> <script type="text/javascript" src="../include/globalapi.js"></script>
<script type="text/javascript" src="../homepage/js/home.js"></script> <script type="text/javascript" src="../homepage/js/home.js"></script>
</head> </head>
<body onLoad="OnInit()"> <body onLoad="OnInit()">
+1
View File
@@ -288,6 +288,7 @@ void PrinterWebView::SendAPIKey()
WebView::MarkScriptMessageHandlerAdded(m_browser); WebView::MarkScriptMessageHandlerAdded(m_browser);
else else
wxLogError("Could not add script message handler"); wxLogError("Could not add script message handler");
WebView::AddHostThemeScript(m_browser);
#ifdef __linux__ #ifdef __linux__
// Re-inject the vue-resize/WebKitGTK workaround that RemoveAllUserScripts just cleared. // Re-inject the vue-resize/WebKitGTK workaround that RemoveAllUserScripts just cleared.
+34 -9
View File
@@ -284,6 +284,25 @@ static WebViewRef *webview_ref(wxWebView *webView)
return webView ? static_cast<WebViewRef *>(webView->GetRefData()) : nullptr; return webView ? static_cast<WebViewRef *>(webView->GetRefData()) : nullptr;
} }
#ifndef __linux__
// The User-Agent Windows and macOS have always sent, with the app's version, dark mode and language
// appended. No bundled page reads it any more (they get the theme from the script below), so Linux
// sends WebKitGTK's own, which Cloudflare accepts on third-party print-host pages.
static wxString tagged_user_agent(bool dark)
{
const wxString language_code = Slic3r::GUI::wxGetApp().current_language_code().BeforeFirst('_');
return wxString::Format("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) BBL-Slicer/v%s (%s) BBL-Language/%s",
Slic3r::GUI::wxGetApp().get_bbl_client_version(), dark ? "dark" : "light", language_code);
}
#endif
// Document-start script the legacy pages read their theme from (globalapi.js). Plugin pages have
// their own, richer contract in WebViewHostDialog.
static wxString host_theme_script()
{
return wxString::Format("window.__orcaTheme=\"%s\";", Slic3r::GUI::wxGetApp().dark_mode() ? "dark" : "light");
}
wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url) wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url)
{ {
#if wxUSE_WEBVIEW_EDGE #if wxUSE_WEBVIEW_EDGE
@@ -314,9 +333,8 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url)
if (webView) { if (webView) {
webView->SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE)); webView->SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE));
wxString language_code = Slic3r::GUI::wxGetApp().current_language_code().BeforeFirst('_');
language_code = language_code.ToStdString();
#ifdef __WIN32__ #ifdef __WIN32__
const wxString language_code = Slic3r::GUI::wxGetApp().current_language_code().BeforeFirst('_');
webView->SetUserAgent(wxString::Format("Mozilla/5.0 (Windows NT 10.0; Win64; x64) " webView->SetUserAgent(wxString::Format("Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.52 BBL-Slicer/v%s (%s) BBL-Language/%s", "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.52 BBL-Slicer/v%s (%s) BBL-Language/%s",
Slic3r::GUI::wxGetApp().get_bbl_client_version(), Slic3r::GUI::wxGetApp().dark_mode() ? "dark" : "light", language_code.mb_str())); Slic3r::GUI::wxGetApp().get_bbl_client_version(), Slic3r::GUI::wxGetApp().dark_mode() ? "dark" : "light", language_code.mb_str()));
@@ -337,10 +355,10 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url)
} }
webView->Create(parent, wxID_ANY, url2, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); webView->Create(parent, wxID_ANY, url2, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
#ifndef __linux__ #ifndef __linux__
webView->SetUserAgent(wxString::Format("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) BBL-Slicer/v%s (%s) BBL-Language/%s", webView->SetUserAgent(tagged_user_agent(Slic3r::GUI::wxGetApp().dark_mode()));
Slic3r::GUI::wxGetApp().get_bbl_client_version(), Slic3r::GUI::wxGetApp().dark_mode() ? "dark" : "light", language_code.mb_str()));
#endif #endif
#endif #endif
WebView::AddHostThemeScript(webView);
#ifdef __WXMAC__ #ifdef __WXMAC__
WKWebView * wkWebView = (WKWebView *) webView->GetNativeBackend(); WKWebView * wkWebView = (WKWebView *) webView->GetNativeBackend();
Slic3r::GUI::WKWebView_setTransparentBackground(wkWebView); Slic3r::GUI::WKWebView_setTransparentBackground(wkWebView);
@@ -393,6 +411,11 @@ void WebView::MarkScriptMessageHandlerAdded(wxWebView * webView)
ref->m_script_handler_added = true; ref->m_script_handler_added = true;
} }
void WebView::AddHostThemeScript(wxWebView *webView)
{
webView->AddUserScript(host_theme_script(), wxWEBVIEW_INJECT_AT_DOCUMENT_START);
}
bool WebView::NeedsRecreateOnShow() bool WebView::NeedsRecreateOnShow()
{ {
const bool recreating = Slic3r::GUI::wxGetApp().is_recreating_gui(); const bool recreating = Slic3r::GUI::wxGetApp().is_recreating_gui();
@@ -468,14 +491,16 @@ bool WebView::RunScript(wxWebView *webView, wxString const &javascript)
void WebView::RecreateAll() void WebView::RecreateAll()
{ {
auto dark = Slic3r::GUI::wxGetApp().dark_mode(); #ifndef __linux__
wxString language_code = Slic3r::GUI::wxGetApp().current_language_code().BeforeFirst('_'); const wxString user_agent = tagged_user_agent(Slic3r::GUI::wxGetApp().dark_mode());
language_code = language_code.ToStdString(); #endif
for (auto webView : g_webviews) { for (auto webView : g_webviews) {
#ifndef __linux__ #ifndef __linux__
webView->SetUserAgent(wxString::Format("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) BBL-Slicer/v%s (%s) BBL-Language/%s", webView->SetUserAgent(user_agent);
Slic3r::GUI::wxGetApp().get_bbl_client_version(), dark ? "dark" : "light", language_code.mb_str()));
#endif #endif
// User scripts run in the order they were added, so the newest theme assignment wins on the
// reload below; the earlier ones are a few bytes each.
AddHostThemeScript(webView);
// A host-themed WebViewHostDialog re-themes in place (no reload). If it handles // A host-themed WebViewHostDialog re-themes in place (no reload). If it handles
// the event, skip the reload; legacy pages fall through and reload as before // the event, skip the reload; legacy pages fall through and reload as before
// (their own dark.css swap re-themes them on reload). // (their own dark.css swap re-themes them on reload).
+4
View File
@@ -26,6 +26,10 @@ public:
// Marks "wx" as registered so CreateWebView's deferred add skips the duplicate. // Marks "wx" as registered so CreateWebView's deferred add skips the duplicate.
static void MarkScriptMessageHandlerAdded(wxWebView * webView); static void MarkScriptMessageHandlerAdded(wxWebView * webView);
// Tells the page the app's theme at document start (window.__orcaTheme). Added by CreateWebView and
// again on a theme change; a view that cleared its user scripts has to add it back.
static void AddHostThemeScript(wxWebView *webView);
// On Windows, a WebView2 backend created during a GUI rebuild (language switch) can come up // On Windows, a WebView2 backend created during a GUI rebuild (language switch) can come up
// ignoring every navigation. A panel that gets true here recreates its view on first Show(). // ignoring every navigation. A panel that gets true here recreates its view on first Show().
static bool NeedsRecreateOnShow(); static bool NeedsRecreateOnShow();