<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://wiki.guohao.asia/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3ACommon.js</id>
	<title>MediaWiki:Common.js - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.guohao.asia/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3ACommon.js"/>
	<link rel="alternate" type="text/html" href="https://wiki.guohao.asia/index.php?title=MediaWiki:Common.js&amp;action=history"/>
	<updated>2026-05-03T14:19:56Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://wiki.guohao.asia/index.php?title=MediaWiki:Common.js&amp;diff=22&amp;oldid=prev</id>
		<title>Null：​调整js规则</title>
		<link rel="alternate" type="text/html" href="https://wiki.guohao.asia/index.php?title=MediaWiki:Common.js&amp;diff=22&amp;oldid=prev"/>
		<updated>2025-10-17T01:19:25Z</updated>

		<summary type="html">&lt;p&gt;调整js规则&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2025年10月17日 (五) 09:19的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l31&quot;&gt;第31行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第31行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;window.addEventListener(&amp;#039;load&amp;#039;, function() {&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;window.addEventListener(&amp;#039;load&amp;#039;, function() {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   const processImages = () =&amp;gt; {&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   const processImages = () =&amp;gt; {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     document.querySelectorAll(&#039;img[src*=&quot;www.guohao.asia&quot;]&#039;).forEach(img =&amp;gt; {&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;    // 修改：同时处理www和cdn域名的图片&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     document.querySelectorAll(&#039;img[src*=&quot;www&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;.guohao.asia&quot;], img[src*=&quot;cdn&lt;/ins&gt;.guohao.asia&quot;]&#039;).forEach(img =&amp;gt; {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;       if (!img.complete || img.naturalWidth === 0) return;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;       if (!img.complete || img.naturalWidth === 0) return;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l53&quot;&gt;第53行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第54行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   // 容错机制：图片加载失败后重试&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   // 容错机制：图片加载失败后重试&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;  // 修改：同时处理www和cdn域名的图片错误&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   document.addEventListener(&amp;#039;error&amp;#039;, (e) =&amp;gt; {&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   document.addEventListener(&amp;#039;error&amp;#039;, (e) =&amp;gt; {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     if (e.target.tagName === &#039;IMG&#039; &amp;amp;&amp;amp; e.target.src.includes(&#039;www.guohao.asia&#039;)) {&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     if (e.target.tagName === &#039;IMG&#039; &amp;amp;&amp;amp;  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;        (&lt;/ins&gt;e.target.src.includes(&#039;www.guohao.asia&#039;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;) || e.target.src.includes(&#039;cdn.guohao.asia&#039;)&lt;/ins&gt;)) {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;       e.target.src = &amp;#039;data:image/svg+xml;utf8,&amp;lt;svg xmlns=&amp;quot;http://www.w3.org/2000/svg&amp;quot; width=&amp;quot;100&amp;quot; height=&amp;quot;100&amp;quot;&amp;gt;&amp;lt;/svg&amp;gt;&amp;#039;; // 占位图&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;       e.target.src = &amp;#039;data:image/svg+xml;utf8,&amp;lt;svg xmlns=&amp;quot;http://www.w3.org/2000/svg&amp;quot; width=&amp;quot;100&amp;quot; height=&amp;quot;100&amp;quot;&amp;gt;&amp;lt;/svg&amp;gt;&amp;#039;; // 占位图&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;       setTimeout(() =&amp;gt; processImages(), 1000);&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;       setTimeout(() =&amp;gt; processImages(), 1000);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key mediawiki:diff:1.41:old-5:rev-22:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Null</name></author>
	</entry>
	<entry>
		<id>https://wiki.guohao.asia/index.php?title=MediaWiki:Common.js&amp;diff=5&amp;oldid=prev</id>
		<title>Null：​创建自定义js</title>
		<link rel="alternate" type="text/html" href="https://wiki.guohao.asia/index.php?title=MediaWiki:Common.js&amp;diff=5&amp;oldid=prev"/>
		<updated>2025-10-09T08:58:08Z</updated>

		<summary type="html">&lt;p&gt;创建自定义js&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */&lt;br /&gt;
&lt;br /&gt;
// 获取所有符合条件的图片&lt;br /&gt;
//const images = document.querySelectorAll(&amp;#039;img[src*=&amp;quot;www.guohao.asia&amp;quot;]&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
// 遍历图片并调整样式&lt;br /&gt;
//images.forEach(img =&amp;gt; {&lt;br /&gt;
// 获取图片的实际宽度&lt;br /&gt;
//    const naturalWidth = img.naturalWidth;&lt;br /&gt;
&lt;br /&gt;
// 根据图片宽度设置样式&lt;br /&gt;
//    if (naturalWidth &amp;lt; 600) {&lt;br /&gt;
//         img.style.maxWidth = &amp;#039;none&amp;#039;; // 移除最大宽度限制&lt;br /&gt;
//         img.style.width = &amp;#039;auto&amp;#039;;   // 使用图片的实际宽度&lt;br /&gt;
//      } else {&lt;br /&gt;
//         img.style.width = &amp;#039;80%&amp;#039;;    // 宽度大于等于450px时，设置为父容器的80%&lt;br /&gt;
//      }&lt;br /&gt;
//});&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// utils.js (可单独封装)&lt;br /&gt;
const debounce = (func, delay) =&amp;gt; {&lt;br /&gt;
  let timeoutId;&lt;br /&gt;
  return (...args) =&amp;gt; {&lt;br /&gt;
    clearTimeout(timeoutId);&lt;br /&gt;
    timeoutId = setTimeout(() =&amp;gt; func.apply(this, args), delay);&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// 主逻辑&lt;br /&gt;
window.addEventListener(&amp;#039;load&amp;#039;, function() {&lt;br /&gt;
  const processImages = () =&amp;gt; {&lt;br /&gt;
    document.querySelectorAll(&amp;#039;img[src*=&amp;quot;www.guohao.asia&amp;quot;]&amp;#039;).forEach(img =&amp;gt; {&lt;br /&gt;
      if (!img.complete || img.naturalWidth === 0) return;&lt;br /&gt;
&lt;br /&gt;
      // Retina屏幕适配计算&lt;br /&gt;
      const pixelRatio = window.devicePixelRatio || 1;&lt;br /&gt;
      const effectiveWidth = img.naturalWidth / pixelRatio;&lt;br /&gt;
&lt;br /&gt;
      // 类名切换逻辑&lt;br /&gt;
      img.classList.remove(&amp;#039;img-auto&amp;#039;, &amp;#039;img-responsive&amp;#039;);&lt;br /&gt;
      img.classList.add(effectiveWidth &amp;lt; 600 ? &amp;#039;img-auto&amp;#039; : &amp;#039;img-responsive&amp;#039;);&lt;br /&gt;
    });&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  // 防抖处理动态内容&lt;br /&gt;
  const debouncedProcess = debounce(processImages, 250);&lt;br /&gt;
  &lt;br /&gt;
  // 初始执行 + 动态监听&lt;br /&gt;
  processImages();&lt;br /&gt;
  const observer = new MutationObserver(debouncedProcess);&lt;br /&gt;
  observer.observe(document.body, { subtree: true, childList: true });&lt;br /&gt;
&lt;br /&gt;
  // 容错机制：图片加载失败后重试&lt;br /&gt;
  document.addEventListener(&amp;#039;error&amp;#039;, (e) =&amp;gt; {&lt;br /&gt;
    if (e.target.tagName === &amp;#039;IMG&amp;#039; &amp;amp;&amp;amp; e.target.src.includes(&amp;#039;www.guohao.asia&amp;#039;)) {&lt;br /&gt;
      e.target.src = &amp;#039;data:image/svg+xml;utf8,&amp;lt;svg xmlns=&amp;quot;http://www.w3.org/2000/svg&amp;quot; width=&amp;quot;100&amp;quot; height=&amp;quot;100&amp;quot;&amp;gt;&amp;lt;/svg&amp;gt;&amp;#039;; // 占位图&lt;br /&gt;
      setTimeout(() =&amp;gt; processImages(), 1000);&lt;br /&gt;
    }&lt;br /&gt;
  }, true);&lt;br /&gt;
});&lt;/div&gt;</summary>
		<author><name>Null</name></author>
	</entry>
</feed>