Regex

help at regex challenge site

ของเมื่อวันที่ 26-11-2015 ดู เวอร์ชันล่าสุด

// ==UserScript==
// @name        Regex
// @namespace   http://wifi.com
// @include     http://callumacrae.github.io/regex-tuesday/
// @version     1.1
// @description help at regex challenge site
// @grant       none
// ==/UserScript==
var elArray = document.getElementsByClassName("challenge");
var done = ["http://callumacrae.github.io/regex-tuesday/challenge1.html",
            "http://callumacrae.github.io/regex-tuesday/challenge20.html",
           "http://callumacrae.github.io/regex-tuesday/challenge2.html",
           "http://callumacrae.github.io/regex-tuesday/challenge3.html",
           "http://callumacrae.github.io/regex-tuesday/challenge4.html",
           "http://callumacrae.github.io/regex-tuesday/challenge5.html",
           "http://callumacrae.github.io/regex-tuesday/challenge6.html",
           "http://callumacrae.github.io/regex-tuesday/challenge7.html",
           "http://callumacrae.github.io/regex-tuesday/challenge8.html",
           "http://callumacrae.github.io/regex-tuesday/challenge9.html"];
//alert(elArray[0].parentElement.parentElement.parentElement.innerHTML);
var counter = elArray.length;
for(i = 0; i< elArray.length; i++){
  //alert(elArray[i].href);
  if(contains(elArray[i].href, done)){
     elArray[i].style.backgroundColor = "limegreen";  
     counter--;
  }
}
if(counter != elArray.length)
    elArray[0].parentElement.parentElement.parentElement.innerHTML = "<h2 style='background-color:red'>Still " + counter + " challenges left</h2>" + elArray[0].parentElement.parentElement.parentElement.innerHTML;
else
    elArray[0].parentElement.parentElement.parentElement.innerHTML = "<h2 style='background-color:limegreen'>Still " + counter + " challenges left</h2>" + elArray[0].parentElement.parentElement.parentElement.innerHTML;
function contains(myValue, myArray)
{
    var count=myArray.length;
    for(var i=0;i<count;i++)
    {
        if(myArray[i]===myValue){return true;}
    }
    return false;
}