本WIKI编辑权限开放,正由 恋与深空Evol攻略组 搭建基础框架ing,期待更多猎人加入WIKI建设!
反馈留言收藏方法加入我们

全站通知:

Widget:ChangeTitleImage

来自恋与深空WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

<script type="text/javascript"> window.addEventListener('load', function () {

 try {
   window.userName = UserStatus.userInfo.uname ? UserStatus.userInfo.uname : "玩家";
   console.log(`window.userName获取成功:${window.userName}`);
 } catch (error) {
   console.log("window.userName获取失败");
   window.userName = "玩家";
 }
 const array = ['h2', 'h3', 'h4'];
 array.forEach(function (type) {
   document.querySelectorAll(type).forEach(function (container) {
     let spanElement = container.querySelector('.mw-headline');
     if (spanElement) {
       reduceBorder(type, spanElement);    // 初始化
     }
   })
 })
 let previousWidth = window.innerWidth; // 记录窗口的初始宽度
 window.addEventListener('resize', function () {  //监听窗口变化
   const currentWidth = window.innerWidth; // 获取当前窗口的宽度
   array.forEach(function (type) {
     document.querySelectorAll(type).forEach(function (container) {
       let spanElement = container.querySelector('.mw-headline');
       if (spanElement) {
         if (currentWidth < previousWidth) {
           reduceBorder(type, spanElement);
         }
         else {
           enlargeBorder(type, container, spanElement);
         }
       }
     })
   })
   previousWidth = currentWidth;
 })
 /**
  * @description 小->大
  * @param {string} type 类型
  * @param {*} h_title h2元素
  * @param {*} span h2中的span元素
  */
 function enlargeBorder(type, h_title, span) {
   let spanWidth = window.getComputedStyle(span).width;
   let h2Width = window.getComputedStyle(h_title).width;
   let spaceLen = type === 'h2' ? 380 : (type === 'h3' ? 200 : 175)
   if (Number(h2Width.slice(0, -2)) > Number(spanWidth.slice(0, -2)) + spaceLen) {
     span.removeAttribute('style');
   }
 }
 /**
  * @description 大->小
  * @param {string} type 类型
  * @param {*} span h*中的span元素
  */
 function reduceBorder(type, span) {
   let computedStyle = window.getComputedStyle(span);
   let styleStr = span.getAttribute('style');
   let doubleHeight = Number(computedStyle['line-height'].slice(0, -2)) * 2;
   let innerHeight = Number(computedStyle.height.slice(0, -2)) - Number(computedStyle.paddingTop.slice(0, -2)) - Number(computedStyle.paddingBottom.slice(0, -2));
   if (Math.ceil(innerHeight) >= doubleHeight) {  // 存在换行
     if (!styleStr) {
       if (type === 'h2') {
         span.setAttribute('style',
           "padding-right: 50px; border-image-slice: 15% 70% 40% 15% fill; border-image-width: 10px 86px 23px 38px; border-image-source:url('https://patchwiki.biligame.com/images/lysk/4/4a/2re779ryxlfiogprf30ioztst4e0ro1.png');");
       }
       else if (type === 'h3') {
         span.setAttribute('style', "padding-right: 0;border-image-source: url(https://patchwiki.biligame.com/images/lysk/a/a3/5pej1dbydse8hdzvli50s6qpv0w7gi6.png);");
       }
       else {
         span.setAttribute('style', "padding-right: 20px; border-image-source:url(https://patchwiki.biligame.com/images/lysk/0/0e/jpsoitu7ibvd0mio1yo7pzqkd9060cv.png)");
       }
     }
   }
 }

}) </script>