打开/关闭搜索
搜索
打开/关闭菜单
5
43
4
422
null
CATEGORY-SIDEBAR
导航
首页
alt z
最近更改
alt r
随机页面
alt x
社群首页
null
NextCloud
Wiki
LimeSurvey
YOURLS
帮助
特殊页面
alt q
上传文件
alt u
打开/关闭外观设置菜单
notifications
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
user-interface-preferences
个人工具
创建账号
登录
alt o
查看“︁MediaWiki:Common.js”︁的源代码
MediaWiki界面页面
更多操作
←
MediaWiki:Common.js
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于这些用户组的用户执行:
用户
、
管理员
此页面为本wiki上的软件提供界面文本,并受到保护以防止滥用。 如欲修改所有wiki的翻译,请访问
translatewiki.net
上的MediaWiki本地化项目。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您可以查看和复制此页面的源代码。
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */ // 获取所有符合条件的图片 //const images = document.querySelectorAll('img[src*="www.guohao.asia"]'); // 遍历图片并调整样式 //images.forEach(img => { // 获取图片的实际宽度 // const naturalWidth = img.naturalWidth; // 根据图片宽度设置样式 // if (naturalWidth < 600) { // img.style.maxWidth = 'none'; // 移除最大宽度限制 // img.style.width = 'auto'; // 使用图片的实际宽度 // } else { // img.style.width = '80%'; // 宽度大于等于450px时,设置为父容器的80% // } //}); // utils.js (可单独封装) const debounce = (func, delay) => { let timeoutId; return (...args) => { clearTimeout(timeoutId); timeoutId = setTimeout(() => func.apply(this, args), delay); }; }; // 主逻辑 window.addEventListener('load', function() { const processImages = () => { document.querySelectorAll('img[src*="www.guohao.asia"]').forEach(img => { if (!img.complete || img.naturalWidth === 0) return; // Retina屏幕适配计算 const pixelRatio = window.devicePixelRatio || 1; const effectiveWidth = img.naturalWidth / pixelRatio; // 类名切换逻辑 img.classList.remove('img-auto', 'img-responsive'); img.classList.add(effectiveWidth < 600 ? 'img-auto' : 'img-responsive'); }); }; // 防抖处理动态内容 const debouncedProcess = debounce(processImages, 250); // 初始执行 + 动态监听 processImages(); const observer = new MutationObserver(debouncedProcess); observer.observe(document.body, { subtree: true, childList: true }); // 容错机制:图片加载失败后重试 document.addEventListener('error', (e) => { if (e.target.tagName === 'IMG' && e.target.src.includes('www.guohao.asia')) { e.target.src = 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"></svg>'; // 占位图 setTimeout(() => processImages(), 1000); } }, true); });
返回
MediaWiki:Common.js
。