// ==UserScript== // @name 人教电子教材显示书名 // @namespace http://tampermonkey.net/ // @version 2025.4.17 // @description 显示书名 // @author AN drew // @match https://jc.pep.com.cn/* // @require https://lib.baomitu.com/jquery/3.5.0/jquery.min.js // @grant GM_addStyle // @downloadURL none // ==/UserScript== //从后往前查找并替换第一个匹配的子串 function replaceLast1(str, search, replacement) { const regex = new RegExp(search, 'g'); let match; let lastMatchIndex = -1; // 遍历所有匹配项,记录最后一个匹配的位置 while ((match = regex.exec(str)) !== null) { lastMatchIndex = match.index; } // 未找到匹配项 if (lastMatchIndex === -1) return str; // 替换最后一个匹配项 return ( str.slice(0, lastMatchIndex) + replacement + str.slice(lastMatchIndex + search.length) ); } //从后往前查找并替换第一个匹配的子串 function replaceLast2(str, search, replacement) { // 转义搜索字符串中的特殊正则字符 const escapedSearch = search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // 构造匹配最后一个子串的正则 const regex = new RegExp(`(.*)${escapedSearch}`); // 替换匹配到的最后一个子串 return str.replace(regex, (_, p1) => p1 + replacement); } //从后往前查找并替换第一个匹配的子串 function replaceLast3(str, search, replacement) { // 查找目标子串在原始字符串中的最后一个出现位置 const index = str.lastIndexOf(search); // 如果存在匹配项(index !== -1) if (index !== -1) { // 拼接三部分:原始字符串前半段 + 替换内容 + 原始字符串后半段 return ( str.substring(0, index) + replacement + str.substring(index + search.length) ); } return str; } function convert(title) { //将(A版)从末尾移动到'数学'之后 if(title.indexOf('普通高中教科书数学')>-1) { title = title.replace(/^(普通高中教科书数学)(.*?册)((.*版))$/, "$1$3$2"); } //选择性必修[0-9]换行 if(title.indexOf('选择性必修')>-1) { title = title.replace(/选择性必修\d?/g, '$&
'); } //必修[0-9]换行 else if(title.indexOf('必修')>-1 && title.indexOf('必修
')==-1) { title = title.replace(/必修\d?/g, '$&
'); } //低视力版 信息技术 部分标题缺少'(供低视力学生使用)' if(title.indexOf('盲校义务教育实验教科书 信息技术')>-1 && title.indexOf('(盲文版)')==-1&& title.indexOf('(供低视力学生使用)')==-1) { title += '(供低视力学生使用)'; } //只在'X年级 (上/下)册'加空格,'(X年级起点)'不加 if(title.indexOf('年级')>-1) { title = replaceLast3(title, '年级', '年级 '); } const replacements = [ ['语文', '语文
'], ['数学', '数学
'], ['英语', '英语
'], ['日语', '日语
'], ['俄语', '俄语
'], ['道德与法治', '道德与法治
'], ['思想政治', '思想政治
'], ['历史', '历史
'], ['地理', '地理
'], ['物理', '物理
'], ['化学', '化学
'], ['生物学', '生物学
'], ['音乐', '音乐
'], ['美术', '美术
'], ['艺术', '艺术
'], ['美工', '美工
'], ['体育与健康', '体育与健康
'], ['信息技术', '信息技术
'], ['通用技术', '通用技术
'], ['科学', '科学
'], ['影视', '影视
'], ['戏剧', '戏剧
'], ['舞蹈', '舞蹈
'], ['沟通与交往', '沟通与交往
'], ['生活适应', '生活适应
'], ['必修
上册', '必修 上册'], ['必修
中册', '必修 中册'], ['必修
下册', '必修 下册'], ['必修
第一册', '必修 第一册'], ['必修
第二册', '必修 第二册'], ['必修
第三册', '必修 第三册'], ['必修
第四册', '必修 第四册'], ['中外历史纲要上', '中外历史纲要 上'], ['中外历史纲要下', '中外历史纲要 下'], ['社会主义思想', '社会主义思想
'], ['小学低年级', '小学 低年级'], ['小学高年级', '小学 高年级'], ['影视
与数字媒体艺术实践', '影视与数字媒体艺术实践
'], ['戏剧
创编与表演', '戏剧创编与表演
'], ['舞蹈
创编与表演', '舞蹈创编与表演
'], ['音乐
情境表演', '音乐情境表演
'], ['美术
创意实践', '美术创意实践
'], ['手册', '手册
'], ['读本', '读本
'], ['教科书', '教科书
'], ['教师用书', '教师用书
'], ['选修课程用书', '选修课程用书
'], ['低视力版', '低视力版
'], ['(五线谱)', '
(五线谱)'], ['(简谱)', '
(简谱)'], ['起点)', '起点)
'], ['(精通)', '(精通)
'], ['(PEP)', '(PEP)
'], ['(A版)', '(A版)
'], ['(B版)', '(B版)
'], ['(上册)', '
(上册)'], ['(下册)', '
(下册)'], ['(盲文版)', '
(盲文版)'], ['(五·四学制)', '(五·四学制)
'], ['(供低视力学生使用)', '
(供低视力学生使用)'] ]; replacements.forEach(([search, repl]) => { title = title.replace(search, repl); }); return title; } (function() { 'use strict'; GM_addStyle(` .page_pc .page_pc_btm .page_pc_btm_period .page_pc_btm_period_body .page_pc_btm_period_body_type:nth-of-type(1) .body_type { display: grid; } .page_pc .page_pc_btm .page_pc_btm_period .page_pc_btm_period_body .page_pc_btm_period_body_type .body_type .item { height: 30px; margin-bottom: 5px; } .page_pc_btm_book_body { height: auto !important } .page_pc_btm_book_body .name { margin: 0px 14px; padding: 8px; font-weight: bold; font-family: 楷体, 隶书, cursive; font-size: 22px; text-align: center; line-height: 1.5; } .page_pc_btm_book_body .read { margin: 5px 0px 20px 20px !important } .textbook .item { height: auto !important } .textbook .item .name { margin: 0px 14px; padding: 8px; font-weight: bold; font-family: 楷体, 隶书, cursive; font-size: 22px; text-align: center; line-height: 1.5; } .textbook .item .read { margin-top: 5px !important } `); let t=setInterval(function(){ //PC端 if($('.page_pc_btm_book_body').length>0) { $('.page_pc_btm_book_body').each(function(){ //教材封面存在 if($(this).find('.imga').length>0) { //教材名称不存在,添加名称 if($(this).find('.name').length==0) { let title=$(this).find('.imga').attr('title'); title=convert(title); $(this).find('.imga').after('
'+title+'
'); } //切换科目时,改变名称 else { let old_title=$(this).find('.name').html(); let new_title=$(this).find('.imga').attr('title'); new_title=convert(new_title); if(old_title != new_title) { $(this).find('.name').html(new_title); } } } }); } //手机端 if($('.textbook .item').length>0) { $('.textbook .item').each(function(){ //教材封面存在 if($(this).find('.cover').length>0) { //教材名称不存在,添加名称 if($(this).find('.name').length==0) { let title=$(this).find('.cover').attr('alt'); title=convert(title); $(this).find('.cover').after('
'+title+'
'); } //切换科目时,改变名称 else { let old_title=$(this).find('.name').html(); let new_title=$(this).find('.cover').attr('alt'); new_title=convert(new_title); if(old_title != new_title) { $(this).find('.name').html(new_title); } } } }); } },1000); })();