Jump to content

User:Svick/HarvErrors.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Usage: add importScript(User:Svick/HarvErrors.js); to Special:Mypage/skin.js
// See also Wikipedia:Centralized discussion/Citation discussion#Technical discussion regarding Harvard Refs
// This script works fine for Harvard references in <ref> tags, but for inline Harv. refs,
// the error message shows up at the end of the paragraph in which the error is
error = " <strong class=error>Harv error: this link doesn't point to any citation.</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;
 }
});