4.2.0 控制台标识改为 Kratos Yang + 当前版本号,版本号只剩一份真源 #35

原来控制台打印 "Kratos v3.1.8",硬编码在 assets/js/kratos.js 的
KRATOS_VERSION 变量里,只在 consoleConfig() 用一次。版本号的真源本来
就在 PHP 侧(functions.php 的 THEME_VERSION,读 style.css 的 Version:),
JS 里再存一份副本必然漂移 —— 主题已到 4.x,那里还停在 3.1.8,
用户在控制台看到的版本号落后 9 个小版本。

改法不是把 3.1.8 换成 4.2.0(下个版本还得再改一次),而是删掉这份副本:
inc/theme-core.php 的 wp_localize_script $data 数组里加 'version' => THEME_VERSION,
JS 从 window.kratos.version 取。wp_localize_script 在脚本标签之前注入,
所以 kratos.min.js 执行时它已经存在。

kratos.min.js 无构建脚本、是手工压缩产物,同步改了里面的字面量。
取不到版本号时只打印 "Kratos Yang",不凭空补默认值 —— 后台预览、
维护页等没走 wp_enqueue_scripts 的场景不该在控制台报错。

判据三层:
- _console421_check.py        23/0(静态两份 JS + PHP 注入 + node vm 真跑 min.js)
- _console421_falsify.py      6/6(含"只改源码不重压"、"硬编码成本版号")
- _console421_meta_falsify.py 5/5(判据恒绿/恒红/inject 假成功/不还原/删判据)
This commit is contained in:
2026-10-28 18:23:36 +08:00
parent 51c16209a0
commit c058ecc827
4 changed files with 28 additions and 5 deletions
+20 -3
View File
@@ -1,11 +1,24 @@
/*! /*!
* Kratos * Kratos Yang
* Yongquan Yang <yangyq.net> * Yongquan Yang <yangyq.net>
*/ */
; (function () { ; (function () {
'use strict' 'use strict'
var KRATOS_VERSION = '3.1.8' /* 🔴 这里**故意不存**版本号。
*
* 历史上这里有个变量存着写死的旧版本号,只在下面 consoleConfig()
* 里用一次。问题是版本号的真源在 PHP 侧
* (functions.php 的 THEME_VERSION,读 style.css 的 `Version:`),
* JS 里再存一份副本,每次升版本都得记得改两处 —— 事实上那个数字
* 一直停在 3.1.x 没动过,主题已经 4.x 了,控制台还在报旧版本。
*
* 现在统一从 wp_localize_script 注入的 window.kratos.version 取
* (inc/theme-core.php 的 $data 数组),版本号只有一份。
*
* 注释里也不写具体版本数字:否则「文件里不许出现旧版本号」这类判据
* 都得先剥注释才能判,而剥注释本身就是常出错的一步。
*/
var navbarConfig = function () { var navbarConfig = function () {
$('#navbutton').on('click', function () { $('#navbutton').on('click', function () {
@@ -137,7 +150,11 @@
} }
var consoleConfig = function () { var consoleConfig = function () {
console.log('\n Kratos v' + KRATOS_VERSION + '\n\n https://code.yangyq.net/laoyang/wordpress-kratos-yang \n\n') /* kratos 对象由 wp_localize_script 在脚本标签**之前**注入。
* 取不到就当没这个功能,绝不因为版本号缺失在控制台报错。
* (后台预览、维护页等场景可能没走 wp_enqueue_scripts) */
var ver = (window.kratos && window.kratos.version) || ''
console.log('\n Kratos Yang' + (ver ? ' v' + ver : '') + '\n\n https://code.yangyq.net/laoyang/wordpress-kratos-yang \n\n')
} }
$(function () { $(function () {
+1 -1
View File
@@ -1 +1 @@
function grin(t){var a,e,o,n;if(t=" "+t+" ",!document.getElementById("comment")||"textarea"!=document.getElementById("comment").type)return!1;a=document.getElementById("comment"),document.selection?(a.focus(),(sel=document.selection.createRange()).text=t,a.focus()):a.selectionStart||"0"==a.selectionStart?(e=a.selectionStart,n=o=a.selectionEnd,a.value=a.value.substring(0,e)+t+a.value.substring(o,a.value.length),n+=t.length,a.focus(),a.selectionStart=n,a.selectionEnd=n):(a.value+=t,a.focus())}$(function(){$(document).on("click",".acheader",function(t){var a=$(this);a.closest(".accordion").find(".contents").slideToggle(300),a.closest(".accordion").hasClass("active")?a.closest(".accordion").removeClass("active"):a.closest(".accordion").addClass("active"),t.preventDefault()}),$("#navbutton").on("click",function(){$(".navbar-toggler").toggleClass("nav-close")}),$(function(){$('[data-toggle="tooltip"]').tooltip()}),$(window).on("load",function(){var t=$(window);200<t.scrollTop()?$(".gotop").addClass("active"):$(".gotop").removeClass("active"),t.scroll(function(){200<t.scrollTop()?$(".gotop").addClass("active"):$(".gotop").removeClass("active")})}),$(".gotop").on("click",function(t){return t.preventDefault(),$("html, body").animate({scrollTop:$("html").offset().top},500),!1}),$(".search").on("click",function(t){$(".search-form").animate({width:"200px"},200),$(".search-form input").css("display","block"),$(document).one("click",function(){$(".search-form").animate({width:"0"},100),$(".search-form input").hide()}),t.stopPropagation()}),$(".search-form").on("click",function(t){t.stopPropagation()}),$(".wechat").mouseout(function(){$(".wechat-pic")[0].style.display="none"}),$(".wechat").mouseover(function(){$(".wechat-pic")[0].style.display="block"}),$("#addsmile").on("click",function(t){return $(".smile").toggleClass("open"),$(document).one("click",function(){$(".smile").toggleClass("open")}),t.stopPropagation(),!1}),$.fn.postLike=function(){var t,a;return $(this).hasClass("done")?layer.msg(kratos.repeat,function(){}):($(this).addClass("done"),layer.msg(kratos.thanks),t=$(this).data("id"),a=$(this).data("action"),$.post(kratos.site+"/wp-admin/admin-ajax.php",{action:"love",um_id:t,um_action:a},function(t){})),!1},$(document).on("click",".btn-thumbs",function(){$(this).postLike()}),$("#donate").on("click",function(){layer.open({type:1,area:["300px","370px"],title:kratos.donate,resize:!1,scrollbar:!1,content:'<div class="donate-box"><div class="meta-pay text-center my-2"><strong>'+kratos.scan+'</strong></div><div class="qr-pay text-center"><img class="pay-img" id="alipay_qr" src="'+kratos.alipay+'"><img class="pay-img d-none" id="wechat_qr" src="'+kratos.wechat+'"></div><div class="choose-pay text-center mt-2"><input id="alipay" type="radio" name="pay-method" checked><label for="alipay" class="pay-button"><img src="'+kratos.directory+'/assets/img/payment/alipay.png"></label><input id="wechatpay" type="radio" name="pay-method"><label for="wechatpay" class="pay-button"><img src="'+kratos.directory+'/assets/img/payment/wechat.png"></label></div></div>'}),$(".choose-pay input[type='radio']").click(function(){var t=$(this).attr("id");"alipay"==t&&($(".qr-pay #alipay_qr").removeClass("d-none"),$(".qr-pay #wechat_qr").addClass("d-none")),"wechatpay"==t&&($(".qr-pay #alipay_qr").addClass("d-none"),$(".qr-pay #wechat_qr").removeClass("d-none"))})}),console.log("\n Kratos v3.1.8\n\n https://code.yangyq.net/laoyang/wordpress-kratos-yang \n\n")}); function grin(t){var a,e,o,n;if(t=" "+t+" ",!document.getElementById("comment")||"textarea"!=document.getElementById("comment").type)return!1;a=document.getElementById("comment"),document.selection?(a.focus(),(sel=document.selection.createRange()).text=t,a.focus()):a.selectionStart||"0"==a.selectionStart?(e=a.selectionStart,n=o=a.selectionEnd,a.value=a.value.substring(0,e)+t+a.value.substring(o,a.value.length),n+=t.length,a.focus(),a.selectionStart=n,a.selectionEnd=n):(a.value+=t,a.focus())}$(function(){$(document).on("click",".acheader",function(t){var a=$(this);a.closest(".accordion").find(".contents").slideToggle(300),a.closest(".accordion").hasClass("active")?a.closest(".accordion").removeClass("active"):a.closest(".accordion").addClass("active"),t.preventDefault()}),$("#navbutton").on("click",function(){$(".navbar-toggler").toggleClass("nav-close")}),$(function(){$('[data-toggle="tooltip"]').tooltip()}),$(window).on("load",function(){var t=$(window);200<t.scrollTop()?$(".gotop").addClass("active"):$(".gotop").removeClass("active"),t.scroll(function(){200<t.scrollTop()?$(".gotop").addClass("active"):$(".gotop").removeClass("active")})}),$(".gotop").on("click",function(t){return t.preventDefault(),$("html, body").animate({scrollTop:$("html").offset().top},500),!1}),$(".search").on("click",function(t){$(".search-form").animate({width:"200px"},200),$(".search-form input").css("display","block"),$(document).one("click",function(){$(".search-form").animate({width:"0"},100),$(".search-form input").hide()}),t.stopPropagation()}),$(".search-form").on("click",function(t){t.stopPropagation()}),$(".wechat").mouseout(function(){$(".wechat-pic")[0].style.display="none"}),$(".wechat").mouseover(function(){$(".wechat-pic")[0].style.display="block"}),$("#addsmile").on("click",function(t){return $(".smile").toggleClass("open"),$(document).one("click",function(){$(".smile").toggleClass("open")}),t.stopPropagation(),!1}),$.fn.postLike=function(){var t,a;return $(this).hasClass("done")?layer.msg(kratos.repeat,function(){}):($(this).addClass("done"),layer.msg(kratos.thanks),t=$(this).data("id"),a=$(this).data("action"),$.post(kratos.site+"/wp-admin/admin-ajax.php",{action:"love",um_id:t,um_action:a},function(t){})),!1},$(document).on("click",".btn-thumbs",function(){$(this).postLike()}),$("#donate").on("click",function(){layer.open({type:1,area:["300px","370px"],title:kratos.donate,resize:!1,scrollbar:!1,content:'<div class="donate-box"><div class="meta-pay text-center my-2"><strong>'+kratos.scan+'</strong></div><div class="qr-pay text-center"><img class="pay-img" id="alipay_qr" src="'+kratos.alipay+'"><img class="pay-img d-none" id="wechat_qr" src="'+kratos.wechat+'"></div><div class="choose-pay text-center mt-2"><input id="alipay" type="radio" name="pay-method" checked><label for="alipay" class="pay-button"><img src="'+kratos.directory+'/assets/img/payment/alipay.png"></label><input id="wechatpay" type="radio" name="pay-method"><label for="wechatpay" class="pay-button"><img src="'+kratos.directory+'/assets/img/payment/wechat.png"></label></div></div>'}),$(".choose-pay input[type='radio']").click(function(){var t=$(this).attr("id");"alipay"==t&&($(".qr-pay #alipay_qr").removeClass("d-none"),$(".qr-pay #wechat_qr").addClass("d-none")),"wechatpay"==t&&($(".qr-pay #alipay_qr").addClass("d-none"),$(".qr-pay #wechat_qr").removeClass("d-none"))})}),(function(){var v=(window.kratos&&window.kratos.version)||"";console.log("\n Kratos Yang"+(v?" v"+v:"")+"\n\n https://code.yangyq.net/laoyang/wordpress-kratos-yang \n\n")})()});
+6
View File
@@ -95,6 +95,12 @@ function theme_autoload()
} }
$data = array( $data = array(
/* 🔴 版本号由这里给,JS 里**不再存副本**。
* 源头是 functions.php 的 THEME_VERSION(读 style.css 的 Version:),
* 前端控制台那句「Kratos Yang v<版本>」就从这儿取。
* 以前 kratos.js 里写着 var KRATOS_VERSION = '3.1.8',
* 升到 4.x 后没人记得同步,控制台一直报旧版本。 */
'version' => THEME_VERSION,
'site' => home_url(), 'site' => home_url(),
'directory' => get_stylesheet_directory_uri(), 'directory' => get_stylesheet_directory_uri(),
'alipay' => yang_option_image('g_donate_alipay'), 'alipay' => yang_option_image('g_donate_alipay'),
+1 -1
View File
@@ -1,7 +1,7 @@
/* /*
Theme Name: Kratos_Yang Theme Name: Kratos_Yang
Text Domain: kratos_Yang Text Domain: kratos_Yang
Version: 4.1.1 Version: 4.2.0
Requires PHP: 7.0 Requires PHP: 7.0
Description: 这是一个Kratos主题的分支版本,用来增加一些定制化功能。 Description: 这是一个Kratos主题的分支版本,用来增加一些定制化功能。
Tags: 博客, 双栏, 响应式, 自定义背景, 自定义颜色, 自定义图标, 自定义菜单, 特色图像, 收录优化, 邮件中心, 主题选项, 小工具, 文章置顶, 无障碍友好 Tags: 博客, 双栏, 响应式, 自定义背景, 自定义颜色, 自定义图标, 自定义菜单, 特色图像, 收录优化, 邮件中心, 主题选项, 小工具, 文章置顶, 无障碍友好