Javascript $(document).ready error with XPath in WordPress

I am having a problem setting a JavaScript function to execute when $(document).ready, I get

Uncaught TypeError: Property '$' of object [object Object] is not a function

when I try with document.onload I get

Read More
Uncaught TypeError: Cannot read property 'src' of null

when doing the same with body.onload, it just does not recognize the body.
the JavaScript code is within a file, registered in a wordpress plugin

wp_enqueue_script( 'dencoder', plugins_url( 'decoder.js' , __FILE__ ), array('jquery'));

as you can see I already setup jQuery as a dependency but I did not get it to work.
Here is my javascript code

function decode2(){
   var element = document.evaluate( '//*[@id="mep_0"]/div/div[1]/video' ,document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue;
   var theurl_e = element.src.replace(document.URL,'');
   var theurl = rot13(atob(element.src.replace(document.URL,'')));
   element.src = theurl;
   var element2 = document.evaluate( '//*[@id="mep_0"]/div/div[1]/video/source' ,document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue;
   element2.src = theurl;
}
function rot13(s)
{
return (s ? s : this).split('').map(function(_)
 {
    if (!_.match(/[A-za-z]/)) return _;
    c = Math.floor(_.charCodeAt(0) / 97);
    k = (_.toLowerCase().charCodeAt(0) - 83) % 26 || 26;
    return String.fromCharCode(k + ((c == 0) ? 64 : 96));
 }).join('');
}

Related posts

Leave a Reply

1 comment