Skip to content

Latest commit

 

History

History
27 lines (17 loc) · 1.1 KB

best-practices.md

File metadata and controls

27 lines (17 loc) · 1.1 KB

Best Practices

Extracting from HTML

The following formats return null in a timely manner if the regex isn't matched. Replace YOUR_REGEX_HERE.

script field:

function process(url, completionHandler) { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var res = xmlhttp.responseText; var results = RegExp('.*(YOUR_REGEX_HERE).*').exec(res); var match = null; if (results != null && results.length > 1) { match = results[1]; }; completionHandler(match); } }; xmlhttp.open('GET', url, true); xmlhttp.send(); }

script2 field:

function process(url, completionHandler) { var res = httpRequest(url); var results = RegExp('.*(YOUR_REGEX_HERE).*').exec(res); var match = null; if (results != null && results.length > 1) { match = results[1] }; completionHandler(match); }

URL Encoding

Replace YOUR_*_HERE.

script and script2 fields:

function process(url, completionHandler) { completionHandler('YOUR_SCHEME_HERE://YOUR_PATH_HERE?url=' + encodeURIComponent(url)); }