Gateway Link Cleaner
Clean up links to Audience View shows at TheGateway.org
by tambascot
HTML
<!DOCTYPE html>
<body>
<form id="form">
<div>
<textarea id="area" cols="50" rows="5"></textarea>
<input type="button" value="Get Link" onclick="run()" />
<br />
<p id="result">Result</p>
</div>
</form>
</body>
JavaScript
function run() {
var c1 = document.getElementById('area').value;
var d1 = document.getElementById('result');
d1.innerHTML = getPostLink(c1);
}
/**
* getPostLink
*
* https://jsfiddle.net/
*
* Get a direct link to your AudienceView posts by cleaning the URL of session info
*/
function getPostLink(textBlock) {
this.textBlock = textBlock;
var permalink = textBlock.match(/permalink=\w+&/);
// If there is no match, permalink will be null: in that case, we can't
// make a direct link to the page, so return an error.
if (permalink === null) {
return "Error: permalink not found. Can't make direct link to this page.";
}
var link = permalink[0].slice(10, -1);
var base = "https://thegateway.org/Online/Article/";
var url = base.concat(link);
var anchor = textBlock.match(/\#.*/);
if (anchor) {
url = url.concat(anchor);
}
url.replace('/null/', '');
return url;
}