_ _    _ _____  ___   __                       
 __      _(_) | _(_)___ / ( _ ) / /_   ___ ___  _ __ ___  
 \ \ /\ / / | |/ / | |_ \ / _ \| '_ \ / __/ _ \| '_ ` _ \ 
  \ V  V /| |   <| |___) | (_) | (_) | (_| (_) | | | | | |
   \_/\_/ |_|_|\_\_|____/ \___/ \___(_)___\___/|_| |_| |_|

User:Gary/enhanced random article.js

In this article, we will explore in depth the impact and relevance of User:Gary/enhanced random article.js in modern society. User:Gary/enhanced random article.js has been a topic of interest and debate for decades, and its influence extends to multiple areas, from politics and economics to culture and technology. Through in-depth analysis, we will examine how User:Gary/enhanced random article.js has shaped our perceptions, behaviors, and relationships in today's world. Additionally, we will address the implications and challenges that User:Gary/enhanced random article.js poses for the future, and how its evolution will continue to shape the course of humanity.
// Generated by CoffeeScript 1.7.1

/*
	ENHANCED RANDOM ARTICLE
	Documentation: ]
	Description: Enhances the existing "Random article" feature.
		Disambiguation pages, redirects, and pages with titles that match a certain pattern can be skipped over.
	
	TODO
	- Match patterns to NOT show.
 */
var addEnhancedRandomArticlePortletLink, addPortletLink, checkRandomMatch, eRCheckMatches, eRCreateArticleList, enhancedRandomArticle, enhancedRandomArticleBegin, matchDisambig, mw;

if (typeof enhancedRandomArticle === "undefined" || enhancedRandomArticle === null) {
  enhancedRandomArticle = {};
}

if (typeof unsafeWindow !== 'undefined') {
  addPortletLink = unsafeWindow.addPortletLink;
  mw = unsafeWindow.mw;
}

enhancedRandomArticleBegin = function() {

  /*
  		DEFAULT SETTINGS
  		
  		enhancedRandomArticle = { patterns: , showDisambiguationPages: false, showStubs: false }
  		
  		enhancedRandomArticle = {}
  		enhancedRandomArticle.patterns = 
  		enhancedRandomArticle.showDisambiguationPages = false
  		enhancedRandomArticle.showStubs = false
   */
  if (enhancedRandomArticle == null) {
    enhancedRandomArticle = {};
  }
  if (enhancedRandomArticle.patterns == null) {
    enhancedRandomArticle.patterns = ;
  }
  if (enhancedRandomArticle.showDisambiguationPages == null) {
    enhancedRandomArticle.showDisambiguationPages = false;
  }
  if (enhancedRandomArticle.showStubs == null) {
    enhancedRandomArticle.showStubs = false;
  }
  return $.get(mw.config.get('wgScriptPath') + '/api.php', {
    action: 'query',
    list: 'random',
    rnnamespace: 0,
    format: 'json',
    rnlimit: 10
  }, eRCreateArticleList);
};

eRCreateArticleList = function(obj) {
  var article, articles, articlesArray, _i, _len;
  articles = obj.query.random;
  articlesArray = ;
  for (_i = 0, _len = articles.length; _i < _len; _i++) {
    article = articles;
    articlesArray.push(article.title);
  }
  return $.get(mw.config.get('wgScriptPath') + '/api.php', {
    action: 'query',
    prop: 'revisions',
    rvdir: 'older',
    rvprop: 'content',
    titles: articlesArray.join('|'),
    format: 'json'
  }, eRCheckMatches);
};

matchDisambig = function(possiblePatterns, content) {
  var matchExpr, pattern, _i, _len;
  for (_i = 0, _len = possiblePatterns.length; _i < _len; _i++) {
    pattern = possiblePatterns;
    matchExpr = new RegExp(pattern, 'i');
    if (content.match(matchExpr)) {
      return true;
    }
  }
  return false;
};

checkRandomMatch = function(userSettings, title, content) {
  var disambiguationMatches, eRA, matched, matchedPattern, pattern, _i, _len, _ref;
  eRA = userSettings;
  disambiguationMatches = ;
  matched = false;
  matchedPattern = '';
  _ref = eRA.patterns;
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
    pattern = _ref;
    if (title.match(pattern)) {
      matched = true;
      matchedPattern = pattern;
      break;
    }
  }
  if (!eRA.patterns.length && eRA.showDisambiguationPages && eRA.showStubs) {
    console.log(1);
    matched = true;
  }
  if (matched && !eRA.showDisambiguationPages && matchDisambig(disambiguationMatches, content)) {
    matched = false;
  } else if (!eRA.patterns.length && !eRA.showDisambiguationPages && !matchDisambig(disambiguationMatches, content)) {
    console.log(2);
    matched = true;
  }
  if (matched && !eRA.showStubs && content.match(/stub}}/i)) {
    matched = false;
  } else if (!eRA.patterns.length && !eRA.showStubs && !content.match(/stub}}/i)) {
    console.log(3);
    matched = true;
  }
  return matched;
};

eRCheckMatches = function(obj) {
  var article, articles, content, eRA, matched, page, title, value, _i, _len, _ref;
  articles = ;
  _ref = obj.query.pages;
  for (page in _ref) {
    value = _ref;
    articles.push(value);
  }
  eRA = enhancedRandomArticle;
  if (typeof eRA.patterns === 'string') {
    eRA.patterns = ;
  }
  for (_i = 0, _len = articles.length; _i < _len; _i++) {
    article = articles;
    content = article;
    title = article;
    matched = checkRandomMatch(eRA, title, content);
    if (matched) {
      window.location = 'https://wiki386.com/en/' + title;
      return;
    }
  }
  return alert("ENHANCED RANDOM ARTICLES\n\nAn article that meets all of your criteria could not be found. Please try again.\nAlso, perhaps consider using less restrictive criteria.\n\nKeep in mind that only 10 articles are retrieved each time this script is activated,\nso there's a good chance that most of them won't match your criteria if it's too strict.");
};

addEnhancedRandomArticlePortletLink = function() {
  var node, nodeLink, randomPageLink;
  if ($('#p-navigation').length) {
    mw.util.addPortletLink('p-navigation', '#', 'Enhanced random', 't-enhanced-random-article', 'Show a random article, with enhanced settings', '', '#n-randompage');
    $('#t-enhanced-random-article').on('click', function(event) {
      event.preventDefault();
      return enhancedRandomArticleBegin();
    });
    if ($('#n-randompage').length) {
      randomPageLink = $('#n-randompage').children().eq(0);
      randomPageLink.attr('accesskey', null);
    }
    node = $('#t-enhanced-random-article');
    nodeLink = node.children().eq(0);
    nodeLink.attr('accesskey', 'x');
    return nodeLink.attr('title', nodeLink.attr('title') + ' ');
  }
};

$(addEnhancedRandomArticlePortletLink);

if (typeof unsafeWindow !== 'undefined') {
  unsafeWindow.checkRandomMatch = checkRandomMatch;
  unsafeWindow.enhancedRandomArticle = enhancedRandomArticle;
  unsafeWindow.enhancedRandomArticleBegin = enhancedRandomArticleBegin;
  unsafeWindow.eRCheckMatches = eRCheckMatches;
  unsafeWindow.eRCreateArticleList = eRCreateArticleList;
  unsafeWindow.matchDisambig = matchDisambig;
}