Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Convert this Greasemonkey code to JavaScript for Android?
    primarykey
    data
    text
    <p>I am trying to load a page and then run a javascript code on it, I found a Greasemonkey script that does the same, but I am having problems implementing the same thing in android, probably because I don't know anything about javascript.</p> <p>This is the Greasemonkey script; it's supposed to a give a new link:</p> <pre><code>window.addEventListener("load", function () { var link = document.evaluate("//div[@class='dl_startlink']/div/a[contains(@href,'"+window.location.href.match(/\?(.*)$/)[1]+"')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); if( !link.snapshotLength ) return; location.href = link.snapshotItem(0).href; }, false); </code></pre> <p><br> and this is how I want to run it:</p> <pre><code>public void onPageFinished (WebView view, String url) { System.out.println("webview loaded"); webView.loadUrl("javascript:/*...........Javascript code here........*/"); } </code></pre> <p>Any ideas on how I get that link and load that page in the webview? EDIT: Another version does the same thing.</p> <pre><code>var candidates = document.evaluate("//*[@class = 'dl_startlink']/div", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); if( !candidates.snapshotLength ) return; //The DIV with the highest zIndex has the *real* link; the rest are useless. - var maxDiv = candidates.snapshotItem(0); - for( var i = 1; i &lt; candidates.snapshotLength; i++ ) - if( maxDiv.style.zIndex &lt; candidates.snapshotItem(i).style.zIndex ) - maxDiv = candidates.snapshotItem(i); - location.href = maxDiv.children[0].href; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload