User:Sanmosa/HarvErrors.js

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。

// 添加代碼「importScript('User:Sanmosa/HarvErrors.js');」至Special:Mypage/common.js頁(自己的common.js頁)即可實裝
// 以下代碼來自英文維基百科的用戶Svick的同名js小工具,該小工具的頁面歷史見https://en.wikipedia.org/w/index.php?title=User:Svick/HarvErrors.js&action=history
// 如使用哈佛參考文獻格式的頁面只添加了短模板{{sfn}}而未添加文末的對應書目文獻,將顯示以下錯誤提示字句:
error = " <strong class=error>哈佛引用格式錯誤:此sfn模板連結並未指向任何有效引用。</strong>";

jQuery(document).ready(function($) {
 links = document.links;
 for (i=0; i < links.length; i++)
 {
  href = links[i].getAttribute('href');
  if (href.indexOf('#CITEREF') == 0)
   if (document.getElementById(href.substring(1)) == null)
    links[i].parentNode.innerHTML += error;
 }
});