User:Yair rand/orangelinks2.js: difference between revisions

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
(add a couple of headers to anchorExclusionList, add new exceptionCategories = ["Category:Latin American Spanish"];)
Line 2: Line 2:
 
function setupOrangeLinks(){
 
function setupOrangeLinks(){
 
var r = [], v = [], f = $("#bodyContent a[href*=\"#\"]:not(.new,.extiw,.external,[href^=\"#\"],[href*=\":\"],#languageLinks a)")
 
var r = [], v = [], f = $("#bodyContent a[href*=\"#\"]:not(.new,.extiw,.external,[href^=\"#\"],[href*=\":\"],#languageLinks a)")
var anchorExclusionList = ["Noun","Verb","Adjective","Adverb","Preposition","Translations"];
+
var anchorExclusionList = ["Noun","Verb","Adjective","Adverb","Preposition","Translations","Etymology","Pronunciation","Conjugation","Declension","Inflection","Synonyms","Antonyms"];
  +
var exceptionCategories = ["Category:Latin American Spanish"];
 
f=f.filter(function(){return $.inArray(this.href.split("#")[1], anchorExclusionList) == -1})
 
f=f.filter(function(){return $.inArray(this.href.split("#")[1], anchorExclusionList) == -1})
 
f.each(function(){
 
f.each(function(){
Line 22: Line 22:
 
if(n){
 
if(n){
 
for(var ii = 0, l = n.length; ii < l; ++ii){
 
for(var ii = 0, l = n.length; ii < l; ++ii){
if(n[ii].title.indexOf(vv) == 0){
+
if(n[ii].title.indexOf(vv) === 0 && $.inArray( n[ii].title, exceptionCategories ) === -1 ){
 
break;
 
break;
 
}
 
}

Revision as of 22:18, 7 April 2013

// The idea for this script was taken from [[User:Hippietrail/ajaxtranslinks.js]].
function setupOrangeLinks(){
  var r = [], v = [], f = $("#bodyContent a[href*=\"#\"]:not(.new,.extiw,.external,[href^=\"#\"],[href*=\":\"],#languageLinks a)")
  var anchorExclusionList = ["Noun","Verb","Adjective","Adverb","Preposition","Translations","Etymology","Pronunciation","Conjugation","Declension","Inflection","Synonyms","Antonyms"];
  var exceptionCategories = ["Category:Latin American Spanish"];
  f=f.filter(function(){return $.inArray(this.href.split("#")[1], anchorExclusionList) == -1})
  f.each(function(){
    var b = decodeURI( ( this.href.split("/wiki/")[1] || '').replace(/\.(?![^#]*#)/g, '%') ).replace(/_/g,' ').split("#"); 
    v.push(b);
    $.inArray(b[0],r) == -1 && r.push(b[0])
    })
  r.length && JsMwApi()({action:'query',prop:'categories',clshow:"!hidden",cllimit:$.inArray("sysop",wgUserGroups) == -1?500:5000,titles:r.splice(0,$.inArray("sysop",wgUserGroups) == -1?50:500).join("|"),maxage:300,smaxage:300},function(p){
    if(p['query-continue']){
      window.console&&console.log&&console.log("Too many links on the page for orangelinks function to work.")
      return;
      }
    var j = p.query.pages;
    f.each(function(g){
      var vv = "Category:"+v[g][1]+" ", vvv = v[g][0];
      for(var i in j){
        if(j[i].title == vvv){
          var n = j[i].categories;
          if(n){
            for(var ii = 0, l = n.length; ii < l; ++ii){
              if(n[ii].title.indexOf(vv) === 0 && $.inArray( n[ii].title, exceptionCategories ) === -1 ){
                break;
                }
              }
            }
          if(!n || ii == l){
            this.className = 'partlynew'
            }
          break;
          }
        }
      })
    })
  }
 
wgNamespaceNumber && wgNamespaceNumber != 4 && wgNamespaceNumber != 100 && wgNamespaceNumber != 110 || addOnloadHook(setupOrangeLinks)